I have a HTML form, with hidden fields, that are populated by PHP (this part is working, seen when you View Source on the page with the form HTML)

the action is set to POST to process.php, process.php is set to return the POST data in an echo, but they are always blank.... I do not understand why 🙁 🙁

If you F5 on the process.php, IE tells you its going to resubmit the data, so data is being parsed. If I use GET on the form instead, the values can be seen in the URL, but I wish to keep them hidden

the form HTML/PHP combo (working):

// form.php

print "
<form name=\"$machinename\" action=\"process.php\" method=\"POST\">
<input type=\"hidden\" name=\"random\" value=\"$random2\">
<input type=\"hidden\" name=\"machinename\" value=\"$machinename\">
<input type=\"hidden\" name=\"ITSS\" value=\"$cn2\">
<input type=\"hidden\" name=\"takemeback\" value=\"$url\">

middle section removed, no user input fields in this form at all, just hidden fields

<input type=\"image\" name=\"button\" src=\"images/setreturn1.gif\" onClick=\"return confirm('Please confirm that $machinename has now been returned.');\">

</form>
";

// View Source results, from IE - proof $'s are being populated

<input type="hidden" name="random" value="COOL31472">
<input type="hidden" name="machinename" value="UKW1TESTMACHINE">
<input type="hidden" name="ITSS" value="Indo">
<input type="hidden" name="takemeback" value="http://localhost/form.php">
// process.php

<?php

$username = $_POST["ITSS"];

echo "Hello $username";

?>

Running PHP on Windows, using Apache

Thanks for any help 🙁

    Looks okay to me. I would try some additional troubleshooting code.

    In process.php, before any other code I would check your POST array:

    <?php
    print_r(array_values($_POST));
    exit;
    ?>

    If there is NO post data, then you need to look at your form action and/or submit button. If it is just the one value, then I'd look for errors in the originating HTML (perhaps a quote or symbol out of place).

    One of the things that I often have to watch for is where I place variables in relation to my includes. For example, if I set the value of $username at the top of my page, then I include my right navbar (which gets it's own $username to output "Welcome $username"), well...you can see the problem. It would be ideal if I could always remember to use a unique variable name, but such is not always the case.

      the print_r says this for me when i added values to the hidden fields manually:

      what is your php version ?

      Array
      (
          [random] => 
          [machinename] => 
          [ITSS] => qweqwe
          [takemeback] => 
          [button_x] => 14
          [button_y] => 18
      )
      

        Hi guys,

        Thanks for the suggestions, have now tried printing the post array - comes back blank

        using GET works (if I change the form method to get) but I do not want the values in the URL shown, POST is better for application

        I have stripped it right back to bare basics, simple form etc... and still post array is blank, so is the requests array

        Decided to upload it to a webhost, and it works perfect.... no issue using the POST method and PHP code to retrieve values from form, hidden or not.....

        SO, I guess that means, well its a config issue locally on the box im running.... what function in the php.ini would cause such an issue ????

        my local box has : PHP v5.2.6 and Apache/2.0.63 (Win32) on Windows XP

        remote webhost has : PHP v4.3.10 / Apache/1.3.29 (Unix) (Red-Hat/Linux)

        info collected from phpinfo();

        sorry if i have missed something obvious.... can I compare php.ini using phpinfo? as I cannot change the remote webhost, but of course, have full access to my local box 🙂

          did you tried

          method="post"

          with lowercase ?

          try to print this

              if (ini_get('register_globals'))
              {
                  print "you have to change this register globals settings on your local system!";
              }
          else
          {
          echo "This settings is okay in your config";
          }

            I am at home now and cannot test the lowercase post, within HTML however, on windows, that should not matter, but will try it!

            I printed a phpinfo(); before I left, to read on train and my box has register_globals OFF (this is some security thing with >php v5?)

            I have uploaded it to a two dev servers, through a friend, different versions of PHP and both have reigster_globals OFF and it works fine on their dev servers!! 🙁

            confusing!!

              Have you tried just a simple <input type="submit" value="submit"> rather than your customized button?

                Yeah what is that javascript doing

                  Couple of incidental points:

                  Why are you putting a bunch of pre-filled hidden fields into the form? If it's solely to pass data from one page to the next, using a [man]session[/man] would be safer.

                  You do know that there are ways to use images for submit buttons without abusing the image form field type, don't you?

                    Thanks for your replies

                    ixalmida;10905487 wrote:

                    Have you tried just a simple <input type="submit" value="submit"> rather than your customized button?

                    Yes, I have scrapped the above code and made a very simple HTML standard form, using normal fields and a normal button = same result

                    tried changing case of POST and post in the method for the form and setting an enctype and removing that = same result

                    the same test code and my code above, works on other boxes

                    foyer;10905493 wrote:

                    Yeah what is that javascript doing

                    the javascript, prompts the user to confirm that they wish to submit this form, to put this in context, this is a system for loan laptops, when a machine is returned, someone would visit the site and click the 'returned' image/button > this would update a database saying its been returned

                    Weedpacket;10905510 wrote:

                    Couple of incidental points:

                    Why are you putting a bunch of pre-filled hidden fields into the form? If it's solely to pass data from one page to the next, using a [man]session[/man] would be safer.

                    You do know that there are ways to use images for submit buttons without abusing the image form field type, don't you?

                    it is to pass the data to the process.php page, this page would the populate a mysql database using the information passed over. the fields are hidden, in the sense, no user input is needed. the php page listing the computers available for loan, finds the user visiting the site and collects their full name from Active Directory. this is to show exactly who clicked the return button

                    There will be more than on machine listed on the page, which is why i will be using more than one form (with unique form names of course)

                    As I understand, session information can be used to pass data from page to page, but this would not work in this application, as i have more than one possible item to pass over ??

                    What did I do wrong on the image submit button ?

                    Thank you,

                      this form you posted brings the form's values into a local process.php, which is needed to be on that laptop!

                      evry laptop has an apache server installed ?

                      if this program works on intraNet , why don't you make user login,
                      where user can select which computer is in used, which is free, ect.

                      You can "install" automatically generated html file to that laptop from your admin panel,

                      where you add that laptop, you get a unique laptop code,
                      the source code contains the hidden field with that laptop unique code, and the user can log in.
                      This is EASY.

                      You should use a better apache package, your's sounds bad with these bugs.

                      What did I do wrong on the image submit button ?

                      Why don't you use a normal submit button ?

                        sorry was not clear. this is not a loan system as such

                        1) loan machine given out

                        2) a batch file runs on loan machine, sends machine name, who logged in and other info to a log file on server.. apache not needed on laptop !!! its only a batch file, saving the .log file to the remote server

                        3) an intranet page is loaded by the IT admin team, whenever they feel like it, they can see which machines are in use (as log file sets it in use, when someone logs in to it), active directory lookups by PHP give the full user name, windows login name etc.... and shows it on screen

                        4) when customer brings machine back, they click a button to set this fact, this submits the form, and changes the record in the DB and shows machine as 'available' when the page refreshes. i want to record who clicked the button... so machines dont go walkabout

                        this is an intranet based application only


                        looking at workaround for this "bug" - going to use GET for some 'safe' values and the most important 'admin name' will be hidden via session variable, will see if this works better and as a workaround

                        will report back....

                        sorry if this is not clear enough :queasy:

                          had enough LOL.... moved on to working with sessions instead, its passing the 'secret' admin name and the rest of the 'safe' data I will move in the URL using GET

                          Thanks all .... unresolved, but had enough 😃 😃 🙂

                          Regards,

                            indo wrote:

                            As I understand, session information can be used to pass data from page to page, but this would not work in this application, as i have more than one possible item to pass over ??

                            You can store an arbitrary amount of data in a session. ("Arbitrary" being subject to things like disk capacity and such, naturally.)

                            What did I do wrong on the image submit button ?

                            The image input type is when you want to submit a pair of x/y coordinates. What you're after is either an ordinary submit button that has been styled using CSS to have an image background (instead of a plain grey one), or a button element that contains an image.

                              Ahh I see what you mean now. With the workaround ive coded, I am only passing one thing in the session, the rest goes via GET in the URL - no <FORM></FORM> business anymore, just a simple text link, that takes you to process.php

                              process.php does the DB stuff and gets the name from the session and then redirects back to the page you came from, to see the results

                              works well 🙂

                              Thanks all

                                indo wrote:

                                With the workaround ive coded, I am only passing one thing in the session, the rest goes via GET in the URL - no <FORM></FORM> business anymore, just a simple text link, that takes you to process.php

                                Well, that's kind of a back-to-front way of using sessions (where most everything goes in the session and only one thing at most is needed in the URL), but.... as long as you can trust everyone using this thing to not go fiddling with the URL and/or using it inappropriately (like bookmarking it).

                                  Write a Reply...