Post form php to another php

I want to publish the search value from index.php to search.php,

index.php

<form action="search.php?val=" method="post">

and search.php

<?php echo $_GET['val']?>

or

<?php echo $_POST['val']?>

I would like to save the value of "val" in the URL, but search.php could not commit the value of "val", which looks like "val =".

+3
source share
3 answers

Create a text field by name valinside the form in the index file, for example:

<form action="search.php" method="post">
  <input type="text" name="val" value="search string" />
  <!-- more form stuff -->
</form>

And now you can get it as:

<?php echo $_POST['val']?>

If you need this value in the URL, you must change the form method to get, for example:

<form action="search.php" method="get">
  <input type="text" name="val" value="search string" />
  <!-- more form stuff -->
</form>

and then you can get its value on the search page, for example:

<?php echo $_GET['val']?>

action form, val:

<form action="search.php?val=<?php echo $search_string;?>" method="get">
  <!-- more form stuff -->
</form>

, :

<?php echo $_GET['val']?>
+1

, , URL . , URL-, ?variable=value. URL- $_GET.

,

<form action="search.php?val=" method="post">

,

<form action="search.php" method="get">

action , ?val, PHP , name val.

<form action="search.php" method="get">
<input type="text" name="val"/>
<input type="submit" />
</form>

URL-, ,

http://www.example.com/search.php?val=your_text_here

search.php , $_GET superglobal.

<?php
echo $_GET['val'];
?>
+1

You can use both. If you have <form action = "search.php? Val = ..."> then you can access it in the same way as $ _GET ["val"]. Any other form elements will be displayed in $ _POST [] for your example.

Btw, in cases where the parameter can be represented in different forms, use $ _REQUEST. It captures both GET and POST content.

0
source

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


All Articles