3

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'];
?>
1
  • 1
    Why have you put your submit button inside another form? When you submit it from that form, you lose data set in other forms. Commented Jun 13, 2011 at 14:22

2 Answers 2

5

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Michael...I tried it it still didn't work. Am I making an error elsewhere ?
@Vinoth You are certain PHP is functioning properly otherwise? Do you get anything if you print_r($_GET); to dump the contents of the GET vars?
4
<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.

2 Comments

Tom did as you said. It works thanks...human error is always redundant :)
My guess would be that @Michael's solution didn't work because of the lost target attribute on <form/> element. Altho', not 100% sure. It could be possible that when passing elements through $_GET not $_POST, data is lost when posted outside PHP_SELF - blank window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.