Hi,
I am a newb to drupal..
I created a form using webform module and i have a phone No. field in it. I have to validate it to accept only numeric values.
Normally i validate other form's fields using the following code...
-------------------------------------------------------------------------------------------------------------------------------------
function sitehelper_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_register' || $form_id == 'user_profile_form') {
$form['registration']['profile_zip']['#element_validate'] = array('sitehelper_profile_zip_validate');
}
}
<?php
function sitehelper_profile_zip_validate ($element) {
if (is_numeric($element['#value'])!=1 ) {
form_set_error('profile_zip', t('Zipcode must be numeric'));
}
}
-----------------------------------------------------------------------------------------------------------------------------
where sitehelper is the module name.
Here the html output of form field created using webform is like the following...
so the name attribute is name="submitted[phone_number]" which i believe is an array representation.
Normally to fetch field value for email we use form_state['values']['email']
But in webform it appears like the form field names are represented as array submitted[phone_number]
So how do we fetch field value and validate....
Pls help
Comments
Comment #1
Sandymaguire commentedIm including the code here to be clear...
Comment #2
Sandymaguire commentedSurprising that no one has posted comments....
I solved the problem myself after few days.
anyway if u come accross this post... u can make use of the following
if u have created the webform, goto administer ---> content management ---> clik edit on ur webform content
and for validating my phone field.
enter the following php code in "additional validation" under "webform advanced settings" fieldset
thank you
Comment #3
qaffaf commentedthnx Sandymaguire that was really helpful
Comment #4
vj0914 commentedThank you Sandymaguire, I think this is very helpful in my situation.
Comment #5
quicksketchThere's a whole section on validation codes in the Webform handbook: http://drupal.org/handbook/modules/webform/validation-code
Sorry when this post was original created the handbook was still completely broken from the Drupal 6 upgrade of drupal.org. It's all now in place again now.
Comment #6
qaffaf commentedComment #7
rushala commentedthnx so much
Comment #8
gurpreet2000 commentedThank you Sandy
Comment #9
quicksketchComment #10
sureshdk1982 commentedI can't find "additional validation" under "webform advanced settings" fieldset to enter the following php code