Verification in Forms

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

Post Reply
phpRoundX
Forum Newbie
Posts: 7
Joined: Mon Dec 30, 2002 6:43 am

Verification in Forms

Post by phpRoundX »

Hi,
I've made a form for user-Adds. I want to verify, that one textfield is checked for "not empty" and one other checked for- it has to be an int oder double.

e.g.
if (empty($_POST[C]))
{
echo "here's the output, when if ist TRUE<br>";
}


I've done all with POST and everything ist fine with empty, but how can a form-textfield be checked for, that the Value has to be a Number?
Can I make this wir is_int oder is_double somewhere in the IF-Block. Some like:
if ( (empty($_POST[C])) && (is_integer($_POST[A])) )
.... bla

?????

Jan
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can do this:

Code: Select all

if (empty($_POST['C']) && is_numeric($_POST['A'])) {
    // blah
}
Don't forget the quotes around the array elements ($_POST['C'] instead of $_POST[C]) for why see this page:
http://www.php.net/manual/en/language.t ... rray.donts

Also you would use is_numeric() instead of is_integer() because:
PHP Manual - is_int() wrote:Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric().
Mac
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

Hi,


try preg_match() here:


if ( (empty($_POST[C])) && (preg_match("/[0-9]+/",$_POST[A])) )
phpRoundX
Forum Newbie
Posts: 7
Joined: Mon Dec 30, 2002 6:43 am

you're Legends :)

Post by phpRoundX »

thx for that fast help.

Jan
Post Reply