Checking if field is empty AND using !is_numeric


Posted on 16th Feb 2014 07:03 pm by admin

Hi lads,

Need to be able to display an error message (using isset?) that says "Cant leave field blank" when someone clicks on submit after leaving the field blank. The problem is that I'm also using the !is numeric function and that has an error message of "please enter numbers only" . Problem is that if someone leaves the field blank, the !is_numeric function picks up that there are no numbers before isset does and therefore outputs "please enter numbers" .

Anyone have any idea's how to fix this ?
My code is :

| <?phpfunction validate_form(){ $entered_grade = trim($_REQUEST['entergrade']); $error = ''; if (! isset($entered_grade)) { $error .= "<span class="error">You cannot leave the grade blank. Enter a mark between 0 and 100.</span>
"; }if (! is_numeric($entered_grade)) { $error .= "<span class="error">Invalid Input. You must enter a NUMBER between 0 and 100</span>
"; } if ($entered_grade >=101 ) { $error .= "<span class="error">Invalid Input. The marks must be between 0 and 100.</span>
"; } return $error;}

Thanks

No comments posted yet

Your Answer:

Login to answer
262 Like 9 Dislike
Previous forums Next forums
Other forums

cPanel API
Hi Guys,

Need a little guidance. I'm trying to get my script to communicate with cPanel (or W

Help building / using array
First - this is a cross-posting, if this is wrong I apologise! What started out as a MySQL query que

Change log of Cost centre change in Plant maintenance order
Hi,
How to view Change log of Cost centre in Plant maintenance order. Not visible thru 'Docume

Multipe Dynamic Controls & AutoPostback Issue
I currently have a need to create many dynamic controls (Example Textboxes) that need to do a PostBa

Need help with some php code :)
Hey! I'm quite new to this whole thing, so please don't fire me with shait on this one =D

I'm

Problem with Sending Mail by PHP
hello all,
I m new to php, can u plz provide me the code to send mail by php having CAPTC

disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte

Header is not working in IE
Hi ! header function is not working in IE but it works in FF, Safari, Chrome. any help please. :

IP question
ive got 2 ip addresses both global from same user how would i detect if they are local to each other

problems with contact forms that are only protected against SQL injections
What could be a potential problem with contact forms that are only protected against SQL injections

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash