Tcmxc
Tcmxc

Reputation: 491

How do I enter a value in textbox then have that value execute on another page in php

I have a form on my Home.php

 <form action="/local-concert-listings/" method="post">
    <input  id="address" size="5" type="text" placeholder="Zipcode" name="search"/>
    <input type="submit" value="go" name="go"  />
</form> 

I want to submit the form then have it redirect to 'local-concert-listings.php' and have the zipcode value from 'home.php' be the value of the 'local-concert-listings.php' zipcode textbox.

Upvotes: 0

Views: 228

Answers (2)

Mete Kabak
Mete Kabak

Reputation: 332

<form action="/local-concert-listings.php" method="post">
    <input  id="address" size="5" type="text" placeholder="Zipcode" name="search"/>
    <input type="submit" value="go"/>
</form> 

No need name for submit button unless you have more then one submit type.

In your local-concert-listings.php file, you can get your zipcode with

$_POST['search'] // this is your zipcode

Upvotes: 1

Samuel Cook
Samuel Cook

Reputation: 16828

1, Type in information into textbox

2, Click "Go" (your submit button)

3, On this page: /local-concert-listings/ (which is your forms action) retrieve that information using $_POST (your forms method):

if(isset($_POST['search']){
    echo $_POST['search'];
}

Upvotes: 1

Related Questions