Jump to content

php form validation.


Nandini

Recommended Posts

Hi all

Can any one tell me how can i validate following form.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<?

extract($_POST);

//$lang_error = "<center>The following errors were found:</center>";

$error_colour = "red"; // Must use HTML compatible colour

$lang_peeruser = "Enter peer or user\n";

 

if ((empty($_POST['peer'])) || (empty ($_POST['user'])))

{

$error = "1";

$info_error .= "".$lang_peeruser . "";

}

 

if ($error == "1")

{

$info_notice = "<span style=\"color: " . $error_colour . "; font-weight: bold;\">" . $lang_error . "</span><br>";

 

if (empty ($submit))

{

$info_error = "";

$info_notice = $lang_notice;

}

?>

<form method="post" action="">

<table border="1" align="center">

<tr align="left" valign="top">

      <td colspan="2"><?php echo "<font color=red>".$info_notice.$info_error. "</font>" ?></td>

    </tr>

<tr><td colspan="4" align="center">Outgoing</td></tr>

<tr><td valign="top">Peer:</td>

<td><input type="text" name="peer[]" /><br />

<input type="text" name="peer[]" /><br />

<input type="text" name="peer[]" />

</td></tr>

<tr><td colspan="4" align="center">Incoming</td></tr>

<tr><td valign="top">User:</td>

<td><input type="text" name="user[]" /><br />

<input type="text" name="user[]" /><br />

<input type="text" name="user[]" />

</td></tr>

<tr><td colspan="2" align="center">

<input type="submit" name="submit" value="submit" />

</td></tr>

</table>

</form>

<?

}

else {

/////////////database here

if(isset($_POST['peer']))

{

  $language = $_POST['peer'];

  $n        = count($peer);

  $i        = 0;

 

  //echo "The languages you selected are \r\n" ."<ol>";

  while ($i < $n)

  {

        echo $peer[$i]." \r\n";

      $i++;

  }

  //echo "</ol>";

}

 

echo "<br>";

echo '<a href="register.php">back</a>';

}

?>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/120391-php-form-validation/
Share on other sites

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.