Jump to content

input as image


Adsa

Recommended Posts

I am trying to create a rollover image for a submit button but when i use the input type as image the values I am sending in the form are not getting sent. Is this how the image process works? I want to keep it as simple as possible

 

Any help would be great.

 

echo "<form method=\"post\" action=\"register1.php\" alt=\"Register\"><p><br>";
echo "<b>Name : </b><br><input name=\"full_name\" type=\"text\" id=\"full_name\"></p>";
echo "<p><b>Email : </b><br><input name=\"email\" type=\"text\" id=\"email\"></p>";
echo "<p><b>Password : </b><br><input name=\"pass1\" type=\"password\" id=\"pass1\"></p>";
echo "<p><b>Retype Password : </b><br><input name=\"pass2\" type=\"password\" id=\"pass2\"></p>";
echo "<p><b>Email Opt out? : </b><br><input name=\"opt_out\" type=\"radio\" id=\"opt_out\" value=\"No\" checked>No";
echo "<input name=\"opt_out\" type=\"radio\" id=\"opt_out\" value=\"Yes\">Yes</p>";
echo "<p><b>Code : </b><br><input name=\"user_code\" type=\"text\" size=\"11\"><br>";
echo "<img src=\"key/pngimg.php\" align=\"middle\">  </p>";
echo "<p><input type=\"image\" name=\"submit\" value=\"submit\" src=\"img/buttons/register_1.png\" onmouseover=\"this.src = 'img/buttons/register_0.png'\" onmouseout=\"this.src = 'img/buttons/register_1.png'\"></p></form>";

Link to comment
Share on other sites

If i replace this

 

echo "<p><input type=\"image\" name=\"submit\" value=\"submit\" src=\"img/buttons/register_1.png\" onmouseover=\"this.src = 'img/buttons/register_0.png'\" onmouseout=\"this.src = 'img/buttons/register_1.png'\"></p></form>";

 

With

 

echo "<p><input type=\"submit\" name=\"submit\" value=\"submit\"></p></form>";

 

It works fine. Changing it to submit rather than an image it returns the form values.

 

 

 

Link to comment
Share on other sites

Browsers don't send the value="..." for type="image" (well some of them do, but they are not required to.) The specification only requires that the x,y coordinates where the image was clicked be send to the server.

 

From the php manual HTML/FAQ -

I'm trying to use an <input type="image"> tag, but the $foo.x and $foo.y variables aren't available. $_GET['foo.x'] isn't existing either. Where are they?

 

When submitting a form, it is possible to use an image instead of the standard submit button with a tag like:

 

<input type="image" src="image.gif" name="foo" />

When the user clicks somewhere on the image, the accompanying form will be transmitted to the server with two additional variables: foo.x and foo.y.

 

Because foo.x and foo.y would make invalid variable names in PHP, they are automatically converted to foo_x and foo_y. That is, the periods are replaced with underscores.

 

So your form would set $_POST['submit_x'] and $_POST['submit_y']

Link to comment
Share on other sites

Unfortunately, a <button></button> as a submit button has the following issue (just confirmed for myself) -

 

Important: Be careful when using the button element in a form. In a form the different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will send the content of the value attribute.

 

The solution of course is to use the name_x or name_y from the type="image" or use a hidden field with the name and value that you want.

Link to comment
Share on other sites

Unfortunately, a <button></button> as a submit button has the following issue (just confirmed for myself) -

 

Important: Be careful when using the button element in a form. In a form the different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will send the content of the value attribute.

 

The solution of course is to use the name_x or name_y from the type="image" or use a hidden field with the name and value that you want.

 

Huh? He wants a simple submit button that is styled completely. If the form is valid, there should be no problem. I have used <button> for more than 2 years and never had problems w/ it. This includes safari, FF, opera, and IE6+. You might be getting confused about

 

<button type="submit" name="submit" value="submit">
Submit
</button>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.