Vince P
Vince P

Reputation: 1791

Go to URL with value from input box

I'm trying to build a search query in PHP and having some trouble.

I need to have an input box which will result in the value of XXXX.

Upon pressing the search button I need the browser to redirect to the URL catalogsearch/advanced/result/?name=XXXX

I know this is probably very simple question but if anyone can help that would be great.

Upvotes: 0

Views: 1888

Answers (5)

cwallenpoole
cwallenpoole

Reputation: 82028

Um...

All you really need is in the generic forms tutorials.

You are specifically looking for a form with a method of 'GET' and the $_GET variable in PHP

Upvotes: 0

Florian
Florian

Reputation: 3171

You can make the form using GET but if you want to have control over the process and maybe want to log, do it like this:

header("Location: http://example.com/catalogsearch/advanced/result/?name=XXXX");
die();

Upvotes: 0

Brad Christie
Brad Christie

Reputation: 101604

<form action="catalogsearch/advanced/result" method="GET">
  <input type="text" name="name" />
  <input type="submit" value="Search" />
</form>

Use a simple form?

This will automatically append the "?name=<value_from_input>" on to the URL and move along to the desired page.

On the server-side, and assuming this is either a url rewrite or a destination page, you'll be able to access the variable using:

<?php
  // other code
  $search_value = $_GET['name'];
  // other code

Upvotes: 4

Steve Nguyen
Steve Nguyen

Reputation: 5974

Just define method="get"

<form method="get">
    <input type="text" id="name" name="name">
    <input type="submit" value="Submit" />
</form>

Upvotes: 0

Brad
Brad

Reputation: 163242

All you have to do is set your form method to get.

<form action="yourscript.php" method="get">
    <input type="text" name="name" value="woot" />
    <input type="submit" name="submit" value="Search" />
</form>

Upvotes: 0

Related Questions