Hello: I need your help. I'm making a Drupal module, and i need to validate if the textfield data are numeric or not. can i use a drupal functions for this ? This is my form code: 'ci' => array ( '#title' => t('C.I.'), '#type' => 'textfield', '#maxlength' => 11, '#size' => 20, '#required' => TRUE, ), Thanks.
When your form is submitted, it will pass through a validation function if you define one. The function name should be nameofyourform_validate($form, &$form_state) See http://drupal.org/node/751826 (The Drupal forms quickstart guide). This function will be automatically called when a user submits your form. Inside this function, you can check on the values of $form and use PHP's is_numeric to be sure that $form_state['ci'] is a numerical value. If it is not (that is, if is_numeric returns FALSE), use form_set_error to invalidate the submission and return the user to the form page with an error message. On Thu, Mar 10, 2011 at 11:46 AM, Damian Adriel Perez Valdes < damian.adriel@gmail.com> wrote:
Hello:
I need your help. I'm making a Drupal module, and i need to validate if the textfield data are numeric or not. can i use a drupal functions for this ?
This is my form code:
'ci' => array ( '#title' => t('C.I.'), '#type' => 'textfield', '#maxlength' => 11, '#size' => 20, '#required' => TRUE, ),
Thanks.
On 3/10/2011 11:46 AM, Damian Adriel Perez Valdes wrote:
...i need to validate if the textfield data are numeric or not. can i use a drupal functions for this ?
Looks like you got your answer before I could hit send. Here's some more links and info: For Drupal 6, read the Form API Quickstart Guide (http://drupal.org/node/751826, search for "Validating Forms"), which is linked from the main Form API doc page (http://drupal.org/node/204270). You can also read about the #validate and #element_validate attributes at [1] and [2]. For Drupal 7, things are mostly the same, at least as far as validation goes. See http://randyfay.com/taxonomy/term/21 for some other changes if you're interested. [1] http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html... [2] http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html...
participants (3)
-
Damian Adriel Perez Valdes -
Ted -
William Smith