|
Posted by Bjorn on September 13, 2006, 8:14 pm
Please log in for more thread options
Hi.
Every time i post data in a form the contents are being checked for
validity.
When i click the back-button, all data is gone and i have to retype it.
It's obvious that only a few or none of the visitors will retype it all
so i'm asking: "how to preserve POST-data when clicking the
back-button?"
i've already tried to print post data as a value in a HTML tag but
since it's not reparsed, this won't help either.
Is this a browser-issue?
---
14 sept 2006 02:14h GMT +1 (CET)
|
|
Posted by Chris Beall on September 14, 2006, 11:06 am
Please log in for more thread options
Bjorn wrote:
> Hi.
>
> Every time i post data in a form the contents are being checked for
> validity.
> When i click the back-button, all data is gone and i have to retype it.
> It's obvious that only a few or none of the visitors will retype it all
> so i'm asking: "how to preserve POST-data when clicking the
> back-button?"
>
> i've already tried to print post data as a value in a HTML tag but
> since it's not reparsed, this won't help either.
>
> Is this a browser-issue?
>
> ---
> 14 sept 2006 02:14h GMT +1 (CET)
>
Bjorn,
It isn't clear to me whether you are talking about a site you visited or
one you are creating.
If the former, you are somewhat at the mercy of the site designer. Some
browsers, on some occasions, seem to save the POST data and will prompt
you to warn that it will be resent if you use BACK. Some don't.
If you are dealing with something like a contact form, where you filled
in few specific fields and then typed a long description, you can swipe
and copy the description into the clipboard before submitting the form.
At least that will preserve the bulk of the data in case the form is
rejected. BUT, you have to remember to do this every time you fill out
a form, which is unlikely.
All of the above, however, indicates poor design of the site, so if
we're talking about a site you are working on, you should avoid the
situation entirely, thus:
1. Optionally, the page on which the form exists should contain
Javascript checks of the data entered. If data fails these checks, a
message can be presented to the user without ever submitting the form,
and leaving all the data intact. Note that some users will have
Javascript disabled, so this check will not take place and the user will
move to the next step.
2. The server should check the data submitted. If the checks fail, the
server should regenerate the page containing the form, with all
user-entered data re-presented for editing. The user should never need
to use the BACK button because of syntactical errors in the input data.
3. It is possible that the user's data is correct, but that an error
still occurs when the server tries to process that data. Again, a
well-designed system would preserve the user input and either
automatically regenerate the form (as above) or give the user the option
to do so.
If you can provide more specifics, you might get a more detailed answer.
Chris Beall
|
|
Posted by Bjorn on September 14, 2006, 12:06 pm
Please log in for more thread options
In reply to Chris Beall's message:
Very useful hints you gave me.
thank you.
It's a site that i'm writing in PHP atm.
the back button is used to reduce the amount of code so it would be a
lot easier for me to write.
i will use JS to check the form entries where the values were only
checked server-side.
Maybe i can solve this problem by loading certain variables into the
(reparsed) form by redirecting instead of using the back-button.
f.e.
<form name="somename" action="script.php?p=contact" method="post">
<input type="hidden" name="contactmessage" id="contactmessage"
value="line1\nthis is line2\nlast line" />
<input type="submit" name="submit" id="submit" />
</form>
server-side code:
<textarea name="contactmessage" id="contactmessage"><?php
echo($_POST['contactmessage']); ?></textarea>
If you could suggest a better way to preserve the values, other
opinions are welcome.
Thank you in advance.
---
14 sept 2006 - 18:06h GMT+1 (CET)
|
|
Posted by Chris Beall on September 14, 2006, 12:56 pm
Please log in for more thread options
Bjorn wrote:
> In reply to Chris Beall's message:
>
> Very useful hints you gave me.
> thank you.
> It's a site that i'm writing in PHP atm.
> the back button is used to reduce the amount of code so it would be a
> lot easier for me to write.
>
> i will use JS to check the form entries where the values were only
> checked server-side.
> Maybe i can solve this problem by loading certain variables into the
> (reparsed) form by redirecting instead of using the back-button.
>
> f.e.
> <form name="somename" action="script.php?p=contact" method="post">
> <input type="hidden" name="contactmessage" id="contactmessage"
> value="line1\nthis is line2\nlast line" />
> <input type="submit" name="submit" id="submit" />
> </form>
>
> server-side code:
> <textarea name="contactmessage" id="contactmessage"><?php
> echo($_POST['contactmessage']); ?></textarea>
>
> If you could suggest a better way to preserve the values, other
> opinions are welcome.
>
> Thank you in advance.
> ---
> 14 sept 2006 - 18:06h GMT+1 (CET)
>
Bjorn,
I think we're on the same wavelength here. I did mine in Perl and the
relevant part of it looks like this:
print <<'ENDPART1';
...snip irrelevant stuff...
<form action="contact.pl" method="post">
ENDPART1
unless ($input_error eq "none") {
print "<div class=\"error\">$input_error</div>" ;
}
if (defined $email) { # Input from prior pass -
regurgitate value.
print "Your E-mail address: <input type=\"text\" id=\"parm1\"
name=\"parm1\" size=\"35\" value=\"$email\"><br>" ;
}
else {
print "Your E-mail address: <input type=\"text\" id=\"parm1\"
name=\"parm1\" size=\"35\"><br>" ;
}
print <<'ENDPART2';
<p>
Please check what you just typed above.
If your e-mail address is incorrect, I won't be able to respond to you,
which will frustrate both of us.
</p>
Message<br>
ENDPART2
if (defined $comments) { # Input from prior pass -
regurgitate value.
print "<textarea rows=\"15\" cols=\"45\" wrap=\"virtual\"
id=\"parm2\" name=\"parm2\">$comments" ;
}
else {
print "<textarea rows=\"15\" cols=\"45\" wrap=\"virtual\"
id=\"parm2\" name=\"parm2\">" ;
}
print <<'ENDPART3';
</textarea>
<input class="button" type="submit" value="Send Message">
</form>
In my case, the Perl code is called repeatedly. When it is first
called, there is no user input, so it generates a page with the blank
form on it. When the form is submitted, the SAME Perl code is called.
It now sees that the user has provided some input, so that is validity
checked. If it fails those checks, the form is created again, with an
error message ($input_error) above it and previous data regenerated by
putting it into into a value= attribute.
The basic flow is:
Link from another page to contact.pl, which sees no user input.
Generate contact.html and serve it to the user.
User enters invalid data and submits it.
Submit to contact.pl, which now detects presence of user input.
Data error detected.
Generate contact.html with error message and regenerated input.
Serve to user.
User corrects the data and submits it.
Submit to contact.pl, which again detects presence of user input.
Data validated.
Process form (in this case a Sendmail).
Generate response.html and serve it to the user.
I'm not familiar with PHP, so I can't evaluate your solution. One
difference I see is that you seem to be using the hidden= attribute,
which I don't.
NOTE: This function can be improved on. See my proposed more elaborate
specification at http://pages.prodigy.net/chris_beall/TC/Contact.html,
Tip #3. Someday I'll get around to implementing it...
Chris Beall
|
|
Posted by Chris Beall on September 14, 2006, 1:02 pm
Please log in for more thread options
Chris Beall wrote:
> Bjorn wrote:
>> In reply to Chris Beall's message:
>>
>> Very useful hints you gave me.
(snip)
>>
> Bjorn,
>
> I think we're on the same wavelength here.
(snip)
In the following description, "Generate contact.html" isn't quite
correct. The user never sees 'contact.html' as a URL. Rather,
contact.pl (which the user DOES see as a URL) sends data of
Content-type: text/html to the client, using the Perl print directive.
Subtle difference.
> The basic flow is:
> Link from another page to contact.pl, which sees no user input.
> Generate contact.html and serve it to the user.
> User enters invalid data and submits it.
> Submit to contact.pl, which now detects presence of user input.
> Data error detected.
> Generate contact.html with error message and regenerated input.
> Serve to user.
> User corrects the data and submits it.
> Submit to contact.pl, which again detects presence of user input.
> Data validated.
> Process form (in this case a Sendmail).
> Generate response.html and serve it to the user.
>
Chris Beall
|
| Similar Threads | Posted | | Post data to server from javascript on client side | January 17, 2005, 3:47 pm |
| preserve line breaks in applet parameters | January 27, 2007, 10:10 pm |
| POST validation | October 6, 2005, 2:45 pm |
| Form post | April 18, 2008, 7:16 pm |
| Post Meta World? | September 2, 2005, 3:12 am |
| making use POST method? | February 11, 2006, 7:37 am |
| Text-links using POST ? | September 8, 2006, 1:17 pm |
| IE form post oddness | September 13, 2006, 4:14 pm |
| Form POST problem | May 14, 2007, 2:49 am |
| Form POST problem | May 15, 2007, 2:53 am |
|