Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.