1

I am using Drupal 7 webform api, have a created a field in my _form_alter hook in a custom module, but while on page load the hidden field contains the correct value, when I submit the form it does not save to the mysql table, and gives me an empty cell

$form['State'] = array(
  '#type' => 'hidden',
  '#value' => 'Unread',
  '#attributes' => array('id' => array('stateform')),    
);

How can I make it save to the mysql table on submit?

UPDATE:

$form['State'] = array(
'#type' => 'hidden',
'#title' => t('Hidden'),    
'#attributes' => array('id' => array('state')),
);
drupal_add_js(drupal_get_path('module','mymodule') . '/js/custom.js');
  • What code is in your submit function? – Pontus Nilsson Jul 30 '15 at 13:43
  • I do not have one, since am using webform's default submit function. – st2014 Jul 31 '15 at 10:24
1

You also will need to write a hook_form_submit for your form. In the _form_submit() you will take the hidden value and store it where you like.

That is the simple answer for your question. If you provide more details there could be other ways of handling the data. What is your form action?

  • The hidden value should be configured to be "less secure" while creating the webform component. – neelmeg Apr 28 '16 at 21:19
0

You do not need any hooks to do this. You can simply create an element via the webform UI of type "hidden." and it will save when the webform is submitted.

  • From my updated post above, am now using a JS instead of #value to fill in the value in my hidden field. Again it is found in the _alter hook, but the above mentioned methods did not work for me. Unless am doing it all wrong here. I am using webform's default submit actions here, which send the data to the webform_submitted_data table. – st2014 Jul 31 '15 at 10:22
  • Did you try my suggestion? Allows you to get rid of all php code except for the 1 line that adds js. Which type of hidden field did you add? Don't use the "secure value" type as that is not alterable via js. – Coleman Jul 31 '15 at 13:18
0

This value should be stored in

$form_state['values']

You can access that in your hook_form_submit. It wouldn't hurt to do a drupal_set_message on $form_state['values'], so that you can see exactly what values are stored there.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.