3

I have a search field with name attribute q, and after a click on the submit button I want the form to go to the same page, (which is index.php) so I set the action of the form like this :

'index.php?a=nl&b=search'.

I want that the url that is navigated to is like this (so the action-url + the name of the field):

'index.php?a=nl&b=search&q=search-term'. 

However after a click the page navigates just to

'index.php?q=search-term'

Is there a way to fix this ?

asked Sep 20, 2012 at 12:14
0

6 Answers 6

5

Instead of having a=nl&b=search in the form action, just add two additional hidden inputs to the form:

<input type='hidden' name='a' value='nl' />
<input type='hidden' name='b' value='search' />
answered Sep 20, 2012 at 12:16
Sign up to request clarification or add additional context in comments.

Comments

3

Make the form method as GET and add fields as hidden fields.

looks like your form has only q input field (and a submit button without name attrib). Add the ones you want to append to the url after submit as hidden inputs - ex:

<form method="get" action="yoururl.com?a=nl&b=search">
<input type="hidden" name="a" value="<?php echo isset($_GET['a']) ? $_GET['a'] : ''; ?>"/>
<input type="hidden" name="b" value="<?php echo isset($_GET['b']) ? $_GET['b'] : ''; ?>"/>

..... rest of the form ...

answered Sep 20, 2012 at 12:16

Comments

3

Add a and b has hidden fields in the form with the desired values.

answered Sep 20, 2012 at 12:16

Comments

1

A form like this should do the trick:

<form action="" method="get">
 <input name="q" type="text"/>
 <input name="a" type="hidden" value="nl"/>
 <input name="b" type="hidden" value="search"/>
 <input type="submit" value="Submit"/>
</form>

Since the action goes to the same page, you don't need to specify it.

answered Sep 20, 2012 at 12:18

Comments

1

Use the GET method in <form>, your form should look like:

<form method="get" action="index.php">
 <input type="hidden" value="nl" name="a">
 <input type="hidden" value="search" name="b">
 <input type="text" name="q">
 <input type="submit" value="submit">
</form>
Asciiom
9,9757 gold badges42 silver badges59 bronze badges
answered Sep 20, 2012 at 12:29

Comments

0

So you say your form is as follows:

<form method="POST" action='index.php?a=nl&b=search'>
 <input type="text" name="q">
</form>

In that case, you can access the three variables in PHP as follows:

$_GET['a']
$_GET['b']
$_POST['q']

because the vars in the action are passed as GET and the fields inside the form as POST.

Another convenience way of getting the vars without paying attention if they are GET or POST is just access them through the $_REQUEST array, as follows:

$_REQUEST['a']
$_REQUEST['b']
$_REQUEST['q']
answered Sep 20, 2012 at 12:22

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.