0

Site1: http://www.sitea.com

Site2: http://www.siteb.com

I would like to use the input field value from Site1 to build an url within a <a href=""> element that will point to Site2. This will be used to access search functionality of another site.

Example: input value = test-search

URL: http://www.siteb.com/#!q=test-search?parameter1

My attempt look like this:

    <form action="index.php" method="GET">
        <input type="search" name="search" />
    </form>
    <a href="https://www.siteb.com/#!q=<?php echo $_GET['search']; ?>?parameter1">Search</a>

I was looking through different tuttorials but could not find one that will use PHP to pass the value of the input field and build the URL.

Please note: I am limited to PHP only and no JS at all.

AMP example: - link to example

<form method="GET"
  class="p2"
  action="/components/amp-form/submit-form"
  target="_top">
  <div class="ampstart-input inline-block relative mb3">
    <input type="search"
      placeholder="Search..."
      name="googlesearch">
  </div>
  <input type="submit"
    value="OK"
    class="ampstart-btn caps">
</form>
3
  • I'm confused - what is your actual question here? Commented Oct 23, 2017 at 16:35
  • I would like on entering data in input field and pressing submit to go to another page with specific URL that will contain the value entered in the input field as well. Commented Oct 23, 2017 at 16:38
  • How is your attempt differing from your desired output? Using echo and the $_GET[''] variable is a standard way of doing this. Commented Oct 23, 2017 at 16:44

2 Answers 2

1

in your main index.php file you will have this

<form method="GET"
      class="p2"
      action="submit-folder"
      target="_top">
    <div class="ampstart-input inline-block relative mb3">
        <input type="search"
               placeholder="Search..."
               name="googlesearch">
    </div>
    <input type="submit"
           value="OK"
           class="ampstart-btn caps">
</form>

and inside a folder named "submit-folder" with another index.php file inside yo will have this

  <?php
if (isset($_GET["googlesearch"])) {
    header("Location: https://www.siteb.com/#!q=" . $_GET["googlesearch"] . "?parameter1");
}

this is the file that will receive the request then automatically redirect you could have done this in a single file though as

<?php
if (isset($_GET["googlesearch"])) {
    header("Location: https://www.siteb.com/#!q=" . $_GET["googlesearch"] . "?parameter1");
    exit;
}
?>
<form method="GET"
      class="p2"
      action="<?php echo $_SERVER['PHP_SELF']; ?>"
      target="_top">
    <div class="ampstart-input inline-block relative mb3">
        <input type="search"
               placeholder="Search..."
               name="googlesearch">
    </div>
    <input type="submit"
           value="OK"
           class="ampstart-btn caps">
</form>
Sign up to request clarification or add additional context in comments.

2 Comments

did you place the above code in a php file, plus this should automatically redirect you to the second site after clicking search
Yes its working on this side after you hit submit you are automatilly redirected
1

You have to make redirect in you action script:

<?php
if (isset($_GET['search']))
    header("Location: https://www.siteb.com/#!q=".$_GET['search']."?parameter1"); 
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.