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 14 of 14
  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Posts
    169
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Strange issue with image submit not posting to PHP

    I have an issue with a submit in a simple form not posting its value to a PHP page, when that submit is of type "image". It works fine as a type "submit" but it needs to work as an image.

    My form is just this:

    PHP Code:
    <form action="archive_model.php" method="post" name="modelsearch">
    <
    table width="600" class="cardisplay">
    <
    tr>
    <
    td width="200" valign="top"><input type="image" value="DB2" name="submit" src="images/car01.jpg" width="200" height="133" />
    </
    td>
    </
    tr>
    </
    table>
    </
    form
    If I take away the src="... and make it type "submit" it works fine.

    Is it a simple syntax error in the input (which I don't think it is) or something else? I've tried it in FF 3.5 and IE 8 and it doesn't work in either browser.

    Any help appreciated - thanks!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I know there is an article somewhere in the api about this, but I'm afraid I cannot find it.
    What I can tell you with 100% certainty, is that the 'submit' will no longer exist. It will be under $_POST['submit_x'] instead. I don't believe that will apply to anything but the image input type though (so any other fields I believe are still correct).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Sep 2009
    Posts
    169
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Okay... so if it no longer exists (or exists under _POST x) (???) then how can I get it to work?

    On the face of it it seems such a simple task to perform, I'm surprised it should be this involved...

  • #4
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    In these situations, I frequently print the array to see what exactly I'm getting back.
    It usually clears things up significantly.
    Try:
    PHP Code:
    echo '<pre>';
    print_r($_POST)
    echo 
    '</pre>';

    /* or */

    echo '<pre>';
    var_dump($_POST)
    echo 
    '</pre>'
    That may show you what you should be looking for.

    ~ Mo

  • #5
    Regular Coder
    Join Date
    Sep 2009
    Posts
    169
    Thanks
    18
    Thanked 0 Times in 0 Posts
    I echoed right at the top of the PHP file that the form submits to- and got a very strange looking output:

    PHP Code:
    Array
    (
        [
    submit_x] => 110
        
    [submit_y] => 67

    Not sure what this means and what I can do about it. Presumably these are image co-ordinates but how will they help submit the form properly using the image?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That I assume to also be the case, probably the top left and bottom right. Couldn't be certain though, but we don't really care about that.
    I assume that you're current form probably looks something like this:
    PHP Code:
    if (isset($_POST['submit']))
    {
        
    // do stuff

    with the image, you'll need to modify that:
    PHP Code:
    if (isset($_POST['submit_x']))
    {
        
    // do stuff

    If my suspicions are right, if you had a text entry for say 'username', I believe its still just under username. So you can look at switching based on a different field so you can update you're submit buttons to images without damaging the underlying code.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by galahad3 View Post
    ... Presumably these are image co-ordinates ...
    Quote Originally Posted by Fou-Lu View Post
    That I assume to also be the case, probably the top left and bottom right. Couldn't be certain though, ...
    I realize this is besides the point, but I'm pretty sure that those are simply the single-point X,Y coordinates of the actual click, rather than the top-left & bottom-right coord's of the image.


    ~ Mo
    Last edited by mOrloff; 02-17-2010 at 10:35 PM.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by mOrloff View Post
    I realize this is besides the point, but I'm pretty sure that those are simply the single-point X,Y coordinates of the actual click, rather than the top-left & bottom-right coord's of the image.


    ~ Mo
    That could be the case too, though I'm not sure if the browser would indicate a click point. I can test that when I get home, but I can't do that at work I'm afraid.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #9
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Yeah, if you test it, please post your findings. (I can't test right now either)
    I thought I remembered reading something about that a fair while back on 3wschools, but after a preliminary search, I'm not seeing it now.

  • #10
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    To Galahad: I'm not sure how fresh this all is to you or not, so I'm going to lay down some advice just in case.

    I see that you're putting your form in a table.
    If your primary reason for using a table is layout, please look into CSS.

    If you are learning HTML right now, may as well learn the right way to do it.
    Even if you're already comfortable with tables, css is not very difficult to step into (and even when hand-coding, some IDE's provide enough suggestions to almost do the work for you).

    Tables (when used for non-tabular data) make everyones lives more difficult, even yours.
    Any time that you save up-front will doubtlessly get spent some time down the road when (not if ) you revisit your code, and the user has less influence on their own experience.
    Inferior user experience translates into inferior traffic.

    ~ Mo
    Last edited by mOrloff; 02-17-2010 at 11:42 PM.

  • #11
    Regular Coder
    Join Date
    Sep 2009
    Posts
    169
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Think I might have got somewhere, by changing the head of the PHP page:

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

    include (
    'inc/dbconnect.php');
      
    // Get the search variable from form that was sent
      
    $modelref =@$_POST['submit'];
      echo 
    $modelref
    etc.

    So basically testing for submission of the submit input rather than the form.

    I'll need to create a form now for each value e.g DB3, DB4 etc. but if this one works then so should they...
    Last edited by galahad3; 02-18-2010 at 01:45 PM.

  • #12
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    I can confirm that an image will not submit the value, the solution I would suggest is to rename the buttons to include the value so in your example you would rename to "submit_db2" or similar, then either:

    - loop through the $_POST array checking anything that starts with 'submit_' and splitting off the end to get the value

    or

    - have a hidden field that contains a list of the possible values and loop through that looking for a suitably named $_POST variable

    or

    - reuse whatever query you originally used to decide what values to check for.


    The first option is probably simplest provided you ensure you never name another field with the prefix 'submit_'

    Another possible gotcha is invalid field names, but then that would be solved if you used a unique id number rather than a model name which is better practice anyway.

    HTH

    Dai

  • #13
    Regular Coder
    Join Date
    Sep 2009
    Posts
    169
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Thanks, also as I suspected setting up different forms for each submit seems to work fine:

    PHP Code:
    <table width="600" class="cardisplay">
    <
    tr>
    <
    td width="200" valign="top">
    <
    form action="archive_model.php" method="post" name="modelsearch">
    <
    input type="hidden" value="DB2" name="submit" />
    <
    input type="image" src="images/archivegallery/db2.jpg" width="200" height="133" />
    </
    form>
    </
    td>
    <
    td width="200" valign="top">
    <
    form action="archive_model.php" method="post" name="modelsearch">
    <
    input type="hidden" value="DB4" name="submit" />
    <
    input type="image" src="images/archivegallery/db4.jpg" width="200" height="133" />
    </
    form>
    </
    td>
    </
    tr>
    </
    table
    Now to create all the others and that should hopefully be that. Thanks.

  • #14
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Yep that should work too.


  •  

    Posting Permissions

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