0

I am creating a button in php and want to call a php with parameter when clicked:

echo '<form method="get" action="./ash.php?q=Y"    >';
echo '<button type="submit"    >QUERY</button>';
echo '</form>';

When I click on the button, ash.php gets indeed called, but the q parameter has been 'forgotten' in the process. How can that be?

5
  • Why don't you put a hidden field with the name q and the value of Y Commented Apr 8, 2014 at 15:22
  • because ash.php may be called with or without parameter Commented Apr 8, 2014 at 15:24
  • 1
    That's actually a feature, not a bug, you're not supposed to form an action attribute that way. Commented Apr 8, 2014 at 15:25
  • so, test your parameters into ash.php : $q = (isset($_GET['q')) ?: ''; Commented Apr 8, 2014 at 15:26
  • possible duplicate of submitting a GET form with query string params and hidden params disappear Commented Apr 8, 2014 at 15:26

1 Answer 1

3
echo '<form method="get" action="./ash.php"    >';
echo '<input type="hidden" name="q" value="Y" />';
echo '<button type="submit"    >QUERY</button>';
echo '</form>';
Sign up to request clarification or add additional context in comments.

Comments

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.