PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Templeton Peck
Forum Commoner
Posts: 45 Joined: Sun May 11, 2003 7:51 pm
Post
by Templeton Peck » Mon May 19, 2003 5:43 pm
I simply want to call a php function to validate my form
<form onsubmit =
"return validate();" method = "POST" action = "summary.php" >
how do I properly call the php function validate?
thanks
McGruff
DevNet Master
Posts: 2893 Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland
Post
by McGruff » Mon May 19, 2003 6:59 pm
There is no native php function for form validation: you'll have to write one something like:
Code: Select all
<?php
IF (!isset($_POST['var1']) OR !isset($_POST['var2']) OR ..etc ) {
// back to the form
} ELSE {
// process form
}
?>
Last edited by
McGruff on Thu Aug 11, 2005 8:54 am, edited 1 time in total.
AVATAr
Forum Regular
Posts: 524 Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:
Post
by AVATAr » Mon May 19, 2003 7:26 pm
Templeton, be aware that php is server side.. so as McGruff told, you have to check the values AFTER submit - checking $_POST[] variable.
If you want to make your validation on the client side you can use javascipt, but the best solution is to use server side validation cause the user may have javascript off.
Templeton Peck
Forum Commoner
Posts: 45 Joined: Sun May 11, 2003 7:51 pm
Post
by Templeton Peck » Mon May 19, 2003 7:47 pm
thanks guys, I get what your saying
How can I make it go back to the original php page if the information sent is not valid?.. what I want to know is the command to go back to the original page?
AVATAr
Forum Regular
Posts: 524 Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:
Post
by AVATAr » Mon May 19, 2003 8:16 pm
check this example
Code: Select all
<?php
if (isset($_POSTї'btn_ok'])){
//OK button pressed
//Initialize error array
$errors = array();
//Check errors
if (strlen(trim($_POSTї'form_text'])) == 0){
$errorsї'form_text'] = 'Please enter text...';
}
if (count($errors) == 0){
//Process Form
echo "Form processed";
//redirect after this
//Header("Location: ");
//exit;
}
}
?>
<HTML>
<HEAD>
<title></title>
</HEAD>
<BODY>
<FORM name="SeccionForm" method="post" enctype="multipart-form-data"
action="<?php echo $_SERVERї'PHP_SELF']; ?>">
<input name="form_text" type="text" value="<?php echo $form_text; ?>"><?php echo $errorsї'form_text']?></TD>
<INPUT class="button" TYPE=Submit value="OK" name="btn_ok"></TD>
</FORM>
</BODY>
</HTML>
Templeton Peck
Forum Commoner
Posts: 45 Joined: Sun May 11, 2003 7:51 pm
Post
by Templeton Peck » Mon May 19, 2003 9:42 pm
if (isset($_POST['submit']))
{
if (empty($_POST['start']))
{
echo "Blank start date";
header("Location:
http://localhost/query.php ");
exit;
}
}
can someone please tell me whats wrong with this code, and why it still submits even if there is nothing in start
AVATAr
Forum Regular
Posts: 524 Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:
Post
by AVATAr » Tue May 20, 2003 12:08 am
try echo $_POST['start'] maybe something is stored in it.
give us some more code