Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Simple form validation question


[SOLVED] Simple form validation question

Reply
  #1 (permalink)  
Old 03-28-09, 04:52 PM
macintosh macintosh is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 84
Thanks: 1
Thanked 0 Times in 0 Posts
[SOLVED] Simple form validation question

how can i display the form error if the form action is some other page than itself.
for example, i have a form, after submitting it goes to validate_form.php page. There i assign error to a variable, eg. $error = "Please enter your name";
Now i want to print this error on the original form page, how can i get this $error value on the form page ?
thanks.
Reply With Quote
  #2 (permalink)  
Old 03-29-09, 01:31 AM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
You could set the error message in a session variable, or pass it as a GET parameter back to the original page. I'd be more inclined to use the first option but either is fine

validate_form.php
PHP Code:

// Validate form
if ($form_does_not_validate) {
     
$_SESSION['formError'] = "There was an error...";
     
header("Location: form.php");
     exit();

form.php
PHP Code:

// If an error is set
if (isset($_SESSION['formError'])) {
     echo 
$_SESSION['formError'];


or

validate_form.php
PHP Code:

// Validate form
if ($form_does_not_validate) {
     
header("Location: form.php?formError=1");
     exit();

form.php
PHP Code:

// List of error messages that are possible
$errorList[0] = "Fields were left empty".
$errorList[1] = "You did not agree to the terms and conditions";
$errorList[2] = "blah blah...";
// and so on

// If an error is set
if (isset($_GET['formError'])) {
     echo 
$errorList$_GET['formError'] ];

__________________
Always sanitise your data


Best regards
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
form validation question darkcarnival JavaScript 3 04-29-09 08:34 AM
ajax checking and onsubmit issue follower JavaScript 4 10-12-08 03:45 PM
Simple form question, I think... Justin171985 PHP 1 02-22-08 09:32 AM
Form Validation slimey PHP 10 03-20-06 06:23 PM
Flexible form validation question epetoke JavaScript 6 09-12-04 04:19 PM


All times are GMT -5. The time now is 08:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.