Results 1 to 2 of 2

Thread: PhP: set values

  1. #1

    PhP: set values

    Hi. I'm having a pretty hard time figuring how to do something... In a nutshell, I have a form, when submitted it calls a php page that emails me the form, if it can't email it, it stores the form field values in a txt file, then calls up another php page, which is actually the form with the fields already populated (the field values are read from the file and assigned to the respective fields). What I'm having trouble with is some checkboxes and radios: they already have values assigned to them, so I don't know how to check them if they were previously checked.
    Anyway...maybe part of the code will clear things up a bit:
    Code:
    <?php
    $fis_txt=fgets($eroare, 102400);
    $text_txt=fgets($eroare, 102400);
    $nav_sel=fgets($eroare, 102400);
    for($i=0; $i<22; $i++)
     {$navs.$i=fgets($eroare, 102400);}
    ?>
     
    <html>
    <input type="radio" name="Text" value="Fisier" onClick="Val_text();Cont_pag2();">Check the one that was previously checked
    <input type="radio" name="Text" value="Text" onClick="Val_text();Cont_pag2();">Check the one that was previously checked
    <input type="file" name="Fis_txt" size="100" value="<?php echo $fis_txt; ?>" onChange="Cont_pag2()">
    <textarea name="Text_txt" cols="80" rows="10" value="<?php echo $text_txt; ?>" onKeyUp="Cont_pag2()">
     
    <input type="checkbox" id="Navs0" name="Navs0" value="1" onClick="Cont_pag5_3()">Check it if it was previously checked, if not leave it unchecked
    <input type="checkbox" id="Navs1" name="Navs1" value="1" onClick="Cont_pag5_3()">Check it if it was previously checked, if not leave it unchecked
    <input type="checkbox" id="Navs2" name="Navs2" value="2" onClick="Cont_pag5_3()">Check it if it was previously checked, if not leave it unchecked
    And so on until Navs21
    </html>
    Well...like I said, this is just a small part of the code...the entire file has about 80KB...
    Anyway...If the checkbox was previously checked, in the txt file the respective line would say ON, if it was unchecked it would say OFF. And for the radios, the txt file would contain the value of the one that was checked.

    So...How do I go and do that? Any help will be very much appreciated...

  2. #2
    icio's Avatar
    3,811
    posts
    looks better in lowercase
    For the checkbox you can do something like:
    PHP Code:
    <?php
        
    echo '<input type="checkbox" name="agree" '. (isset($_POST['agree']) ? 'selected="selected"' '') .'/>';
    ?>
    And for the radio buttons you can do something like:
    PHP Code:
    <?php>
        echo 
    '<input type="radio" name="option" value="1" '. ($_POST['option'] == '1' 'selected="selected"' '') .'/>';
        echo 
    '<input type="radio" name="option" value="2" '. ($_POST['option'] == '2' 'selected="selected"' '') .'/>';
        echo 
    '<input type="radio" name="option" value="3" '. ($_POST['option'] == '3' 'selected="selected"' '') .'/>';
        echo 
    '<input type="radio" name="option" value="4" '. ($_POST['option'] == '4' 'selected="selected"' '') .'/>';
        echo 
    '<input type="radio" name="option" value="5" '. ($_POST['option'] == '5' 'selected="selected"' '') .'/>';
    ?>
    I would recommend simplifying the process by incorporating these methods into functions. Hope that helps
    "60% of the time it works... every time." -- Paul Rudd as Brian Fantana.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012