Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET form method wont append parameters

Tags:

forms

php

I am working for a school project written in PHP for some weeks and i am stuck.

I am using for my structure a page index.php?page=.... where page could be home , game, aboutus,contact etc.

Now I am in index.php?page=game and I want to send using a form with GET method some parameters like game_name, created_by and stage_paused. Here comes the problem because when I press the Submit button I lose my "page=game" parameter and is something like index.php?game_name=...&created_by=...., and I don't have anymore my page=game, and by default my script check the page parameter and if not it renders the home page.

I checked w3 standards and they say that GET method shoud APPEND my form parameters with the one that is specified in the action ="" on the form, but in my case I lose my page parameter.

I don't get it why it doesn't remember my current parameters when I submit the form.

I would appreciate very much your help and sorry for my bad english.

Thanks !

like image 667
Chris Avatar asked Dec 27 '22 10:12

Chris


1 Answers

Add the page parameter to either:

  1. Your <form> action URL, or
  2. Your <form> as a hidden <input> element, like so:

<input type="hidden" name="page" value="<?= $_GET['page'] ?>" />

like image 183
nickb Avatar answered Jan 10 '23 04:01

nickb