How would I append the search string to the end of the url instead of deleting the current posts
<input class="searchBox" type="text" name="search" placeholder="Search Here">
<input type="submit" value="">
I have this at the moment and it deletes the other Post variables at the end of the url, but what I want it to do is append it to the end
So for example, I have page.php?id=123 .. the user searches and I want it to display page.php?id=123&search=text, but at the moment it replaces it and does page.php?search=text
you can insert a hidden input before the other inputs. Also your form must submit using get to achieve what you are looking for.
<form method="get" action="">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
<input class="searchBox" type="text" name="search" placeholder="Search Here">
<input type="submit" value="Search">
</form>
Add
<input type='hidden' name='id' value='".$_GET['id']."'>;
Into the form
Related
I currently built a simple form to GET request someones zipcode.
<form action="http://example.com" method="get" target="_blank">
<p>ZIPCODE</p>
<input type="text" name="zip">
<input type="submit" value="Submit">
</form>
When submitted it will be http://example.com/?zip=ZIPCODE
What I am looking to do it add an additional piece so it will be http://example.com/?zip=234&country=usa
I tried adding a hidden field <input type="hidden" name="country=usa"></input> but this replaces = with %3D and adds = after it like so: http://example.com/?zip=ZIPCODE&country%3Dusa=
How can I easily append the URL with country=usa?
Try:
<form action="http://example.com" method="get" target="_blank">
<p>ZIPCODE</p>
<input type="text" name="zip">
<input type="hidden" name="country" value="usa">
<input type="submit" value="Submit">
</form>
i have a problem keeping a post element in variables before calling one more time post in a second form .
briefly:
variable below contain elements from previous post
$img=isset($_POST['image'])?$_POST['image']:false;
$table=isset($_POST['tabl'])?$_POST['tabl']:false;
Then i have as next to the lines above the form below :
<form method="post" action="" style="padding-top:200px;padding-bottom:200px;padding-left:500px">
<div><span>Email</span></div> <input type="text" value="" name="user"/><br><br>
<div><span>Password</span></div> <input type="password" value="" name="pass"/><br><br>
<input type="submit" value="send" name="submit"/>
</form>
and right after pressing submit $img and $table are both empty .
how can i keep the values in $imgand $table even after calling post again ?
any clue ?
Thanks
You aren't sending the variables you want in the POST data in your second form.
You could use a hidden field to send it,
A bit like this.
<form method="post" action="" style="padding-top:200px;padding-bottom:200px;padding-left:500px">
<input type="hidden" name="img" value="<?php echo $img;?>" />
<input type="hidden" name="table" value="<?php echo $table;?>" />
<div><span>Email</span></div> <input type="text" value="" name="user"/><br><br>
<div><span>Password</span></div> <input type="password" value="" name="pass"/><br><br>
<input type="submit" value="send" name="submit"/>
</form>
How do I check the url if it has a parameter or not before passing?
I need to pass the value of s on current page.
When passing on current page 'index.php' it would look like this index.php?s=value
How can i pass the value if the url has parameters like index.php?page=1 or index.php?orderby=asc so when i press the search button it would be something like this index.php?page=1&s=value or index.php?orderby=asc&s=value
<form method="get">
<p class="search-box">
<label class="screen-reader-text" for="user-search-input">Search Members:</label>
<input type="search" id="user-search-input" name="s" value="" size="30" placeholder="Search">
<input type="submit" name="" id="search-submit" class="button" value="Search Members">
</p>
</form>
Use php, you can output the param in the form as a hidden value, e.g. to keep the page param
<form method="get">
<input type="hidden" name="page" value="<?php echo htmlspecialchars(isset($_GET['page'])? $_GET['page']:''); ?>" />
Keep the htmlspecialchars when using $_GET['page'], or you will face XSS attacks.
Here, in action whole url will be placed.
<form method="get" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
You should keep current page as a `action along with query string, so that extra parameters will be added at last.
YOu have to include the page incomming parameters in the "action" attribute of you tag.
<?php
if(isset($_GET['s'])
{
*dostuffwiths
"echo <input type='hidden' name='s' value='$s'>";
}
else
{
echo "<input type='hidden' name='s' value='$s'>";
}
?>
Try this
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="GET">
<p class="search-box">
<label class="screen-reader-text" for="user-search-input">Search Members:</label>
<input type="search" id="user-search-input" name="s" value="" size="30" placeholder="Search">
<input type="submit" name="" id="search-submit" class="button" value="Search Members">
</p>
</form>
I'm trying to create a search box that would have 4 inputs but output as one search. Here is my current code:
<form method="get" id="searchform" action="http://sitename.com/">
<input type="text" name="s" />
<input type="text" name="a" />
<input type="text" name="b" />
<input type="text" name="c" />
<div class="clear_space"></div>
<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />
</form>
But that outputs like this in wordpress: /?s=milk&a=eggs&b=cheese&c=garlic&submit=Search
But I need it to output like this: /?s=milk+egg+cheese+garlic&submit=Search
So somehow those additional inputs need to add their text to the first ?s= with just a +... Any help is massively appreciated.
Are you kidding??
The + that you are seeking is simply a space. Have one text field, and when the form is submitted the spaces in between the words will be converted into +.
Wow, you have a lot of problems, but before we get deep into them let me tell you that your "output" is in fact a get parameter, or a URL. Now you should NEVER use the same id for different tags (!!!). If you think about a valid reason to do that, then think again.
Change your form as follows:
<form method="get" id="searchform" action="http://sitename.com/">
<input type="text" class="field" placeholder="Search" />
<input type="text" class="field" placeholder="Search" />
<input type="text" class="field" placeholder="Search" />
<input type="text" class="field" placeholder="Search" />
<input type="hidden" name="s" id="s" />
<div class="clear_space"></div>
<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />
</form>
and then implement a form submit event to calculate your value and assign to your input field. Cheers.
EDIT:
Use the following js code to run before you submit your form:
//...
var value = "";
$(".field").each(function(){
value += ((value !== "") ? (" ") : ("")) + $(this).val();
});
$("#s").val(value);
//...
I have few fields in a form say
<form action="?code='.$order_id.'" method="post">
<input type="text" name="length" placeholder="'.$row_order['length'].'">
<input type="text" name="breadth" placeholder="'.$row_order['breadth'].'">
<input type="text" name="width" placeholder="'.$row_order['width'].'">
<input type="submit" name="save" value="Save">
</form>
I retrieve the value of length, breadth and width from database and show it through a placeholder. Now I want if the user enters some value say in length then only length field in DB to be affected others being intact.
Now if I put the value of length as 50 and "Save" it then it shows length=50, breadth=0 and width=0 even if I had breadth=40 and width=30 before updating.
Instead of placeholder use value in input tag
<form action="?code='.$order_id.'" method="post">
<input type="text" name="length" value="'.$row_order['length'].'">
<input type="text" name="breadth" value="'.$row_order['breadth'].'">
<input type="text" name="width" value="'.$row_order['width'].'">
<input type="submit" name="save" value="Save"> </form>