Jump to content

[SOLVED] <select> form validation (PHP) - need help


unsider

Recommended Posts

I've recently resolved a past issue with the input, but now validating if it is set with PHP is the problem. While I ultimately will validate it both client side and serve side my main objective is validating with PHP atm.

 

I've been able to validate all other form types, but not <select> forms.

 

I can choose any value from 1-4 and have it input the correct id number, but if I leave it set to "-1" it inputs the 0 default, and it should be returning an error.

 

All simply validation, I'm not having any errors inputting.

 

Here's my form

<select name="cat">
<option value="-1" selected="selected">&nbsp</option>
<option value="1">test</option>
<option value="2">testi</option>
<option value="3">testin</option>
<option value="4">testing</option>
</select>

 

I'm using a quick test below to validate it's existence.

 

if(!isset($_POST['cat'])) {
echo "not set";
exit();
}

 

But unfortunately this does not catch anything as it inputs a default value of 0 into the DB field.

Which by the way is: cat_id, int, 11, NULL: NO, default: 0

 

Are there any other methods of validating if the select field selection is not set on the "-1" option.

 

Or another method of doing this?

 

This is really frustrating me, as this should be one of the most simple operations, but I just can't resolve it.

 

Anything, PLEASE i really need to solve this problem. Tutorials, code, code you've used in the past. ANYTHING.

 

???

 

 

 

you may try this:

 

<select name="cat">
        <option value="">Select Any</option>
<option value="1">test</option>
<option value="2">testi</option>
<option value="3">testin</option>
<option value="4">testing</option>
</select>

<?php
if(isset($_POST['cat']) && empty($_POST['cat'])) {
echo "not set";
exit();
}
?>

you may try this:

 

<select name="cat">
        <option value="">Select Any</option>
<option value="1">test</option>
<option value="2">testi</option>
<option value="3">testin</option>
<option value="4">testing</option>
</select>

<?php
if(isset($_POST['cat']) && empty($_POST['cat'])) {
echo "not set";
exit();
}
?>

 

Unfortunately this did not work either. Went right by it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.