Forum Moderators: coopster
I wrote this guestbook script and I have a couple of questions. Firstly, someone else has tried to use it and they have this problem:
On the guestbook page there is a "sign guestbook" link. After they have clicked that and entered their information, they get a preview of their entry, this is written into the sign.php page, ie:
if ($entry==preview)
do actions;
This displays a preview of their entry, obviously. Now if some required fields aren`t filled in an error message appears informing the visitor to back and try again. I`ve used the javascript:history.go(-1) code which works fine for me.
Problem is, in this other persons browser, they cannot go back. Even if they use their browser back button, the page doesn`t return to the sign.php page with the form. All they can do is click the back button twice and return to the actual guestbook page.
Any idea what might be causing this?
Thanks,
:)
It would appear as though the server is running in Safe Mode, I wonder if that has anything to do with it?
Strange.
after reading your posting, i think you're using ms internet explorer. the history.go(-1) acts that way you describe with some forms as far as i know.
to solve your problem, why don't you display the error message and the form on the same page? this will solve the back-button problem and will help the user to correct the input he/she made. you can even mark the erroreos fields with an exclamation mark for example.
checkout this form as an example [pyrosys.de]. it's in german language but you can understand what i mean - just press the '-> weiter' button on the end of the page. this one is completly based on the users input and will display errormessages automaticly.
I would highly recommend that you don't use javascript but use PHP for the error infomration. have your form in a function such as
function signGuestbook($error=0)
{
if($error) print $error;
print "myform";
}
"myform" is basicly your HTML of the form you are sending.
once the user submits the form, do the error correction and see what errors
e.g. check if they have a valid email
if (!preg_match("/^[A-Za-z0-9\_]*@[A-Za-z0-9\_]*\.[A-Za-z]{1,4}\.{0,1}[A-Za-z]{0,3}$/",$_REQUEST['email'])) $error.="Your email address must be in the correct form.<p>";
then after all your error checking check if there is anything inside the variable $error
if ($error) signGuestbook($error);
else
{
Insert into Database Logic
}
this will then see and error and get your form back for the user, to edit.
a usfull thing then for your form is to also place the variables they sent you back in the boxes.
<tr>
<td width=\"53%\">Email</td>
<td width=\"47%\"><input type=\"text\" name=\"Email\" value=\"".$_REQUEST['email']."\" style=\"border: 1 solid #000000; width: 150px;\"></td>
</tr>
Therefore this will return the form to the user, printing out the error, and then printing out the form with the already inputted values for the user (so they don't have to place them all again!)
In the original script I was doing the following:
if ($REQUEST['preview']) {
blah blah;
}
and
if ($REQUEST['sign']) {
blah blah;
}
The input fields had the names "sign" and "preview" and the form action was just "$PHP_SELF".
Once I removed the input names and did the following, everything worked ok:
if ($action == "preview") {
blah blah;
}
and
if ($action == "sign") {
blah blah;
}
with the form attribute being "$PHP_SELF?action=preview" or "$PHP_SELF?action=sign"
COOL!
Thanks again!
:)