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 10 of 10
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Lightbulb 3 pictures in a form on a HTML page, won't send to a PHP page

    I have 3 pictures that are on a form on a HTML page, and I use the post so when I post it will goto a php page...but my problem is that when I do ask it to post it does not transfere it to a php page, or not that I know of...is there a way that I c an do this...or that I can set the name of the buttons on the HTML page, to a variable on the PHP page, if I can then I can use functions and do what I want to on the page, and not have to make 3 pages..I have also been asked not to use any javascript.
    Last edited by briintex1; 12-23-2003 at 06:31 AM.
    thanks
    bri

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    While I'm sure there's a much prettier way of doing things, I usually use a combination of javascript and php for this...how?

    Code:
    <script language="JavaScript">
    <!--
       function whichButton(theButton) {
             document.formname.buttonSet.value = theButton
             document..formname.submit()
       }
    //-->
    </script>

    Then in your form, make a
    Code:
    <input type="hidden" name="buttonSet">
    in the buttons,
    Code:
    <input type="button" value="Option A"onclick="whichButton(this.value)">
    That could be wrong, and I'm sure it isn't cross-browser compatible.

    Then in your php file,
    PHP Code:
    ...
    switch (
    $_POST["buttonSet"]) {
        case 
    "Option A" :
                .....
                break;
        default :
    ...

    That's a really rough idea of one consideration.

  • #3
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Another possible solution:

    1. Ignore the javascript entirely.
    2. Do the following:

    Code:
    <input type="image" name="image1" value="1" src="yourimage.jpg">
    <input type="image" name="image2" value="1" src="yourimage2.jpg">
    <input type="image" name="image3" value="1" src="yourimage3.jpg">
    Then in your php code, just check for variable existence!

    PHP Code:
    while ($found != TRUE) {
      if (!isset(
    $_POST["image1_x"])) {
          
    $found false;
      } else { 
           
    $found TRUE;
           
    $submitted "image1";
      }
      if (!isset(
    $_POST["image2_x"])) {
          
    $found false;
      } else { 
           
    $found TRUE;
           
    $submitted "image2";
      }
      if (!isset(
    $_POST["image3_x"])) {
          
    $found false;
      } else { 
           
    $found TRUE;
           
    $submitted "image3";
      }




    Because the variable names aren't passed, we get what we can...the variablename followed by an underscore and "X" or "Y" for the coordinates.

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    give the three the same name (for instance image) in your form, but a different value (1, 2, 3).

    then,inside the php,you get the clicked image with
    PHP Code:
    $selected $_POST['image'

  • #5
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    now with an error and with the code

    this is on the index.html page

    <input type="image" name="test" value="1" src="Something.jpg" alt="Something">
    <input type="image" name="test" value="2" src="This.jpg" alt="test"></td>
    <input type="image" name="test" value="3" src="That.jpg" alt="That"></td>

    this is on the pictures and names on the php page

    <?php
    $selected = $_GET['name']
    ?>


    <?php
    echo($selected);
    ?>
    I did what you said, but now I get an error, and it says Undefined index: image in Folder on line 3
    Last edited by briintex1; 12-23-2003 at 05:12 PM.
    thanks
    bri

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A few question:

    -why do you search for the variable in the qurystring collection, while you specify in your first post that you use the post-method?
    - what are you trying to do? do you want to use the images as submitbuttons (so you can also post the values from other formfields)? Or do you just want to create a link on the images?

  • #7
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    hmmm

    Well, I think what I messed up was the question, maybe?

    First I have a form that is on a html page, with three pictures on it, that are called different names. Well with a click on an image, it sends the name of the image to a php page. On the php page I want it to call a function that I have written for the certain images -(that way I do not have to have 3 PHP pages)- that was pushed on the html page. That is the reason that I was wondering if there was a way to do it. The only way I figured it could be done was with a form and a post, so it would send the name of the image to the php page, and display what I wanted it to in the function because I would call the function with PHP. I am not sure if that is the answer that you are looking for, but that is where my problem does lie, on how to call the name of the image from a HTML page, and send it to the PHP page, and call the function in the PHP page. If there was a way to set the name of the image to a variable on the PHP page, then I could end up doing it?
    thanks
    bri

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If i understand it correctly (i'm not the smartest one arround ) then you just wan't to know which image was clicked. Right ?

    Now, you don't need a form for this. You can just lay a link on the image, that points to your php pahe (lets say page.php). Then you add a variable-value pair to the querystring. Like:
    Code:
    <a href="page.php?picture=1" title="Get the pictureaction by clicking on it!"><input type="image" src="Something.jpg" alt="Something" /></a>
    <a href="page.php?picture=2" title="Get the pictureaction by clicking on it!"><input type="image" src="Something2.jpg" alt="Something2" /></a>
    <a href="page.php?picture=3" title="Get the pictureaction by clicking on it!"><input type="image" src="Something3.jpg" alt="Something3" /></a>
    and then, inside page.php:
    <?php
    $selected = $_GET['picture']
    ?>

    You see ?
    You only need the formconstruction if you want to also get formfiel-values to page.php, but this will probably envolve a submit with an onclick javascript event.

  • #9
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I am not the brightest light buld in a box of burnt out ones

    That did it, I had to play with just a little bit to get the link to work but that did what I wanted to do...now I am workin' with functions haha...just like C++ I think..thank you for your help I do appreciate it, thanks again
    thanks
    bri

  • #10
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you're welcome. Glad you got it running


  •  

    Posting Permissions

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