How to pass input value to href - php

I have a form with method post and with a text box and button to submit.
I can easily grab the value with $_POST but I want to be able to pass this value to a link.
textinput = search term
link = index.php?search=search term
If I just concoctenante it into the href I get the value $search isn't set because $search gets set on $_POST.
I know this is possible, wowhead.com is an example, although id rather not use javascript, just css html and php.
Thanks!
Using form method get works but it also passes my button value to the url
<form action="search.php" method="get">
<table style="border:0px">
<tr>
<td style="border:0px">
<input id="search" name="search" autocomplete="off" type="text" maxlength="32" style="width:350px;" />
</td>
<td style="border:0px">
<input name="submit" type="submit" value="Search" style="font-size:16;padding:3px;" />
</td>
</tr>
</table>
</form>
Shows up like this:
http://localhost/search.php?search=searchterm&submit=Search
I want to not have &submit=Search
FIXED by changing
<input name="submit" type="submit" value="Search" style="font-size:16;padding:3px;" />
to (got rid of name tag)
<input type="submit" value="Search" style="font-size:16;padding:3px;" />

use get method
<form action="index.php" method="GET">
<input type="search" name="search" />
<input type="submit" name="submit" />
</form>
OR
<form action="index.php" method="GET">
<input type="search" name="search" />
</form>
and in php you grab the value by $_GET['search']

Related

append php form URL

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>

How to post html outside your domain?

Let's say we are making a form that we want to have on domain1.com and we want to post it to domain2.com. Can this be done?
<form method="post" action="domain2.com/receivepost.php">
<input type="text" name"text" />
<input type="submit value="submit" />
</form>
domain2.com/receivepost.php
<?php print_r($_POST); ?>
You need to specify the full URL (including protocol) in the action attribute of your form tag as follows:
<form method="post" action="http://domain2.com/receivepost.php">
<input type="text" name="text" />
<input type="submit" value="submit" />
</form>
On the PHP side, you can check for POST data as follows:
if (isset($_POST['text'])) {
echo $_POST['text'];
}
Notice that the name attribute of the input tag is text.
You need to specify full URL if you want to send request to specific domain
<form method="post" action="http://domain2.com/receivepost.php">
<input type="text" name"text" />
<input type="submit value="submit" />
</form>
Or you can send to relative (for your domain) path:
<form method="post" action="receivepost.php">
<input type="text" name"text" />
<input type="submit value="submit" />
</form>

why my forms are not working in bootstrap website?

I tried all but no form is working with method or simple action like http://google.com `
<form action="http://google.com" method="post">
<input type="text" />
<input type="submit" />
</form>
even this is not working
use this
<form role="form" action="http://google.com" method="post">
<input type="text" name="text" />
<input type="submit" name="submit" />
</form>
role attribute for FORM
name attribute for input
In PHP, $_POST always accept name attribute from form elements:-
You need to write
<input type="text" name='name_of_your_field' />
instead of
<input type="text" />
You need to refer this Link.

form action, send data from the current form in the URL

for the life of me cant remember how i should be doing this / if its possible.
I am creating a form that takes the user to another page but want to pass the value of the text box in the url.
so e.g:
<form action="newadvert.php?vrm=" class="newadvertform" method="post">
<input type="text" name="carvrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
How can i send the user to newadvert.php?vrm= THE ENTERED TEXT HERE
I need this to then get value on the next page.
Use GET method
<form action="newadvert.php" class="newadvertform" method="GET">
And rename carvrm to vrm
<input type="text" name="vrm" class="carvrm"/>
Use the GET method and rename carvrm to vrm.
<form action="newadvert.php" class="newadvertform" method="GET">
<input type="text" name="vrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
When submitting the form, it'll go as http:///newadvert.php?vrm=
<form action="newadvert.php" class="newadvertform" method="get">
<input type="text" name="vrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
change your form method from post to get
Like this:
<form action="newadvert.php" class="newadvertform" method="get">
<input type="text" name="carvrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
you can get input value by :
$_REQUEST['carvrm']
or change input name to vrm :
<form action="newadvert.php" class="newadvertform" method="get">
<input type="text" name="vrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
now you can get input value by :
$_REQUEST['vrm']
doc: http://www.w3schools.com/PHP/php_forms.asp

PHP Send query string with button

I have a form for searching products which will be visible in each page. When the search button is clicked it will redirect to a search.php page. I want to send a query string (parameter) with the content of the search text box when the button is clicked. The code for the form is simple, but here it is:
<form method="post" action="search.php">
<input type="text" id="txtSearch" name="txtSearch" class="searchInput" value="" />
<input type="submit" id="btnSubmit" name="btnSubmit" value="Search" ?>'" />
</form>
I want that when clicked this will redirect to search.php?q=txtSearch. Thanks.
Change "POST" to "GET" on the form element and change the input name parameter to "q".
use :
<form method="get" action="search.php">
<input type="text" id="txtSearch" name="q" class="searchInput" value="" />
<input type="submit" id="btnSubmit" name="btnSubmit" value="Search" />
</form>
<form method="post" action="search.php?q=txtSearch">
<input type="text" id="txtSearch" name="txtSearch" class="searchInput" value="" />
<input type="submit" id="btnSubmit" name="btnSubmit" value="Search" />
</form>
This way submitting the form you'll be redirect to search.php?q=txtSearch and from php you can get the $_POST variable so
$_POST['txtSearch']
$_POST['btnSubmit']
Just use GET instead of POST
<form method="get" action="search.php">
The name of the fields will be the name of the querystring variable. Like this:
?input_name=input_value

Categories