...

View Full Version : Stay Selected after selected in a form...



Jon W
03-04-2009, 01:21 AM
So I'm making a register page for my site. My problem here is say for example a person forgets to fill in a field, not a big deal, just have PHP fill in everything that they just filled in back. Well, I can do this with the inputs and textareas but I'm not to sure how this is done with the select and the radios. How can this be done? Also is there a function in PHP that will make a random key. Kinda like something like this... "a45aljlj2344ljj54541" lol


Thanks,
Jon W

sea4me
03-04-2009, 01:46 AM
say like it was gender:

you would have say male stored in $gender, then something like this will work:



<select>
<option value="male"<?php if($gender=="Male"){ echo "selected"; } ?>>Male</option>
<option value="female"<?php if($gender=="Female"){ echo "selected"; } ?>>Female</option>
</select>


There may be an easier solution but this is the one that I use :thumbsup:

Jon W
03-04-2009, 02:04 AM
I see. Very cut and dry. Thanks for the help! :) Anyone know anything about PHP functions for random_keys?

sea4me
03-04-2009, 03:41 AM
Here:


function CreateRandomCode($len) {
$chars = "abcdefghijkmnpqrstuvwxyz23456789";
srand((double)microtime()*1000000);
$code = '' ;
$len++;

for ($i=0;$i<=$len; $i++) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$code = $code . $tmp;
}
return $code;
}

Change $chars to what letters/numbers/symbols are allowed in the random



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum