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 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    Kelowna, British Columbia
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    having problems passing variables from one page to another

    Hello, I've been playing with this one for a long time and I can't see why these variables are not being passed to another page via a form and hidden input fields. The code echo's some of the variables on the same page they are on no problem, but won't pass them. Here's the code:
    PHP Code:
    elseif ($item_cash == 0.00) {
                            echo 
    "<form method='post' action='order_form.php'>
                            <ul><li><span class='mytext'>$item_code - </span><span class='mytext2'>
                            <i> $item_desc</i></span><span class='mytext'> - $item_points points </span>"
    ;
                            echo 
    "<input type='hidden' name='code' value='$item_code'>";
                            echo 
    "<input type='hidden' name='desc' value='$item_desc'>";
                            echo 
    "<input type='hidden' name='points' value='$item_points'>";
                            echo 
    "<input type='hidden' name='cash' value='$item_cash'>";
                            echo 
    "<input type='hidden' name='name' value='$prod_name'>";
                            echo 
    "<input type='hidden' name='cityname' value='$city'>";
                            echo 
    "<input type='hidden' name='prdesc' value='$prod_desc'>";
                            echo 
    "<input type='hidden' name='pic' value='$prod_image'>";
                            echo 
    "<input type='hidden' name='exmonth' value='$expiry_m'>";
                            echo 
    "<input type='hidden' name='exday' value='$expiry_d'>";
                            echo 
    "<input type='hidden' name='exyear' value='$expiry_y'>";
                            echo 
    "<input type='image' src='pics/order.jpg' name='orderpic'>";
                            echo 
    "</form></ul>";
                        }
                            else {
                                echo 
    "<form method='post' action='order_form.php'>
                                <ul><li><span class='mytext'>$item_code - </span><span class='mytext2'>
                                <i>$item_desc</i></span><span class='mytext'> - $item_points points plus \$$item_cash </span>"
    ;
                                echo 
    "<input type='hidden' name='code' value='$item_code'>";
                                echo 
    "<input type='hidden' name='desc' value='$item_desc'>";
                                echo 
    "<input type='hidden' name='points' value='$item_points'>";
                                echo 
    "<input type='hidden' name='cash' value='$item_cash'>";
                                echo 
    "<input type='hidden' name='name' value='$prod_name'>";
                                echo 
    "<input type='hidden' name='cityname' value='$city'>";
                                echo 
    "<input type='hidden' name='prdesc' value='$prod_desc'>";
                                echo 
    "<input type='hidden' name='pic' value='$prod_image'>";
                                echo 
    "<input type='hidden' name='exmonth' value='$expiry_m'>";
                                echo 
    "<input type='hidden' name='exday' value='$expiry_d'>";
                                echo 
    "<input type='hidden' name='exyear' value='$expiry_y'>";
                                echo 
    "<input type='image' src='pics/order.jpg' name='orderpic'>";
                                echo 
    "</form></ul>";
                                } 
    and this is the code on the page I'm passing them to with just a simple echo statement, but they won't display
    PHP Code:
    echo '<br><br><span class="mytext"><b>This order form is for the Save-On-More catalogue code '.$_POST['item_code'].'</b>   </span> '
    Would this have anything to do with the forms being in loops? I have an isset on the page they are being passed to and they are not. thanks for any help...
    Last edited by percept; 01-23-2004 at 01:48 PM.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe i'm missing something, but i don't see any submitbutton. How are the forms submitted?

  • #3
    New Coder
    Join Date
    Dec 2003
    Location
    Kelowna, British Columbia
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am using an image as a submit button...
    When submitting a form, it is possible to use an image instead of the standard submit button with a tag like:
    <input type="image" src="image.gif" name="foo">
    so in my code above it is
    PHP Code:
    echo "<input type='image' src='pics/order.jpg' name='orderpic'>"
    I altered my submit statement to the traditional input type = 'submit' but still don't pass to next page.

    I don't understand why they aren't being passed because I have been using these images on other areas to submit forms... and I've been passing variables successfully on many other pages and even sites now...
    Last edited by percept; 01-23-2004 at 02:12 PM.

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah yes, sorry. I missed that.

    The problem is that tou use the wrong names to refere to the formfields.

    You have $_POST['item_code'] but there is no formfield with name="item_code"
    I supppose it is meant to refer to this field
    <input type='hidden' name='code' value='$item_code'>

    so you should use
    $_POST['code']
    to refere to it, or change the name of the formfield to name="item_code"

  • #5
    New Coder
    Join Date
    Dec 2003
    Location
    Kelowna, British Columbia
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh boy.... i can't believe I just spent about 5 hours on this one... I had the same name in as you just told me to and it wasn't working so I thought maybe a conflict because they were the same... but now I change them to the same and they work... (banging head on desk)

    but this is good to know because I thought it was the "value" and that "name" was actually irrelevant. now this is a solid rule i can adhere to.

    Thanks as always raf...

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're welcome.

    I thought it was the "value" and that "name" was actually irrelevant
    Nonono. The name is the only thing to reference the formfields. Which is logical since for most formfields, you wount know what value it will have when it is posted. In the formcollection, there is a variable-value pair for each formfield and it is the formfieldsname that will become the variablename.

    In your case, i would name the formfieldsthe same as the variable that is used to insert the value into it. So
    echo "<input type='hidden' name='item_code' value='$item_code'>";

    because then you can use multi-purpose pages where you post the form to itself and do the fpormprocessing in the same page. If there is an invalid value and you want to reload the page, then you can simply have

    echo ('<input type="hidden" name="item_code" value="'. $_POST['item_code'] . '" />';

    and the formfield will always contain the last entered text (or it will be empty on first load), no matter how often you reload or post it.


  •  

    Posting Permissions

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