#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    5
    Rep Power
    0

    Problem retrieving HTML form values


    I'm totally starting this over as I've learned a little and can at least simplify the issue.

    My form is submitted using method="post". I don't know if that's relevant or not.

    Here is an example of one of the form inputs:

    Code:
    <strong>Would you consider a watch?</strong>
    <div style="margin:0px 8px 20px 15px;">
    <input id="watch" type="radio" name="watch" value="y" />Yes 
    <input id="watch" type="radio" name="watch" value="n" /> No
    </div>
    On the processing page,

    Code:
    $mywatch = $_POST["watch"];
    
    if ($mywatch == "y") {
         $this_watch = "y' OR watch = 'n";
    }  else {
         $this_watch = $mywatch;
    }
    var_dump($mywatch); is NULL

    I definitely selected a value on the form page, so why can't I retrieve it?

    Don't know if this will help, but when I set method="get", here is what I get attached to the URL:

    ?price=med&size%5B0%5D=med&watch=n&alt_targets=b&bignumbers=n&hole_views=b&button=Get%20Product%20Re commendations

    Sorry I don't really know much PHP, but would really appreciate any help I can get.

    Thanks.
    Last edited by vbrennan; October 11th, 2012 at 07:01 PM. Reason: Simplifying the Problem
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    5
    Rep Power
    0
    As you might notice in the title, this code, or something very similar was working and a few cosmetic changes later, it stopped working.

    Is there any sort of variable flushing that I might need to do?
  4. #3
  5. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,111
    Rep Power
    1990
    I can see one problem straight away. You are using a query string for your values, but you are trying to access them using $_POST instead of $_GET.

    It should be:
    PHP Code:
    $mywatch $_GET["watch"]; 

    Comments on this post

    • Jacques3 disagrees : He changed the method to GET for testing (at least that's what he said)
  6. #4
  7. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    0
    Hi,

    it's hard to tell what the problem is when we've only got some code snippets (that should indeed work). Either post the complete form and processing scripts. Or do the debugging yourself:

    1. boil the code down to the minimum and uncomment everything else. Something like this

    form script
    PHP Code:
    <form action="(insert filename)" method="post">
        <
    strong>Would you consider a watch?</strong>
        <
    input id="watch" type="radio" name="watch" value="y" />Yes 
        
    <input id="watch" type="radio" name="watch" value="n" /> No
        
    <input type="submit" />
    </
    form
    processing script
    PHP Code:
    <?php
        var_dump
    ($_POST);
    2. Before you test the script, open the development tools of your browser (if you don't know how, google it) and go to something like "network" where you can see the request and response. Then you'll be able to see if the form data is even submitted.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    5
    Rep Power
    0
    Originally Posted by Jacques3
    Hi,

    it's hard to tell what the problem is when we've only got some code snippets (that should indeed work). Either post the complete form and processing scripts. Or do the debugging yourself:

    1. boil the code down to the minimum and uncomment everything else. Something like this

    form script
    PHP Code:
    <form action="(insert filename)" method="post">
        <
    strong>Would you consider a watch?</strong>
        <
    input id="watch" type="radio" name="watch" value="y" />Yes 
        
    <input id="watch" type="radio" name="watch" value="n" /> No
        
    <input type="submit" />
    </
    form
    After I stripped the form code down to a minimum, it started working. So then I just added stuff back one piece at a time and now it's working. So thanks for your indirect assistance!

IMN logo majestic logo threadwatch logo seochat tools logo