Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit form fields inside display:none element

I have a long form that I've broken up into 6 steps. When the form is loaded, all of the steps are loaded, but only the first step is visible. The rest have CSS of display:none so they are hidden. As a step is completed and validated with Javascript, the current step is set to display:none and the new step is set to display:block. On the final step, the user submits the form. However, as expected, only the fields in display:block element on the page are submitted. All the completed fields in the elements with display:none are ignored.

Is there a way to submit the fields inside the display:none elements?

If not, is there another way to achieve the same effect?

like image 597
Nick Petrie Avatar asked Nov 29 '11 22:11

Nick Petrie


People also ask

Do display none fields get submitted?

display:none - doesn't mean that form elements are not submitted (just not displayed)... They are submitted in the current version of Chrome, despite being hidden.

Does submit need to be inside form?

Yes, structurally the submit button needs to be inside a form element for the document to be valid X/HTML.


1 Answers

Set them to visibility:hidden and position:absolute instead. The fields will not be sent to the server with display:none, but will be with visibility:hidden. By also toggling "position" to "absolute" you should get the same visual effect.

Update This does not appear to be an issue anymore in any current browser (as of Nov of 2015). Fields are submitted even if display is set to 'none'. Fields that are 'disabled', however, will continue to not be submitted.

like image 104
adam0101 Avatar answered Sep 17 '22 13:09

adam0101