I want to post a 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 retain 'val' value in the URL, but search.php could not capture the value of 'val' which appear to be "val=".
Create a text field by the name of val inside the form on index file eg:
<form action="search.php" method="post">
<input type="text" name="val" value="search string" />
<!-- more form stuff -->
</form>
And you can now get it like:
<?php echo $_POST['val']?>
If however, you want that value in url you should modify the form's method to get like:
<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 search page like:
<?php echo $_GET['val']?>
Alternatively, you can specify search string directly in the action attribute of the form and in this case you don't need the val field:
<form action="search.php?val=<?php echo $search_string;?>" method="get">
<!-- more form stuff -->
</form>
and then you can get its value on search page like:
<?php echo $_GET['val']?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With