2

I'm sorry for mi bad english, but I need to display an image in a button, then send hidden values in form post.

Mi code:

echo "<form method='post' action='index.php'>";
echo '<input id="prueba" type="submit" value="Submit">​​​​';
echo "<input type='hidden' name='opt' value='3'>";
echo "<input type='hidden' name='sede' value='".$sede."'>";
echo '</form>';

In my CSS:

#prueba{
    background-image:url(back.png);
    font-size:0;
    width:50px;
    height:50px;
}​

Please help me.

7
  • What is wrong with this code? this should change background image of prueba submit button Commented Nov 17, 2014 at 20:19
  • whats the Problem? sending the form? to Display the Image in a button? Commented Nov 17, 2014 at 20:21
  • Try putting quotes for the image url: background-image:url("back.png"); Commented Nov 17, 2014 at 20:22
  • Even if this is not relevant with your question, you might also want to consider using PHP Sessions or cookies for storing and using data through different pages. Commented Nov 17, 2014 at 20:25
  • My problem is: the image is not display in the button and appear these characters "​​​​". But the subtmit button is working fine. Commented Nov 17, 2014 at 20:51

2 Answers 2

1

How about simply displaying an image and use javascript to click the submit button?

Example 1: using "document.form.submit()'

echo "<form id='myform1' method='post' action='index.php'>";
echo '<a href="javascript:void(0);" ';
echo   ' onclick="document.getElementById(\'myform1\').submit();">';
echo  '<img src="back.png" width="50" height="50" />';
echo '</a>';
echo "<input type='hidden' name='opt' value='3' />";
echo "<input type='hidden' name='sede' value='".$sede."' />";
echo '</form>';

or, Example 2: use a hidden submit button (need jQuery)

echo "<form method='post' action='index.php'>";
echo '<a href="javascript:void(0);" onclick="$(\'#prueba\').trigger(\'click\');">';
echo  '<img src="back.png" width="50" height="50" />';
echo '</a>';
echo '<input id="prueba" type="submit" value="Submit" style="display:none" />​​​​';
echo "<input type='hidden' name='opt' value='3' />";
echo "<input type='hidden' name='sede' value='".$sede."' />";
echo '</form>';

or, Example 3: use CSS to display the image

echo "<form id='myform1' method='post' action='index.php'>";
echo '<a id="prueba" href="javascript:void(0);" ';
echo   ' onclick="document.getElementById(\'myform1\').submit();" />';
echo "<input type='hidden' name='opt' value='3' />";
echo "<input type='hidden' name='sede' value='".$sede."' />";
echo '</form>';
Sign up to request clarification or add additional context in comments.

Comments

0

instead of input type= submit use

  <input type="image" src="back.png" alt="Submit">

2 Comments

But this won't automatically submit the form. Nothing will happen on click. But you can add some jQuery there ;)
errr ,yes it will, according to the w3 here and w3schools, I quote type=image Defines an image as the submit button here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.