How can I preserve the unsubmitted contents of a web form whilst calling a refresh on its structure?
August 24, 2005 5:47 AM
Subscribe
Half way through a form, a user decides that they'd like to add a category to a selection list. How can I facilitate this without also losing everything they've typed into the form so far?
Say I have a selection list, featuring "red", "green", "blue". I have a link which takes the user to an add-a-colour page, where they add "yellow". Now, going Back preserves all the information they'd typed in before they got as far as the selection box, but doesn't update the selection box itself. Refreshing the original page updates the selection box but loses everything they've typed in so far.
I could POST the stuff filled in so far to the add-a-colour page if I used a submit button as a link - but that would mean a form with 2 submit buttons.
Selection box and page are PHP/MySQL constructions. I suspect I could do something with JavaScript events, but I'm not quite sure how. Any pointers or suggestions welcome...
posted by handee to computers & internet (17 comments total)
Whenever I make an interactive form like this, I treat the form as a template, and use hooks to pre-fill values where I can. For example:
<input type=text name=first size=25 value=##value_first##>
<select size=1 name=color>
<option value=red ##selected_color_red##>
</select>
The, the PHP script will go through this template and replace anything in the ## pairs with appropriate values (as you can see, I'm naming them strategically so I can keep them straight in my mind. You can do it however you'd like).
posted by thanotopsis at 6:05 AM on August 24, 2005