Checking to see if Field was Submitted empty
Moderator: General Moderators
-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
Checking to see if Field was Submitted empty
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.
Last edited by anthony88guy on Thu May 12, 2005 5:45 pm, edited 1 time in total.
-
thegreatone2176
- Forum Contributor
- Posts: 102
- Joined: Sun Jul 11, 2004 1:27 pm
if you want to check for something being posted use
also you have || to check for empty fields which means if they are both empty it will still update
Code: Select all
if ($_SERVER['REQUEST_METHOD'] == 'POST')hi
i would use isset() for checking if it exist before stripping the $_POST array and then check to see if it's empty
regards
thallish
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;;
}thallish
Last edited by thallish on Mon Apr 25, 2005 2:19 am, edited 1 time in total.
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 &&.thegreatone2176 wrote:also you have || to check for empty fields which means if they are both empty it will still update
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?
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
RE:
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:
and then check each variables for NULL values:
So, what i am trying to explain is...checking for the existence of $_POST as in:
Code: Select all
if($_POST){
// do stuff
}Instead, get all the $_POST variables you need:
Code: Select all
$id = $_POST['id'];
$operation = $_POST['operation'];
// etc.Code: Select all
if($id && $operation){
// do stuff...
}-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
Thank you, harrisonad
Now it works.
Edit: Doesnt work right.
Now it works.
Edit: Doesnt work right.
Last edited by anthony88guy on Mon Apr 25, 2005 8:07 am, edited 1 time in total.
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"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?
isset() does the same to my understanding and you would have saved some effort.harrisonad wrote:
Instead, get all the $_POST variables you need:
and then check each variables for NULL values:Code: Select all
$id = $_POST['id']; $operation = $_POST['operation']; // etc.
Code: Select all
if($id && $operation){ // do stuff... }
regards thallish
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
re
With due respect, thallish, isset() function tells if a variable has been defined. as the holy scripture said:
but it will also return true in submitted empty form.
read the bible.
Code: Select all
bool isset ( mixed var ї, mixed var ї, ...]])
- Returns TRUE if var exists; FALSE otherwise.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 usedharrisonad wrote:With due respect, thallish, isset() function tells if a variable has been defined. as the holy scripture said:
but it will also return true in submitted empty form.Code: Select all
bool isset ( mixed var ї, mixed var ї, ...]]) - Returns TRUE if var exists; FALSE otherwise.
read the bible.
thallish
-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
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.
Code: Select all
if($var != "")
Last edited by anthony88guy on Thu May 12, 2005 5:59 pm, edited 1 time in total.
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
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.
i trimmed them to remove any spaces from them before checking.
Code: Select all
if(trim($fuda) != '' && trim($fuparmysize) != '') {-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm
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.
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.
Last edited by anthony88guy on Thu May 12, 2005 6:00 pm, edited 2 times in total.
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
Sorry for posting late... i was busy in my work
now there is a typo
should be
also print them out before checking them...
when i removed most of you extra stuff and corrected the above typo it started responding correctly...
now there is a typo
Code: Select all
if(trim($fuda) != '' && trim($fuparmysize) != '')Code: Select all
if(trim($fupda) != '' && trim($fuparmysize) != '')when i removed most of you extra stuff and corrected the above typo it started responding correctly...
-
anthony88guy
- Forum Contributor
- Posts: 246
- Joined: Thu Jan 20, 2005 8:22 pm