Jump to content

[SOLVED] how to validate this form


mraza

Recommended Posts

Hi please somebody can help me in this. I have two process for this form you can see on the end of the page that after submitting where they move. now i need to validate this form and i am not sure what to do. Please any help. Thanks

<div id="form" style="margin: 90px;">
<?php 
if $_POST['submit'] {

$title = $_POST['title'];
$name = $_POST['name'];
$insurance = $_POST['insurance'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['title'];

$error = "";

if (!$title)
$error = $error. "Title <br />"
if ($name)
$error = $error. "Name <br />"
if (!$insurance)
$error = $error. "National Insurance Number <br />"
if (!$address)
$error = $error. "Address <br />"
if (!$phone)
$error = $error. "Telephone Number <br />"
if (!$email)
$error = $error. "Email Address <br />"
if (!$error !="")
  echo "Please Fill in The Following Required Fields <br /> $error";
  else {
  return $_POST['submit'];
  }
}
?>
<form action="" method="POST">
<table>
	<tr>
	<td align="right">
	Title:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="title">
	</td>
	</tr>
	<tr>
	<td align="right">
	Name:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="name">
	</td>
	</tr>
	<tr>
	<td align="right">
	National Insurance<br /> Number:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="insurance">
	</td>
	</tr>
	<tr>
	<td align="right">
	Address:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="address">
	</td>
	</tr>	
	<tr>
	<td align="right">
	Tleephone Number:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="phone">
	</td>
	</tr>
	<tr>
	<td align="right">
	Email:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="email">
	</td>
	</tr>
	<tr>
	<td align="right">
	CSCS Registration Number:
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="registration">
	</td>
	</tr>
	<tr>
	<td align="right">
	Special Accommodations:
	</td>
	<td>
	   <textarea  style="border:1px solid #4088b8;" type="textarea" cols="30" rows="5" name="comments">
	   
	   </textarea>
	</td>
	</tr>
	<tr><td> </td></tr>
	<tr><td> </td>
	<td><input type="button" value="Payment"onClick="this.form.action='payments.php';this.form.submit()" />
	<input type="button" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td>
	</tr>
</table>
</form>
</div>

Link to comment
https://forums.phpfreaks.com/topic/176599-solved-how-to-validate-this-form/
Share on other sites

sorry i posted the wrong one here is the code what i need to know what should i put in

$_POST['submit']. because i am getting this error:

Notice: Undefined index: submit in C:\Program Files\wamp\www\site\includes\registration.php on line 25

Thanks for any help

<?php 
if ($_POST['submit']) {

$title = $_POST['title'];
$name = $_POST['name'];
$insurance = $_POST['insurance'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['title'];

$error = "";

if (!$title)
$error = $error. "Title <br />";
if (!$name)
$error = $error. "Name <br />";
if (!$insurance)
$error = $error. "National Insurance Number <br />";
if (!$address)
$error = $error. "Address <br />";
if (!$phone)
$error = $error. "Telephone Number <br />";
if (!$email)
$error = $error. "Email Address <br />";
if (!$error !="")
  echo "Please Fill in The Following Required Fields <br /> $error";
  else {
  return $_POST['submit'];
  }
}
?>
<div id="form" style="margin: 90px;">

<form action="" method="POST">
<table>
	<tr>
	<td align="right">
	Title:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="title">
	</td>
	</tr>
	<tr>
	<td align="right">
	Name:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="name">
	</td>
	</tr>
	<tr>
	<td align="right">
	National Insurance<br /> Number:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="insurance">
	</td>
	</tr>
	<tr>
	<td align="right">
	Address:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="address">
	</td>
	</tr>	
	<tr>
	<td align="right">
	Tleephone Number:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="phone">
	</td>
	</tr>
	<tr>
	<td align="right">
	Email:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="email">
	</td>
	</tr>
	<tr>
	<td align="right">
	CSCS Registration Number:
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="registration">
	</td>
	</tr>
	<tr>
	<td align="right">
	Special Accommodations:
	</td>
	<td>
	   <textarea  style="border:1px solid #4088b8;" type="textarea" cols="30" rows="5" name="comments">
	   
	   </textarea>
	</td>
	</tr>
	<tr><td> </td></tr>
	<tr><td> </td>
	<td><input type="button" value="Payment"onClick="this.form.action='payments.php';this.form.submit()" />
	<input type="button" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td>
	</tr>
</table>
</form>
</div>

Technically 'Undefined index' is not an error it's a notice, but thats by the by. It basically means it's tried to access an item in the $_POST array with a key of 'submit' and one doesn't exist. The way to avoid this notice is to check if the variable exists.

 

<?php
if(isset($_POST['submit']) {
// etc
?>

pleaes have a look at the last line i am not using submit method. i am moving this form to two diffrent pages ..

 

      <td><input type="button" value="Payment"onClick="this.form.action='payments.php';this.form.submit()" />

      <input type="button" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td>

 

now what should i write on place of if $_POST['submit'] {

well i added the line as :

	<td><input type="hidden" name="submit" value="1" /><input type="button" value="Payment" onClick="this.form.action='payments.php';this.form.submit()" />
	<input type="button" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td>

 

and same error

 

Notice: Undefined index: submit in C:\Program Files\wamp\www\cscssolutions\includes\registration.php on line 25

i have tried this way to but no luck :

 

if ($_POST['submit'] || $_POST['submit2'] ) {

 

and in form:

		<td><input type="button" name="submit" value="Payment" onClick="this.form.action='payments.php';this.form.submit()" />
	<input type="button" name="submit2" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td>

<?php 
if ($_POST['submit'] || $_POST['submit2'] ) {

$title = $_POST['title'];
$name = $_POST['name'];
$insurance = $_POST['insurance'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['title'];

$error = "";

if (!$title)
$error = $error. "Title <br />";
if (!$name)
$error = $error. "Name <br />";
if (!$insurance)
$error = $error. "National Insurance Number <br />";
if (!$address)
$error = $error. "Address <br />";
if (!$phone)
$error = $error. "Telephone Number <br />";
if (!$email)
$error = $error. "Email Address <br />";
if (!$error !="")
  echo "Please Fill in The Following Required Fields <br /> $error";
  else {
  return $_POST['submit'];
  }
}
?>
<div id="form" style="margin: 90px;">

<form action="" method="POST">
<table>
	<tr>
	<td align="right">
	Title:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="title">
	</td>
	</tr>
	<tr>
	<td align="right">
	Name:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="name">
	</td>
	</tr>
	<tr>
	<td align="right">
	National Insurance<br /> Number:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="insurance">
	</td>
	</tr>
	<tr>
	<td align="right">
	Address:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="address">
	</td>
	</tr>	
	<tr>
	<td align="right">
	Tleephone Number:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="phone">
	</td>
	</tr>
	<tr>
	<td align="right">
	Email:<span style="color:red;">*</span>
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="email">
	</td>
	</tr>
	<tr>
	<td align="right">
	CSCS Registration Number:
	</td>
	<td>
	   <input  style="border:1px solid #4088b8;" type="text" size="29" name="registration">
	</td>
	</tr>
	<tr>
	<td align="right">
	Special Accommodations:
	</td>
	<td>
	   <textarea  style="border:1px solid #4088b8;" type="textarea" cols="30" rows="5" name="comments">
	   
	   </textarea>
	</td>
	</tr>
	<tr><td> </td></tr>
	<tr><td> </td>
	<td><input type="button" name="submit" value="Payment" onClick="this.form.action='payments.php';this.form.submit()" />
	<input type="button" name="submit2" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td>
	</tr>
</table>
</form>
</div>

when i submit the form and i can see is_submit in array with print_r($_POST); but its showing same error on first page for undefined index of is_submit which i used on line 25:

 

if ($_POST['is_submit']) {

 

and in from:

		<td><input type="hidden" name="is_submit" value="1" /><input type="button" value="Payment" onClick="this.form.action='payments.php';this.form.submit()" />
	<input type="button" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td>

ok here is the problem again i can't even use javascript validation. because there is no submit button. I need to use two files to move to one if user will choose to pay or next just they submit the request:

 

<td><input type="button" value="Payment" onClick="this.form.action='payments.php';this.form.submit()" />
      <input type="button" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td>

 

Please can somebody some good way to show a display error on same page i am not sure what to do i need to move to two pages so i cant use one submit button

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.