vendredi 10 avril 2015

Exclude characters from format_string() in Drupal form

I have a text field in my Drupal form, which I need to sanitise before saving into the database. The field is for a custom name, and I expect some users may want to write for example "Andy's" or "John's home".


The problem is, that when I run the field value through the check_plain() function, the apostrophe gets converted into ''' - which means "Andy's code" becomes "Andy's code".


Can I somehow exclude the apostrophe from the check_plain() function, or otherwise deal with this problem. I have tried wrapping in the format_string() function, but it's not working:



$nickname = format_string(check_plain($form_state['values']['custom_name'], array(''' => "'")));


Thanks.


Aucun commentaire:

Enregistrer un commentaire