Message of a PHP form method with an action URL

Hello, I have the following problem with my form.

The form looks like this:

<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 validating the form, I see the result in the following URL:

 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 

Thanks for the help.

+4
source share
2 answers

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']."" ?>' > 
+3
source

Your approach is wrong. You do not need <?php echo "?naujiena=".$_GET['pavadinimas']."" ?> On the action attribute .

Just change the method from POST to GET , and after clicking submit (type) button you will see the value in the URL and you can get the value of $_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 use javascript code:

 function changeActionURL() { var forma = document.getElementById('myForm'); forma.action += "?naujiena=" + document.getElementById('pavadinimas').value; } 

JSFiddle: http://jsfiddle.net/mETwZ/2/

+3
source