Content of an input to HREF

Asked

Viewed 31 times

0

How do I get the person redirected to a URL + what they type?

Example

The person types potato in the input below

<input type="text" name="search" id="search">

And when you hit enter is redirected to

www.google.com/search? q=potato

  • 1

    can be javascript or has to be php?

  • 1

    Easy way just use a form with method=get.

1 answer

1


I don’t know if you really need to use PHP to do what you want! If it’s just a field! You can use a form with method="get"

But if you don’t want to do it that way, just capture the input value, add the value to a variable and insert it into a URL, and redirect it with the PHP header

<?php header("Location: http://www.site_a_ser_redirecionado.com/search=".$variavel.""); ?>
  • Ivan, you can use in place of <code> and </code> (or mark code snippet and press control k).

  • @Bacco what the difference ?

  • 1

    @Magichat in the output has practically no, but it is more legible for those who touch the source of the post, and it is the official way to format. In fact, I don’t understand why the network allows HTML if it already has Markdown. Here’s a good summary: Help from the Markdown

  • I agree, with the best maintenance, and that’s what I thought... some of us could have moderated that by now. Now the question is, why, is this allowed or what the possible advantage of not blocking.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.