Search code examples
phphtmlbuttonsearchanchor

is it possible to send user entered keyword through anchor tag in php


i have a searchbox in my website like below:

<div style="" class="col-sm-8">
  <div class="wrapda">
    <div class="searchda">
      <a href="https://google.com">
        <input type="text" class="searchTermda" placeholder="Search Image">
        <button type="submit" class="searchButtonda">
            <i class="fa fa-search">Search</i>
         </button>
      </a>
    </div>
  </div>
</div>

am trying to pass the user entered keyword in the input box to next page , is there anyway to do this using anchor tags, please help. thanks in advance


Solution

  • Instead of using anchor tag, the more standard way is to use form.

    <div style="" class="col-sm-8">
      <div class="wrapda">
        <div class="searchda">
          <form method="POST" action="your target url">
            <input type="text" name="searchInput" class="searchTermda" placeholder="Search Image">
            <button type="submit" class="searchButtonda">
                <i class="fa fa-search">Search</i>
             </button>
          </form>
        </div>
      </div>
    </div>
    

    You have to specify the action attribute in the form tag which will be your target url.
    You also have to specify the name attribute in the input tag.
    This way your input will be sent to your target url.