Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Stay Selected after selected in a form...

    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
    Last edited by Jon W; 03-04-2009 at 12:27 AM.

  • #2
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    say like it was gender:

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

    PHP Code:
    <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

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I see. Very cut and dry. Thanks for the help! Anyone know anything about PHP functions for random_keys?

  • #4
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Here:

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

            for (
    $i=0;$i<=$len$i++) {
                
    $num rand() % 33;
                
    $tmp substr($chars$num1);
                
    $code $code $tmp;
            }
            return 
    $code;
        } 
    Change $chars to what letters/numbers/symbols are allowed in the random


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •