[PHP] Re: combo box validation

2010-06-09 Thread Pete Ford

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 89 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: combo box

2003-12-02 Thread Seung Hwan Kang
If I were you, I do this way.

// in your HTML form.

select name=flag
option value=1 Husband/option
...
/select
// DB
then insert 1, 2, 3, 4. //it will be one of them from flag variable.
// when you retrieve it...

if (flag == 1)
echo Husband
if ...
and so on. :)

Kang

Chan Hweefarn Saputra wrote:
hi :)

i am creating a webpage. i use a combo box to let user
choose which folder they want.
after they choose, it will be saved into the database.
the next time they load this page, it will retrieve
the data from database and appear at the combo box.
i already done that.
but now the problem isthe data that i retrieve
from the database will same with the options in the
combo box.
so, it will become 2 same options. i am afraid this
will confuse the user. so i want to fix it.
if u dont understand what i mean, try look at the
picture   coding below:
folder: husband
  friend
  family 
  boss
  husband
___
this is the code:

select size=1 name=groupMailbox1 
option?php echo $row[groupMailbox1]; ?/option
?php 
//Open Directory you want to include 
//$base='/home/a/mail';
$handel = opendir($base); 
//Get contents of the directory 
while (false !== ($file =
readdir($handel))) { 
if (is_dir($base . / .
$file)  ($file !== .)  ($file !== ..)) { 
list($filename, $ext) =
explode(., $file); 
list($main, $sub, $include) =
explode(/, $PHP_SELF); 
echo option value=\$file\; //Echo
the file name in a combo box 
if ($inc==$file) echo 
selected;  
echo$file/option\n; 
echo $file; 
} 
} 
?
/selectp/p

___

how to make it so that the data that we retrieve from
database, if same with the options we have, we only
need to make that option selected?
thanks :)

hweefarn 

__
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php