2

i am writing html form code with in php script

here it is

<?php
 $problem_code="STR";
 echo '<form name="submit-button" action="/codejudge/submit.php?id='.$problem_code.'">';
 echo '<button type="submit" >Submit</button>';
 echo "</form>";
?>

But after submitting url look like this localhost/codejudge/submit.php ? but it should be like this localhost/codejudge/submit.php?id=STR

Barb C. Goldstein
4541 gold badge3 silver badges13 bronze badges
asked Jan 19, 2014 at 19:01
2
  • 1
    What if you set GET as action of form? <form method="get" name="submit-button" etc. Commented Jan 19, 2014 at 19:06
  • @AycanYaşıt — He has, that's the default. Commented Jan 19, 2014 at 19:06

2 Answers 2

4

If a form is method="GET" (which is the default), as this one is, then submitting it will erase the existing query string in the action.

Store the data in a hidden input instead.

<?php
 $problem_code="STR";
?>
<form name="submit-button" action="/codejudge/submit.php">
 <input type="hidden" name="id" value="<?php echo htmlspecialchars($problem_code); ?>">
 <button type="submit">Submit</button>
</form>
answered Jan 19, 2014 at 19:05
Sign up to request clarification or add additional context in comments.

1 Comment

This is the correct answer. You should put query variables inside hidden inputs, that's why they exist.
1

You should specify a method of form submit.

$problem_code="STR";
echo '<form method=post name="submit-button" action="/codejudge/submit.php?id='.$problem_code.'">';
echo '<button type="submit" >Submit</button>';
echo "</form>";
answered Jan 19, 2014 at 19:04

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.