Developer Support »

Back button for errors

This applies to the free version and the Pro version.

By default, if the script detects any errors in the submitted form it shows the error(s) on the screen (with the Pro version, you can display the error messages on the form page so the user doesn't have to hit "Back"). To provide a convenient way for the user to return to your form, you can make a "Back" button show below the error(s). This does the same thing as hitting "Back" in the browser.

To make a Back button you will need to edit the script code. Open the script in a text editor. locate this line in the script (from Pro version 3.3):

if(count($errors) && $show_errors_on_form_page == 0){foreach($errors as $value){print stripslashes($value) . "<br>";} exit;}

...or this line in the Free script (or Pro script prior to version 3.3)

if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

Replace it with this line:

if(count($errors)){foreach($errors as $value){print stripslashes($value) . "<br>";} print "<p><form><input type=\"button\" value=\"Back\" onclick=\"history.go(-1)\"></form>"; exit;}

In the above line, value=\"Back\" is the wording that appears on the button, you can change this to suit. The backslashes are there to escape the quotes for PHP and should be retained.

The above code needs Javascript to work (most people have this by default). Alternatively, you could simply provide a link to the form (but calling it up fresh would probably wipe out the information that was on it, unless you use the $pre_populate_form option in the Pro version) like this, for example:

if(count($errors)){foreach($errors as $value){print stripslashes($value) . "<br>";} print "<p><a href=\"contact_page.html\">Click here to return to the form</a>"; exit;}

In the above line, "contact_page.html" is the name of the page containing the form.

When you have made the changes to the script, save it and upload it to your webspace.