Page 1 of 1
Checking to see if Field was Submitted empty
Posted: Sun Apr 24, 2005 3:21 pm
by anthony88guy
When I use the following script, its doesnt return "Please Fill In all the Fields." when the field is empty. If you need all the code tell me.
Posted: Sun Apr 24, 2005 3:30 pm
by thegreatone2176
if you want to check for something being posted use
Code: Select all
if ($_SERVER['REQUEST_METHOD'] == 'POST')
also you have || to check for empty fields which means if they are both empty it will still update
Posted: Sun Apr 24, 2005 3:30 pm
by thallish
hi
i would use isset() for checking if it exist before stripping the $_POST array and then check to see if it's empty
Code: Select all
if(isset($_POSTї'variableName']))
{
if($_POSTї'variableName'] == "e;"e;)
{
echo "e;Please fill the field that corresponds to the relevant variable name"e;;
}
else
{
// do your thing here
}
}
else
{
echo "e;Nothing Posted"e;;
}
regards
thallish
Posted: Sun Apr 24, 2005 5:48 pm
by nigma
thegreatone2176 wrote:also you have || to check for empty fields which means if they are both empty it will still update
I think what he's trying to say is that if one is empty and the other isn't then it'll still update, which is the case. Instead you should be using
&&.
Thallish, what's the reasoning behind checking to see if it exists first, and only if it does checking to see if it has a value?
RE:
Posted: Sun Apr 24, 2005 8:25 pm
by harrisonad
When a form is submitted using POST method, all of it's member inputboxes, selectionboxes, and other elements are also submitted with their values in it. Now, if the user didn't completely fillup the form, $_POST variables will still be sent and contains their own default values.
So, what i am trying to explain is...checking for the existence of $_POST as in:
... doesn't ensure you that the form is empty.
Instead, get all the $_POST variables you need:
Code: Select all
$id = $_POST['id'];
$operation = $_POST['operation'];
// etc.
and then check each variables for NULL values:
Code: Select all
if($id && $operation){
// do stuff...
}
Posted: Sun Apr 24, 2005 9:16 pm
by anthony88guy
Thank you, harrisonad
Now it works.
Edit: Doesnt work right.
Posted: Mon Apr 25, 2005 2:17 am
by thallish
nigma wrote:
Thallish, what's the reasoning behind checking to see if it exists first, and only if it does checking to see if it has a value?
For error protection, if all the relevant variables dosen't exist then it can make errors in your code. if for exampel some visitor come from a site other than the site with the form and you make a lot of work on the variables in the $_POST array then you would get errors cause the don't exist. thats the reasoning. but if anybody knows a better method then be sure to "post reply"
harrisonad wrote:
Instead, get all the $_POST variables you need:
Code: Select all
$id = $_POST['id'];
$operation = $_POST['operation'];
// etc.
and then check each variables for NULL values:
Code: Select all
if($id && $operation){
// do stuff...
}
isset() does the same to my understanding and you would have saved some effort.
regards thallish
Posted: Mon Apr 25, 2005 2:25 am
by hongco
besides others' suggestions, you can also consider either:
1- use session to save any info had been filled out by the user. this to prevents him from writing all over again if he missed to fill out 1 field,
2- or use javascript to check if all required fields have been filled onSubmit action.
re
Posted: Mon Apr 25, 2005 2:32 am
by harrisonad
With due respect, thallish, isset() function tells if a variable has been defined. as the holy scripture said:
Code: Select all
bool isset ( mixed var ї, mixed var ї, ...]])
- Returns TRUE if var exists; FALSE otherwise.
but it will also return true in submitted empty form.
read the bible.
Posted: Mon Apr 25, 2005 5:54 am
by thallish
harrisonad wrote:With due respect, thallish, isset() function tells if a variable has been defined. as the holy scripture said:
Code: Select all
bool isset ( mixed var ї, mixed var ї, ...]])
- Returns TRUE if var exists; FALSE otherwise.
but it will also return true in submitted empty form.
read the bible.
maybe I didn't make myself clear, but if you try to read my reply then you would see that i actually write that it is used to check if it exist. thats why the check to see if the variable is empty is used
thallish
Posted: Mon Apr 25, 2005 8:06 am
by anthony88guy
Sorry guys but it doesnt work. The following code will return "Please Fill In all the Fields." at everything you submit at it. It will never return "Farm $fuser was updated." This is <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> me off now. In other pages I used
to see if the field was emtpy. But in this case that returns "Please Fill In all the Fields.". I need some help.
Posted: Mon Apr 25, 2005 8:36 am
by n00b Saibot
anthony88guy, in the code you posted there is nowhere you check for the vars being empty. you just check for their existence which they will, even if they are submitted empty. so change you line 12's if condition to include vars being blank.
Code: Select all
if(trim($fuda) != '' && trim($fuparmysize) != '') {
i trimmed them to remove any spaces from them before checking.
Posted: Mon Apr 25, 2005 8:51 am
by anthony88guy
Same error. Thats the basicly the same thing I had before. I'll post all the code. We are looking at lines 108-115.
Click on "" on the navigation, then in the form just press "" Now hopefully some "" should come up. On the right their is an update button, Click it. Then play around with the form, doesnt work right. You cant harm anything since I will be dumping the tables. Thanks for the help and time you put into this.
Posted: Mon Apr 25, 2005 10:51 am
by n00b Saibot
Sorry for posting late... i was busy in my work
now there is a typo
Code: Select all
if(trim($fuda) != '' && trim($fuparmysize) != '')
should be
Code: Select all
if(trim($fupda) != '' && trim($fuparmysize) != '')
also print them out before checking them...
when i removed most of you extra stuff and corrected the above typo it started responding correctly...
Posted: Mon Apr 25, 2005 2:26 pm
by anthony88guy
Thank you n00b Saibot, Now it offically works. I should of caught the incorrect variable.