I have a multipage form when I'm setting a hidden field's value depending on the value of two other fields.

My code works for the first hidden fields, but I have 4 hidden fields that all get their values depending on other fields value.

The reason why I'm doing this is because I have a form where I need to make the state either a select list with USA states options for users in the US, or a textfield for users outside of the US. Then I'm trying to grab the value of whatever field was completed (either select list or the textfield) and pass it on to another field which is the one I use to export the data into an oracle database.

Here's the code

if ($form_id == 'webform_client_form_nid') {
if (isset($form_state['input']['submitted']['personal_information_fieldset']['state_province']) && !(is_null($form_state['input']['submitted']['personal_information_fieldset']['state_province']))) {
$form['submitted']['personal_information_fieldset']['state_value']['#value'] = $form_state['input']['submitted']['personal_information_fieldset']['state_province'];
}
elseif (isset($form_state['input']['submitted']['personal_information_fieldset']['AddressState'])) {
$form['submitted']['personal_information_fieldset']['state_value']['#value'] = $form_state['input']['submitted']['personal_information_fieldset']['AddressState'];
}
}

This works fine for the first case, but I have four other places within the form where I need to do the same thing.

This is a long form with multiple pages.
The first two cases are in page 1 and the next two cases are in page 2, currently only the first case in page 1 works.

If I do "dpm($form['submitted']['personal_information_fieldset']['state_value']['#value'] );" it shows me the value I set no problem, but when I go to get the submission, either by downloading it, using wfx or just going to webform results, it doesn't show me the value.

Can anybody help me figure out what's going on, it seems to be a bug with the module.

Comments

DanChadwick’s picture

Category: Bug report » Feature request
Status: Active » Fixed

Is the field you are putting it in hidden? If so, hidden fields are not saved to the database when the submission is complete (i.e. no longer a draft).

Otherwise, we don't provide custom programming support in the issue queue. If your custom code doesn't work, you should conclude that you have a bug in it, or that you are not interacting with webform in the required way. If you wish webform to act differently, you need to open an issue with the desired feature request and a patch making the change you need.

I suggest you create a very simple form and perfect your code there. Use a development environment and good debugger to step through the code to see where the issue is.

Good luck.

DanChadwick’s picture

Category: Feature request » Support request

D'oh.

jcuna’s picture

Hi DanChadwick,

It is a hidden field, but how is it that in the first case the data gets saved to the database. I tested it in a development environment of course.

The code I pasted here works. It's just when I continue to repeat the same thing for the next hidden fields that the values don't get saved.

I don't think that you considered all the information I put here before closing the issue.

I ended up doing it with javascript by setting the hidden field to not secure, and it works fine, the data in the hidden fields get saved, but I'd rather do this with PHP.

DanChadwick’s picture

Sorry. I should have been clearer. The data in components that are hidden by webform conditions is not saved once the submission is final / completed. The data in components of type 'hidden' are saved like any other component.

No idea why it doesn't work -- you'd need to debug it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.