GET form method does not add parameters

I have been working on a school project written in PHP for several weeks and I am stuck.

Am I using the index.php page for my structure? page = .... where the page can be home, game, odus, contact, etc.

Now I am in index.php?page=game , and I want to send some parameters using the form with the GET method, such as game_name, created_by and stage_paused. This is where the problem arises because when I click the submit button, I lose my parameter "page=game" and something like index.php?game_name=...&created_by=.... and I no longer have mine pages = games, and by default, my script checks the page parameter and if it does not display the home page.

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

I do not understand why he does not remember my current settings when submitting the form.

I would really appreciate your help and apologize for my poor English.

Thanks!

+4
source share
3 answers

Add a page parameter:

  • Your action url is <form> or
  • Your <form> as a hidden <input> element, for example:

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

+4
source

A simple hidden input element should do the trick:

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

Thus, the page parameter provided through the URL is also considered part of your form and therefore is added to the form URL.

+3
source

You need to add a hidden field for the page:

  <input type="hidden" name="page" value="game" /> 

You can also change the form method to POST and add the page to the action:

 <form action="index.php?page=game" method="POST"> 
+2
source

Source: https://habr.com/ru/post/1382097/


All Articles