Passing variables to fill a form

Discussion in 'PHP' started by coool, Aug 11, 2007.

  1. coool

    coool New Member

    Joined:
    Jul 12, 2007
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    Hi :)

    anyone knows how can I send variables from a php page to a form - i need to fill the form with these variables ?

    maybe using (the process of passing variables to other pages - through url)

    but how can i assign them to form variables ?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83
    Your form page is also a PHP Page and you will get them as _GET and _POST
     
  3. coool

    coool New Member

    Joined:
    Jul 12, 2007
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    page.php
    HTML:
    
    <?php
    $items = "item1,item3";
    ?>
    
    <a href="form.php?selectedItems=<?=$items?>" >View Form<a/>
    
    

    form.php
    HTML:
    <form name="selectionform" method="post" action="">
    
                  <select  size="3" multiple name="selectedItems[]">
                    <option value="item1">Item1</option>
                    <option value="item2">Item2</option>
                    <option value="item3">Item3</option>
                  </select>
    
                  <input type="submit" value="View Result">
    </form>
    
    What I'm looking for is when user click "View Form" link, they get the for filled with items - i.e some items are alreay selected ---- then if the user want to deselect one of the items or select more items he should able to do that.. !

    to check the result: - in form.php
    PHP:
    if($_POST)
        echo 
    implode($_POST['selectedItems'],",");
    so what do you think ? having $_GET inside form.php will solve the problem ! .. but I've tried it and it doesn't work.. I didn't know how to handle the array and nothing selected !! .. can you take my sample code and add to it the proper things so it will work ! please
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83
    Here goes the example

    page.php
    HTML:
    <a href="form.php?selectedItems=SomeValue" >View Form<a/>
    
    form.php
    HTML:
    <?php
    $items = $_GET['selectedItems'];
    ?>
    
    <form name="selectionform" method="post" action="">
        <input type="text" name="replyname" size=30 value="<?php $items; ?>">
        <input type="submit" value="View Result">
    </form>
    
    Other all options like explode and other things are cosmetic changes.

    Also I have not verified the code and so don't go for the syntax but see the semantics for it.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice