Re: combo box validation

From: Date: Wed, 09 Jun 2010 07:57:50 +0000
Subject: Re: combo box validation
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-305991@lists.php.net to get a copy of this message
On 07/06/10 18:49, David Mehler wrote:
Hello, I've got a form with two combo boxes, one for the month one for the day. Both are required. I've got code that checks the post submission to ensure neither is empty. My problem is that if a user does not select anything in the combo boxes January first is sent, this i don't want. If they haven't selected anything i'd like that to show as an error. Thanks. Dave.
It's not really php, but if you make the default option of each combo return an empty value then you can assume that the user didn't choose anything and flag the error: Like: <select name='month'> <option selected='selected' value=''>Select One</option> <option value='january'>January</option> ... </select> You should find that if the empty option is selected the PHP will not receive a value in $_REQUEST['month'], or at least it will be something equivalent to NULL. -- Peter Ford, Developer phone: 01580 893333 fax: 01580 893399 Justcroft International Ltd. www.justcroft.com Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom Registered in England and Wales: 2297906 Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

« previous php.general (#305991) next »