NameSilo

[Resolved] Querystring question

Spaceship Spaceship
Watch

kwan

Established Member
Impact
19
querystring question

I'm trying to use a simple html form, but after submitting the existing variables are replaced.

So if I submit a form on a page like index.php?page=1 with a form
<form><input name="chapter">1</input></form>

it sends me to index.php?chapter=1 while I need index.php?page=1&chapter=1.

I know I could put the page variable in the form, but there should be an easier way (I gave 1 variable as an example, but there could be more).
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
what is the actual code for the form you are using. Ensure you have set the action as index.php?page=1.

Alternatively you could set the page number as a hidden field.
 
0
•••
This is the code

Code:
<form method="get" action="index.php?page=1">
  <select name="chapter" onchange="this.form.submit();">
    <option value="1">1</option>
    <option value="2">2</option>
  </select>
</form>
I tried using both post and get. And you're right about the hidden field, but like I said there could be more than one parameter and it seems more obvious to keep them in the url than create a field for each one.

Normally I would use a session to store the page value, but I want it in the URL for SEO reasons.

peter@flexiwebhost said:
what is the actual code for the form you are using. Ensure you have set the action as index.php?page=1.

Alternatively you could set the page number as a hidden field.
 
0
•••
Try stopping the javascript and see if it works. There is nothing wrong with the way you are doing it so it may be the javascript stripping the variable from the action address.
 
1
•••
That didn't help either. It's probably being stripped by the browser to prevent XSS or something. I added them in hidden fields like you said and that works.

Thanks anyways for the suggestions.


peter@flexiwebhost said:
Try stopping the javascript and see if it works. There is nothing wrong with the way you are doing it so it may be the javascript stripping the variable from the action address.
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back