I have the following problem with my form.
The form looks like:
<form name='add'
method='post'
action='<?php echo htmlentities($_SERVER["PHP_SELF"]) ?><?php echo "?naujiena=".$_GET['pavadinimas']."" ?>' >
<input name='id' type='hidden'>
<input name='skaicius' type='hidden'>
<input name='pavadinimas' type='text'>
<input type='submit' name='prideti' value='prideti'>
</form>
After the form confirmation I see the result in the URL like this:
http://viper.us.lt/php/naujiena/forma.php?naujiena=
It should be like this:
http://viper.us.lt/php/naujiena/forma.php?naujiena=some_value
2 Answers 2
Your approach is wrong. You don't need the <?php echo "?naujiena=".$_GET['pavadinimas']."" ?> on the action attribute.
Just change your method from POST to GET, and after submit (type) button is clicked, you will see the value on the URL, and will be able to get the value as $_GET.
Edited:
Then you need your form like
<form name="add" method="post" id="myForm" action="garissuero.html" onsubmit="changeActionURL()">
<input name="id" type="hidden" />
<input name="skaicius" type="hidden" />
<input name="pavadinimas" id="pavadinimas" type="text" />
<input type="submit" name="prideti" value="prideti" />
</form>
And have a javascript code like:
function changeActionURL() {
var forma = document.getElementById('myForm');
forma.action += "?naujiena=" + document.getElementById('pavadinimas').value;
}
JSFiddle: http://jsfiddle.net/mETwZ/2/
4 Comments
Change the form method from POST to GET like this:
<form name='add' method='GET' action='<?php echo htmlentities($_SERVER["PHP_SELF"]) ?><?php echo "?naujiena=".$_GET['pavadinimas']."" ?>' >
.""at the end either.