0

I have a search box with an image as submit button. Now when I submit the URL looks like this: search.php?name=&s=s&submit.x=26&submit.y=8

Normaly the URL looks like ?name=&s=s, but that is with a button and not with a image.

Who can help me to delete the url after &s=s?

This is my code:

HTML:

echo '<div id="div3">
    <input name="s" value="s" type="hidden">
    <input type="image" name="submit" src="../img/search.png" border="0" alt="Submit">
    </div>';

search

if (isset($_GET['s'])) {
    $string = $_GET['name'];
}

Thanks.

smottt
  • 3,272
  • 11
  • 37
  • 44
D. Ester
  • 35
  • 5

2 Answers2

1

That's what <input type=image> does — it submits the coordinates that were clicked on the image as additional x and y form fields. If you don't want that, don't use that input type! Consider using a <button type=submit> containing an <img> tag instead, or using CSS to style an <input type=submit>.

  • Thats what I understand, but if I use a normal input with CSS style, the button shows the value, and I need the value for the link. Do you know what better is to do then? – D. Ester Jan 09 '16 at 20:23
  • @D.Ester You do have other inputs, don't you? Why not use them? – Mikhail Batcer Jan 09 '16 at 20:33
0

When you have an <input type="image">, you get two additional parameters sent with the request: the x and y coordinates of the place where the image submit button was clicked. In order to not have these parameters added to the URL, you're going to have to get rid of the <input type="image">. If the button must be an image, I would recommend using the CSS property background-image:

input[type=submit] {
    background-image: url(http://lorempixel.com/40/20/);
    border: 0;
    width: 40px;
    height: 20px;
}

And the corresponding HTML:

<input type="submit" value="" name="submit">

Then, simply check if isset($_GET['submit']).

As for how it looks: JSFiddle

Hatchet
  • 5,320
  • 1
  • 30
  • 42