0

I wrote a custom method to do some set of operations when a webform is submitted and that is working fine. However I need to access some fields values that has been submitted in the Webform.

The fields in the Webform are: 'phone' , 'emailid'. I need to access these variables in the method custom_example_some_function. I tried playing around with some arrays, but that didn't worked out.

function custom_example_form_alter(&$form, &$form_state, $form_id) {  
  if ($form_id == 'webform_client_form_22') {
       $form['#submit'][] = 'custom_example_some_function';
  }
}

function custom_example_some_function($form, &$form_state) { 
// Do something
// echo $phoneNumberFromForm;
// echo $emailidFromForm;
}
1

You'll find submitted values in $form_state['values'], eg

$foo = $form_state['values']['bar'];
|improve this answer|||||
  • I'm getting this error Notice: Undefined index: phone in custom_example_some_function() This is the function I wrote. function custom_example_some_function(&$form, &$form_state) { $mobilenumbers = $form_state['values']['phone']; } – user3350 Feb 13 '14 at 13:33
  • Yeah, you'll need to inspect $form_state['values'] and find out what's in it, impossible to guess the exact keys from here – Clive Feb 13 '14 at 13:35
  • Forgive my ignorance, but how can I check the values in it. I tried print_r and render. – user3350 Feb 13 '14 at 13:41
  • 1
    Because of the output buffering print_r()/var_dump() have mixed results if you call them outside a template file. By far the easiest way to debug Drupal is to install the Devel module and use the dpm() function (dpm($form_state['values']);). That will print a Krumo representation of the variable to the messages area, and you can inspect it easily – Clive Feb 13 '14 at 13:44
  • 1
    Great!! The Devel module really helped. I used this in the custom function dpm($form_state['values']); Which gave me the exact key. $mobilenumbers = $form_state['values']['submitted'][3]; Thanks Again! – user3350 Feb 13 '14 at 14:23
0

If I understand correctly, you want to edit your $form array values. Now they are passed and locally scoped in *function custom_example_some_function($form, &$form_state)*

Try changing it to function custom_example_some_function(&$form, &$form_state) so that you're able to alter your $form array.

|improve this answer|||||
  • NO! I just to get the fields values in my method custom_example_some_function. If someone submitted form with 'phone number' as '1234567', I want this number in my method. – user3350 Feb 13 '14 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy