Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.