5 Replies Latest reply: Jul 16, 2012 2:14 PM by Nancy O. RSS

    Shouldn't this line of code work?

    Prodigy9 Community Member

      Hi All...

       

      I'm just trying to spruce up a HTML/PHP Form and change the look of the buttons...  I'm almost certain you can add a different button using tge "src" element in the following line of the form code...

       

      <input name="submit" type="submit" src="images/subbtn.gif" value="submit">

       

      But all I get are the standard buttons.                        

        • 1. Re: Shouldn't this line of code work?
          Ben Pleysier MVP
          <input type="image" src="images/subbtn.gif" value="" onclick="this.form.submit();">

          Gramps

          • 2. Re: Shouldn't this line of code work?
            Prodigy9 Community Member

            Hi Gramps...  That line of code definitely got my images to appear however the "onClick"'s don't work any longer.  One is a submit to a PHP file and the other is a cancel which just sends you back to the index.html.  Like Below (With you're updates included)...

             

             

            <form action="contactlist.php" method="post" name="contactform" >

            <input type="image" src="images/subbtn.gif" value="" onclick="contactform.submit();">

             

            <input name="cancel" type="image" value="" src="images/canbtn.gif"  onClick="window.location='index.html'" />

            </form>

            • 3. Re: Shouldn't this line of code work?
              Ben Pleysier MVP

              Well, I've learnt somthing new. Input type image will only submit the form even without specifying an onclick event procedure.

               

              I don't know what your images look like, but if they look like buttons, you could use the image with the onclick events.

               

              Gramps

              • 4. Re: Shouldn't this line of code work?
                Prodigy9 Community Member

                Well...  Thanks anyway for helping...  I know there is a way to do it (maybe with css) but I could have sworn I've seen done with a simple call to the image/button file I created.

                • 5. Re: Shouldn't this line of code work?
                  Nancy O. MVP

                  There are inherent problems with HTML image buttons -- especially with PHP forms.

                   

                  Safest methods: 

                  • use plain form submit buttons, 
                  • CSS styled submit buttons,
                  • put your images in the CSS background as shown below.

                   

                  /**normal state**/

                  form input[type=submit] {

                  background : url("submit.png") no-repeat center center;

                  width : 115px;

                  height :52px;

                  border : none;

                  color : transparent;

                  font-size : 0 /**for older IE**/

                  }

                   

                  /**on mouse over**/

                  form input[type=submit]:hover {

                  background : url("submit-hover.png") no-repeat center center;

                  }

                   

                   

                   

                  Nancy O.