Jump to content

form validation


cs1h

Recommended Posts

You need to use the empty() function.

Learn from this example:

 

<form action="<?php echo basename($_SERVER['PHP_SELF']); ?>" method="POST">
<input type="text" name="field1"><input type="submit" name="submit">
<br>

<?php

if(isset($_POST['submit']))
{
if(empty($_POST['field']))
	echo "<center><font color=red>Fill in the Field!</font></center>";
}

?>

 

Orio.

Link to comment
https://forums.phpfreaks.com/topic/70364-form-validation/#findComment-353475
Share on other sites

when you submit a form, it is sent via either GET or POST. PHP can then get the values using the name for each form element. For instance, if you have a form that POSTs to a PHP file and one of the form elements is a text field with the name test_field, in the PHP file, you can get the value like this:

 

$a_variable = $_POST['test_field'];

 

Then compare the value of $a_variable to the allowed values. If $a_variable != $allowed_value, display an error. It's the same with GET.

Link to comment
https://forums.phpfreaks.com/topic/70364-form-validation/#findComment-353492
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.