Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Cant get image to work as submit button

    ive been pulling my hair out trying to get this simple script to work by using an image instead of the standard submit button, nothing i do will fix this!! when i hit submit on the image all it does it re-load the page. But when i use a standard submit button it works fine:

    my code as follows (file named step2.php)

    Initiation code helps direct you to the correct page depending on what you choose (i have blanked URL with ##)

    Code:
    <?php
    if($_POST['submit'])
    {
    $colour = $_POST['col'];
    if($colour == "unlimited")
       {
        if($_POST['bonus'] == "1")
    	{
    		$url = "#####URL#####";
    	}
        else
    	{
    		$url = "#####URL#####";
    	}
       }
    if($colour == "2year")
       {
        if($_POST['bonus'] == "1")
    	{
    		$url = "#####URL#####";
    	}
        else
    	{
    		$url = "#####URL#####";
    	}
       }
    if($colour == "1year")
       {
        if($_POST['bonus'] == "1")
    	{
    		$url = "#####URL#####";
    	}
        else
    	{
    		$url = "#####URL#####";
    	}
       }
    //echo $url;
    header("Location: $url");
    }
    ?>
    form code here:
    Code:
    <form name="formColor" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    
    <input type="radio" name="col" value="unlimited" checked/>choice1</td><td>
    <a href="#" ONMOUSEOVER="popup(choice1','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
    </td></tr><tr><td align="left">
    <input type="radio" name="col" value="2year" />choice 2</td><td>
    <a href="#" ONMOUSEOVER="popup(choice2','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
    </td></tr><tr><td align="left">
    <input type="radio" name="col" value="1year" />choice3</td><td>
    <a href="#" ONMOUSEOVER="popup('choice3','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
    </td></tr><tr><td align="left">
    <input name="bonus" type="checkbox" id="bonus" value="1" checked><font size="2" color="999999"> *give me bonus!</font>
    </td></tr></table>
    <input type="submit" name="submit" value="Proceed to Next Step" />
    </form>
    above works.

    so if i replace the input line to try and get it to load with an image instead of a submit button i was using:

    Code:
    <input type="image" name="submit" src="images/justordernow.jpg" border="0" />

    and all this does is reload the same page over and over.

    can someone help me please!!!!!

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    when you use <input type="image" name="foo" src="..." />, two callback variables are passed to the server, namely "foo_x" and "foo_y" - these contain the coordinates on the image of the mouse cursor when the click occurred - this is because <input type="image" ... /> actually creates an image map rather than a simple button. You could get round this by having a hidden variable in your form (with a known name and value) - that way you can change between <input type="submit" ... /> and type="image" without needing to modify your callback code.

  • #3
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    PHP Code:
    <input type="hidden" name="submitted" value="TRUE" /> 
    Then:

    PHP Code:
    if(isset($_POST['submitted']))

    or

    if(
    $_POST['submitted'] == 'TRUE'){ 
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #4
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    or

    use hyperlink on the image

    <a href =mmmm> ......image... </a>

  • #5
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    ive been pulling my hair out
    By the way , how many hairs you have pulled

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    When you use an image to submit it passes an array of two values (the X and Y coordinates of the mouse when it clicked the image) rather than a single value. Also if the submit is triggered from the keyboard both mouse coordinates will be zero (ie false).

    ahallicks suggestion of a hidden field is the easiest fix.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    New Coder
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok so how do i add that into the webpage - sorry im pretty stupid and need my hand held!!!!!!!!!!!!!!!!!!!!

  • #8
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Do it like this:

    Update:
    Code:
    <form name="formColor" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    
    <input type="radio" name="col" value="unlimited" checked/>choice1</td><td>
    <a href="#" ONMOUSEOVER="popup(choice1','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
    </td></tr><tr><td align="left">
    <input type="radio" name="col" value="2year" />choice 2</td><td>
    <a href="#" ONMOUSEOVER="popup(choice2','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
    </td></tr><tr><td align="left">
    <input type="radio" name="col" value="1year" />choice3</td><td>
    <a href="#" ONMOUSEOVER="popup('choice3','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
    </td></tr><tr><td align="left">
    <input name="bonus" type="checkbox" id="bonus" value="1" checked><font size="2" color="999999"> *give me bonus!</font>
    </td></tr></table>
    
    <!-- Here's the first change to your code -->
      <input type="image" name="submit" src="images/justordernow.jpg" border="0" />
      <input type="hidden" name="submitted" value="TRUE" />
    <!-- --- -->
    
    </form>
    Callback:
    PHP Code:
    if (isset($_POST['submitted']))  //Here's the second change.
    {
    $colour $_POST['col'];
    if(
    $colour == "unlimited")
       {
        if(
    $_POST['bonus'] == "1")
        {
            
    $url "#####URL#####";
        }
        else
        {
            
    $url "#####URL#####";
        }
       }
    if(
    $colour == "2year")
       {
        if(
    $_POST['bonus'] == "1")
        {
            
    $url "#####URL#####";
        }
        else
        {
            
    $url "#####URL#####";
        }
       }
    if(
    $colour == "1year")
       {
        if(
    $_POST['bonus'] == "1")
        {
            
    $url "#####URL#####";
        }
        else
        {
            
    $url "#####URL#####";
        }
       }
    //echo $url;
    header("Location: $url");

    Last edited by mlse; 01-22-2008 at 10:26 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •