This is my current URL .
I've had this new project now for some time and I was wondering if:
cat=gadgets
, and it also remembers the previous selections My code:
<div id="advanced-search">
<form action="<?php bloginfo('url');?>/recipes" method="GET" id="searchF1">
<?php
$searched_term = get_query_var('recipe_search');
if (empty($searched_term)) {
$searched_term = isset($_GET["search"]) ? $_GET["search"] : "";
}
?>
<input id="sfield" type="text" name="search" placeholder="keywords" <?php if (!empty($searched_term)) {echo 'value="'.$searched_term.'"';} ?>>
<select id="img" name="images">
<option value="1" <?php if($_GET["images"]=='1'){ echo 'selected="selected"';} ?>>with pictures</option>
<option value="0" <?php if($_GET["images"]=='0'){ echo 'selected="selected"';} ?>>without pictures</option>
</select>
<div id="time-side">
<!--<small>Published time</small>-->
<input type="text" id="from-side" name="from" placeholder="Start date">
<input type="text" id="to-side" name="to" placeholder="End date">
</div>
<input type="submit" value="Tech">
<input type="submit" value="Gadgets">
</form>
</div>
You can save data over multiple pages in a few different ways.
example.com/index.php?id=12345
You can then get the id
through $_GET
, like this $_GET['id']
session You can save a value in a session, probably your best option for the saving of the previous data. You can save a value like this: $_SESSION["key"] = "value";
then you can acces that value anywhere on your website like this: $_SESSION["key"]
. Very nice and simple.
cookies You can store a cookie just like you can with $_SESSION
but now it's saved on the users computer as long as you want. Please read the manual if you want to use it.
So in your case, you can send your catagory
information through the url. Like this: example.com/file.php?catagory=toyota
. To get that data in your php code you can do it like this: $_GET['catagory']
The storing of the data of your previous section
$_SESSION["previoussection"] = "some value";
You can then later acces it like this: $_SESSION["previoussection"]
and you will get "some value"
Try this:
<?php
session_start();//starting session
$searched_term = isset($_GET["search"]) ? filter_var($_GET["search"],FILTER_SANITIZE_FULL_SPECIAL_CHARS) : "";
if(!empty($search_term)){
$_SESSION = array();//emptying session for putting new data
$_SESSION['previous'] = $search_term;//add the new search term to the session with previous key
}else{
if(!empty($_SESSION['previous'])){//if session is not empty
$search_term = $_SESSION['previous'];//put the old data to the search term variable
}
}
?>
<div id="advanced-search">
<form action="recipes" method="GET" id="searchF1">
<input id="sfield" type="text" name="search" placeholder="keywords" <?php if (!empty($searched_term)) {
echo 'value="'.$searched_term.'"';} ?>>
<input type="radio" name="images" value="1" <?php if(isset($_GET["images"]) && $_GET["images"]=='1'){
echo 'Checked';} ?>>with pictures</option>
<input type="radio" name="images" value="0" <?php if(isset($_GET["images"]) && $_GET["images"]=='0'){
echo 'checked';} ?>>without pictures</option>
</select>
<div id="time-side">
<input type="text" id="from-side" name="from" placeholder="Start date">
<input type="text" id="to-side" name="to" placeholder="End date">
</div>
<input type="submit" name="Tech" value="Tech">
<input type="submit" name="cat" value="Gadgets">
</form>
</div>
You have two button Tech and Gadgets, so in order to send the way you in the url, you need name value pair:
<input type="submit" name="Tech" value="Tech">
<input type="submit" name="cat" value="Gadgets">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.