null input from multiple selection list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

null input from multiple selection list

Post by sh33p1985 »

theres an element to my php form that allows the user to make multiple selections from a list. i know how to handle multiple selections when the form is submitted, but how do i capture and handle the scenario if no selections are made (i.e. the user should select at least 1 option from the list).

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Typically, the field will not appear in the submission data, or will only appear with the default selection depending on how you've written the field.
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

default is nothing selected, so when the script is invoked via the submit button

Code: Select all

$availableSizes = $_POST['availableSizes'];
will throw an error no?

i want to catch that and throw it back to the form and inform the user than they did not make any selection.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

if ( !isset($_POST['availableSizes']) ) {
...
}
Post Reply