Vinoth
Vinoth

Reputation: 1359

HTML to PHP form data not submitting

I want to pass information from an HTML form to a PHP page. My problem is that the data from the form is not getting submitted. What am I doing wrong ?

HTML FORM

<div id="go">
    <form method="get" action="client_authorized.php">
        <fieldset>
            <input type="text" name="query" class="input-text" />
            <input type="submit" value="Secure Client Access" class="input-submit" />
        </fieldset>
    </form>
</div>

client_authorized.php

<?php
     print $_GET['query'];
?>

Upvotes: 3

Views: 7630

Answers (2)

tomsseisums
tomsseisums

Reputation: 13377

<div id="go">
    <!-- see the moved `target` attribute from other form element to here -->
    <form target="_blank" method="get" action="client_authorized.php">
        <fieldset>
            <input type="text" name="query" class="input-text" />
            <!-- <form target="_blank"> -->
            <input type="submit" value="Secure Client Access" class="input-submit" />
            <!-- </form> -->
            <!-- this form here is as useless as these comments are, define target in main form -->
        </fieldset>
    </form>
</div>

Basicly your second <form/> overrides first <form/> elements, therefore loses data when posted.

Oh, by the way PHP's print(); won't print out your array data (at least I think so..), you should use print_r(); or var_dump(); instead.

Upvotes: 4

Michael Berkowski
Michael Berkowski

Reputation: 270775

Your submit button is wrapped in another <form>. This should be an <input type='submit'> instead. Just remove the extra <form></form>.

<div id="go">
  <form method="get" action="client_authorized.php">
    <fieldset>
        <input type="text" name="query" class="input-text" />
        <input type="submit" value="Secure Client Access" class="input-submit" />
    </fieldset>
  </form>
</div>

Upvotes: 5

Related Questions