Form Validation 
Author Message
 Form Validation

I have a form which takes user input and passes it to a php which validates
the data and if correct inserts it into a DB. I want to add error comments
into the validation, but the only way i can think of doing this is by
including 4error variables in the submitting form then redirecting using
header and pass the vars back using get ie:

header("location:NewUser.php?error=Please reenter your password!");

but this looks very messy even with one error message, let alone 3+

Is there an easier way to do this? Or should I making the submitting form
self calling, checking the data from there, and if it's correct redirect to
the page which will enter the data into DB.

 Just as an after thought. is it possible to check the sending URL? so if
the sending URL isnt the one you specify to print  an error?

 thanks in advance for any help, and happy new year!



Sun, 19 Jun 2005 09:46:10 GMT  
 Form Validation

Quote:
> I have a form which takes user input and passes it to a php which
validates
> the data and if correct inserts it into a DB. I want to add error comments
> into the validation, but the only way i can think of doing this is by
> including 4error variables in the submitting form then redirecting using
> header and pass the vars back using get ie:

> header("location:NewUser.php?error=Please reenter your password!");

Make your form handling script just output an error page with whatever
information you want on it, rather than trying to redirect someone to
another page that has to use data from the previous.  In your NewUser.php,
you'd just handle both:

// form validation occurs here
// on success it gets added to the database, or if some error occurs, we do:

echo "<html><head><title>Ack!</title></head><body>\n";
echo "Some error occured with your form! ";

if( $invalidPassword )
     echo "Your password contains invalid characters";

// etc..

echo "</body></html>\n";

This is just a very simple example;  Ideally you might read a nicer looking
HTML template and substitute in your error messages on it and output the
result rather than coding the HTML in by hand like above, but you get the
idea.

Quote:
> Is there an easier way to do this? Or should I making the submitting form
> self calling, checking the data from there, and if it's correct redirect
to
> the page which will enter the data into DB.

It doesn't have to be self-calling (although it could, particularly if you
want to do something like give an error message at the top and have the rest
of the page display the same form they tried to fill out, but with all their
previous data already filled in.)

The validation, submitting to DB, or generation of error message can all be
done in the same single script.  Additionally the form it's self can be
generated from the same script;  I do this sometimes.. The first thing I do
is look to see if the 'Submit' button was pressed (via whatever variable
name I gave it from the form), and if not, I just output the HTML of the
blank form.  Otherwise, it processes the form, and either does what it's
supposed to do, or spits out an error so they can try again.

--

|  Bob Maple  |  bobm_at_burner_dot_com  |  [http] burner.com
|
|  Thom Yorke: "Here's to getting hitched, Space Ghost."
|  "Yeah..  Lets drink until our hearts stop."



Mon, 20 Jun 2005 03:55:46 GMT  
 Form Validation


Quote:
> I have a form which takes user input and passes it to a php which
validates
> the data and if correct inserts it into a DB. I want to add error comments
> into the validation, but the only way i can think of doing this is by
> including 4error variables in the submitting form then redirecting using
> header and pass the vars back using get ie:

How about like this:
--------------------------------------------
<?
/*
 * This form works like this:
 * The first time through $submit and $error are both undefined
 * so the form itself is displayed.
 *
 * 'submit' is the name of the submit button, so it is passed in as part of
the post string
 * when the submit button is pressed, the form 'action' directs us right
back here ...; (That's what <?php $_SERVER['PHP_SELF']?> does).
 * except this time $submit is true,
 *
 *  If $error is set, we print a error message below the offending field
*/
if (!isset($_POST['submit'])) {
?>
<html>

 <head>
  <title>test</title>
 </head>

 <body>
  <h3>Test</h3>
  <hr><p>This form was built to test validation by php

  <form METHOD="POST" ACTION="<?php $_SERVER['PHP_SELF']?>">
  <input type=hidden name="validate" value="yes">
  <p>Enter your .name below:
  <blockquote>
  <p><input TYPE="TEXT" NAME="name" SIZE="35"> <br>
<?php

if ($_GET['error']){
 echo  '<p><font color="#FF0000"><b>You must fill out this
field</b></font></body></html><br>';

Quote:
}

?>
  </blockquote>
  <p><input name="submit" TYPE="SUBMIT" VALUE="Submit Form">
        <input TYPE="RESET" VALUE="Reset Form">
  </form>
  <hr>
 </body>
</html>
<?php
Quote:
} else {

/*
 * We are here when the form has been submitted for validation
 * Perform any kind of test you want
 *
 * Here we are removing all spaces and determing if anything is left.
 *  if we fail, we pass the error parameter back to ourselves
 *  otherwise, we print a 'test complete' screen
 */

 if (!ereg_replace(' *', '', $_POST['name'])){
  header("Location: " .$_SERVER['PHP_SELF'] ."?error=yes");
 }

?>
<head>
<title>test</title>
</head>

<body>
  <hr>
<h3>Test Complete</h3>
  <hr>
</body>

</html>
<?php

Quote:
}

?>
-----------------------------------------------------------------------
<snip>

Alan Walkington



Mon, 20 Jun 2005 05:49:41 GMT  
 Form Validation



Quote:
> I have a form which takes user input and passes it to a php which
validates
> the data and if correct inserts it into a DB. I want to add error comments
> into the validation, but the only way i can think of doing this is by
> including 4error variables in the submitting form then redirecting using
> header and pass the vars back using get ie:

> header("location:NewUser.php?error=Please reenter your password!");

> but this looks very messy even with one error message, let alone 3+

> Is there an easier way to do this? Or should I making the submitting form
> self calling, checking the data from there, and if it's correct redirect
to
> the page which will enter the data into DB.

>  Just as an after thought. is it possible to check the sending URL? so if
> the sending URL isnt the one you specify to print  an error?

>  thanks in advance for any help, and happy new year!

you might want to have a look at
http://www.pgmarket.net/

ofor



Tue, 21 Jun 2005 04:42:04 GMT  
 Form Validation

Quote:

> header("location:NewUser.php?error=Please reenter your password!");

header("location: ") calls must contain an absolute path the the file,
e.g. header("location:
http://www.example.com/path/to/NewUser.php?error=blah);

--
Registered Linux User #273744
<www.volutin.net -- everything irrelevant>
now playing :: [winamp not running]



Tue, 21 Jun 2005 21:00:30 GMT  
 Form Validation
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In a fit of e{*filter*}ment on Sat, 04 Jan 2003 00:00:30 +1100, Will Mays

Quote:

> > header("location:NewUser.php?error=Please reenter your password!");

> header("location: ") calls must contain an absolute path the the
> file,  e.g. header("location:
> http://www.*-*-*.com/ );

Out of interest, does anyone actually know if this will be "enforced"
by browsers? anyone heard anything on the grapevine?

Reason for me asking, is that sure, php.net states this, yet all
browsers I currently have access to work fine without justa  relative
URL. From within lynx, I get a message/warning about it not being an
absolute URL but it redirects regardless.

I know there's the correct, the "it works" and the wrong way but just a
curiousity =)

Regards,

  Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBPhlp7Gfqtj251CDhEQKOCQCcCA2LHhaV+vtNgWTxYtTqTVRSWG0AoJzw
M56f63bfxHNIsNZIBJdiGW6R
=DTS5
-----END PGP SIGNATURE-----

--
Ian.H  [Design & Development]
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.



Fri, 24 Jun 2005 19:35:10 GMT  
 Form Validation


Quote:
> Out of interest, does anyone actually know if this will be "enforced"
> by browsers? anyone heard anything on the grapevine?

> Reason for me asking, is that sure, php.net states this, yet all
> browsers I currently have access to work fine without justa  relative
> URL. From within lynx, I get a message/warning about it not being an
> absolute URL but it redirects regardless.

> I know there's the correct, the "it works" and the wrong way but just a
> curiousity =)

Can't say to ever have encountered a browser that doesn't redirect when the
path is relative. But the HTTP 1.1 standard clearly states that paths must
be absolute.

KAH



Sat, 25 Jun 2005 02:49:20 GMT  
 Form Validation

Quote:

>> > header("location:NewUser.php?error=Please reenter your password!");

>> header("location: ") calls must contain an absolute path the the
>> file,  e.g. header("location:
>> http://www.example.com/path/to/NewUser.php?error=blah);

> Out of interest, does anyone actually know if this will be "enforced"
> by browsers? anyone heard anything on the grapevine?

> Reason for me asking, is that sure, php.net states this, yet all
> browsers I currently have access to work fine without justa  relative
> URL. From within lynx, I get a message/warning about it not being an
> absolute URL but it redirects regardless.

> I know there's the correct, the "it works" and the wrong way but just a
> curiousity =)

I'd be interested in robots/spiders and the like.

Still, whenever I am given the choice between doing
it correctly and a way that works, if the correct
way requires no significant extra effort, I choose
the correct way.

One could almost always use a combination of
$_SERVER['SERVER_NAME'] and dirname($_SERVER['PHP_SELF'])
to get all of the benefits of relative paths in
redirects anyway ...

--
regards,
reggie.



Sat, 25 Jun 2005 04:52:38 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Form validation q

2. form validation

3. Form validation and page navigation

4. Form validation problem: URGENT

5. Field Validation in a Form

6. Validation of FORM fields

7. HTML Form data validation with Object REXX (Windows)

8. Date validation of input from HTML form

9. newbie with a php validation form mail script problem

10. clientside validation of checkboxes from PHP form

11. J Form Editor resizing a form?

12. J Form Editor resizing a form

 

 
Powered by phpBB® Forum Software