Home > Software design >  Form with Text and Submit give wrong output value
Form with Text and Submit give wrong output value

Time:05-02

I have a little problem with my HTML Form and can't resolve it.

I have the following form:

<div >
   <form action="" method="get">
   <input type="text" name="search" placeholder="Search">
   <input type="submit" value="Search">
</div>

It works without any problem, but it appends to the URL another value that is not present. To give an example, the correct URL will be "SITE_URL/?search=VALUE" but from nowhere it become "SITE_URL/?search=VALUE&cat=-1" with &cat=-1 that I don't know how to remove.

I've got around the problem temporarily with a redirect removing the wrong part, but it's not so elegant nor optimized. I hope someone could help, thanks!

P.S. My bad, </form> was in the wrong position, all okay now...

CodePudding user response:

You forgot to close the form tag. That's why it shows some other input's value too because you must have that somewhere else in the code and the form takes that to be the part of it too. So use this, it will work -

<div >
  <form action="" method="get">
    <input type="text" name="search" placeholder="Search">
    <input type="submit" value="Search">
  </form>
</div>

  • Related