Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store form data on Error

Status
Not open for further replies.

d0nny

IS-IT--Management
Dec 18, 2005
278
GB
I have a registration form I get users to complete.
I also check the form for the existence of certain fields/data. If some of the data is missing I throw a server-side error - meaning I check the form upon a page refresh (Submit).

The problem I have is that the form resets upon this error - no data in the form.
Is there any way of keeping the existing data the user has input when the page refreshes upon the check?
 
feherke, thanks for the response.

I suppose what I'm asking is how I redisplay the form with previously received data?

For more details about the solution post more details about the problem.
I could reproduce all the code here for my form, but at the moment its just a simple form, and it could be as simple as some input boxes asking for NAME and EMAIL.
If one of these input boxes creates an error, I display an error on the form page but I want the user data in the NAME and/or EMAIL box to remain as the user input.

At present, I have an IF statement in my script which checks for the Submit button on the form.
When this is true, I then do various checks on the inputed data. If any of these create an error, I simply display the register page again with the error, but the user input has obviously disappeared.

How would I redisplay the form with the received data?
 
number of ways to do this. the simplest is to submit the form via ajax and control the browser based on the server feedback.

the more traditional method is simply to fill the form values back on non-validation. how to do this is more an html question than anything else. for the typical input controls, just set the value attribute. for select controls set the selected property and for radios/checkboxes set the checked attribute.
 
Hi

d0nny said:
At present, I have an IF statement in my script which checks for the Submit button on the form.
Note that the browsers can submit the [tt]form[/tt] when the user presses Enter on a control which itself not handles The Enter presses. In that case depends on the browser's behavior if any [tt]submit[/tt] button information will be sent.

Or later you may decide to add a way to programmatically submit the [tt]form[/tt] calling its [tt]submit()[/tt] method. ( Maybe as a result of implementing jpadie's above suggestion. ) In that case also depends on the browser's behavior if any [tt]submit[/tt] button information will be sent.

So I would not rely on that. Personally I used to check the [tt]$_SERVER['REQUEST_METHOD'][/tt]. If is "POST", the request certainly resulted from [tt]form[/tt] submitting.

Keep giving us details and we will keep giving suggestions.

If you are not sure what part of your script would be interesting for us and your script is huge, you could upload it somewhere. See the Need File Storage? Upload to box.net in the reply form.

Feherke.
 
one other suggestion, for forms processing i often use HTML_QuickForm from the PEAR repository. this will do all the validation and rendering for you. other similar classes also exist.
 
Thanks for the suggestions, but I better put more details about the problem.

I have a form with various INPUT controls.
When the user populates the form, they click submit.
My form then submits it to itself and I run some IF checks on POST values. If some of the values are not met, I display the form again with an error.

What I want is when the form is re-displayed, I want those input boxes that were completed to have the previous values in them.

What I have done is added this to say one of the input controls:
Code:
<input name="fullname" type="text" id="fullname" size="25" maxlength="64" value="<?php echo $_POST['fullname']; ?>">

But this doesn't work - well, no value is contained in the FULLNAME input box.

 
as said, quickform does this all for you. it really is worth checking out.

however there is nothing intrinsically wrong with your code above. if it is not working it is because there is nothing in the fullname POST array element at the time that it is being output.
 

Well, I spend an evening looking into QuickForm and could get past the first hurdle!

I mean, where does "HTML/QuickForm.php" come from???
My understanding is that the script would look in this directory for the file, but I neither have the directory nor the file!
No matter where I looked, I couldn't find anywhere that told me about this file??
 
It is a framework. It is hosted on pear.php.net. I posted a simple sample in chris chamberlains recent thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top