4

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
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
asked Mar 8, 2013 at 18:51
1
  • Obvious question, are you sure your GET variable contains anything? I don't think you need the ."" at the end either. Commented Mar 8, 2013 at 18:54

2 Answers 2

3

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/

answered Mar 8, 2013 at 18:57
Sign up to request clarification or add additional context in comments.

4 Comments

I need only see naujienos name in action ! Not others
Man, you want me to go to your computer? Did you even check the JSFiddle page I gave you?
Maybe it's possible to do with objects?
Why is JavaScript required for this?
3

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']."" ?>' >
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Mar 8, 2013 at 18:54

2 Comments

It's not working, because the values don't insert in database.
Why should it be changed from POST to GET?

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.