Jump to content

check arrays


esport

Recommended Posts

Hi Guys,

I am posting a form that consists of an array.

 

<select name="model[]" class='forminput' id="model">

 

I am trying to do some form validation to check if the user has selected from the drop list. Since the POST value is returned as an array, if there is no value selected, it still picks up a value.

 

How do I determine if the array is empty? I have tried to use the empty function but no luck.

 

Thanks in advance.

 

Daniel

Link to comment
https://forums.phpfreaks.com/topic/118729-check-arrays/
Share on other sites

So if in your form you have selected="selected" set to a null value or placeholder, when the form is processed, you will redirect the user back to the form if the null value or placeholder was posted because it is not in the array of acceptable values. For instance, consider that the value of $model = null:

 

$model_possibilities = array("1","2","3","4","5","6-10","11-15","16+","dont_know");
if(in_array("{$_POST['model']}", $model_possibilities)){
$model = $_POST['model'];
}else{
        //redirect back to the form...
}

Link to comment
https://forums.phpfreaks.com/topic/118729-check-arrays/#findComment-611330
Share on other sites

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.