-1
<form action="shorturl" method="POST">
  <div class="search-box">
    <input class="search-txt" type="text" name="" placeholder="https://">
    <a class="search-btn">
      <i class="fa-solid fa-minimize"></i>
    </a>
  </div>
</form>

I made a button in CSS out of the tag, but for some reason, when I click on it, I can't get a post request.

I tried this

<a class="search-btn" action="shorturl" formmethod="POST">

but nothing

and this

<a class="search-btn" href="shorturl" formmethod="POST">

which gives a get request

Kailash Muthu
  • 21
  • 1
  • 3

1 Answers1

0

Since there is no formmethod attribute on the tag, the form must be submitted using <button type="submit">. (If JavaScript is not used)

<form action="shorturl" method="POST">
  <div class="search-box">
    <input class="search-txt" type="text" name="" placeholder="https://">
    <button class="search-btn" type="submit">
      <i class="fa-solid fa-minimize"></i>
    </a>
  </div>
</form>

Or if you use JavaScript:

<form action="shorturl" method="POST" id="searchForm">
  <div class="search-box">
    <input class="search-txt" type="text" name="" placeholder="https://">
    <a class="search-btn" id="searchBtn">
      <i class="fa-solid fa-minimize"></i>
    </a>
  </div>
</form>
document.getElementById("searchBtn").addEventListener("click", () => {
  document.getElementById("searchForm".submit();
});
  
waki285
  • 338
  • 1
  • 11