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
chandan111
2512 gold badges6 silver badges16 bronze badges
2 Answers 2
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
Quentin
949k137 gold badges1.3k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Christian
This is the correct answer. You should put query variables inside hidden inputs, that's why they exist.
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>";
Comments
default
GETas action of form?<form method="get" name="submit-button"etc.