Found something that looks like a bug in the code for fields using conditional rules. The result is that unwanted values are submitted to the database.

An example is a form with a select option field on page 1 where you choose how many text fields you want on page 2. To the fields on page 2 you choose conditional rules depending on the value from the select option on page 1. So if you choose 1 you get 1 textfield, if you choose 2 you get 2 textfields and so on.

If you first choose 2 on the select option, 2 textfields are displayed on page 2. Then enter some values in those textfields and hit the "previous page" button and choose to only display 1 textfield on page 2. Everything looks fine when looking at the form but the previously entered value in the second textfield is still there, but hidden, and is saved to the database.

The result is that the submission data represent false information not intended to be submitted.

Maybe unset the submitted values in form_state on hidden fields?

Comments

vernond’s picture

Your suggestion will work fine when the use case you describe occurs. How do we handle it when the user changes their mind yet again, goes back and re-selects the original option on preceding page, clicks next page and finds their original data missing... new bug report. It is not going to be trivial to manage the cascading that can occur when, for example, the fields we clear on page two mean that fields on page six and nine must also be cleared and so on.

If it is mission critical for you to have these fields cleared on an if-then-else basis, then it is probably a better solution to write a little module to implement hook_webform_submission_presave for the situation. That way you get to deal with the entire submission in one hit as opposed to attempting to manage bits and pieces all along the way.

kleve’s picture

You make a good point. Maybe this is not the solution but I still think something is wrong here. I agree you should not clear the data between pages based on the scenario you described, but would it not be a good solution to clear the data when submitting the form? Or do you still worry that the user might want to go back and edit the form and think that the data is still there.

If you don´t think this is something manageable or suitable for this module, I will of course look in to the use of hook_webform_submission_presave.

vernond’s picture

Category: bug » feature

Let us know how you get along with the standalone module. It may be that your answer works well enough to be rebuilt as a patch for Webform itself and everyone can win. There is merit in what you're saying, but it'll probably be a while before this kind of thing will be built in otherwise.

Changing category from bug report to feature request.

quicksketch’s picture

Status: Active » Closed (duplicate)

This is a valid bug, I filed it when we first created conditional support in #680262: Conditional fields may save inapplicable values. Let's merge this issue into that one.