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

Help on Order Entry Form/System Where is best to begin.
I have a dilema and a very short amount of time at this point and I'm looking for some help on decid

some questions
Hello,

I am looking for the answers for following questions:

1) Does PHP support overl

Extracting URL pointer within XML tag
Hi.

I'm trying to extract text between two quotation marks in XML. For example, I want to ex

Linked Keywords
I am trying to get a script that makes my predefined keyword converted to links and / or converted t

Using Windows message as a Handle
Hi,

I am writing one of my first multithreaded programs.

In one of the thread,

Delete all files in folder except with certain name
I have a script that I want to delete all files in a folder (taken from a database) except for one n

reading xml faster than DB call?
I am trying to optimize a high traffic website, and I enabled a feature where there are three photos

login to other site by sending post variables
hey,

here is my problem: my school gave me a mail account for school-stuff use. they mail us

Sharing PHP Sessions Across Domains
I am in the process of writing a script to share a php session across various domains I have.
The

I apologise! It's a newbie to PHP feedback form problem!
Hi,

I am a total newbie to PHP. I am also a unemployed and need to get a job. So after 100% r

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