SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I want to use images for submit buttons but there are like 6 of them. Each link leads to a section of code inside the same page. Here is the code for the page -
    Code:
    <?
    $connection = mysql_pconnect("localhost","root","") or die("Couldn't connect to DB");
    mysql_select_db("abraham",$connection) or die("Couldn't select DB");
    $select = "SELECT username, password FROM users WHERE username='$username' AND password='$password'";
    $getnum = mysql_query($select,$connection);
    $number = mysql_num_rows($getnum);
    if($number == 1)
    {
    if($action == "info")
    {
    ?>
    <HTML>
    <HEAD>
    <TITLE>Info Form</TITLE>
    </HEAD>
    <BODY>
    <FORM action="infoform.php" method="post">
    <P>
    Last Name: <input type="text" size="30" name="lastname">
    <BR>
    First Name: <input type="text" size="30" name="firstname">
    <BR>
    <input type="submit" value="SUBMIT">
    </FORM>
    </Body>
    </HTML>
    <?}
    elseif($action == "education")
    {?>
    <HTML>
    <HEAD>
    <TITLE>Education Form</TITLE>
    </HEAD>
    <BODY>
    <form action="eduform.php" method="post">
    High School: <input type="text" size="30" name="hschool">
    <P>
    College: <input type="text" size="30" name="college">
    <P>
    <input type="submit" value="SUBMIT">
    </form>
    </body>
    </HTML>
    <?}
    else
    {?>
    <HTML>
    <HEAD>
    <TITLE>Forms</TITLE>
    </HEAD>
    <BODY>
    <H1>Forms</H1>
    <form action="<? $PHP_SELF ?>" method="post">
    <input type="hidden" name="username" value="<? print $username ?>">
    <input type="hidden" name="password" value="<? print $password ?>">
    <?
    $info = "SELECT * FROM info WHERE username='$username'";
    $information = mysql_query($info);
    $infoarray = mysql_fetch_array($information);
    $ssn = $infoarray["ssn"];
    $LastName = $infoarray["LastName"];
    $FirstName = $infoarray["FirstName"];
    $Address1 = $infoarray["address1"];
    $City = $infoarray["city"];
    $State = $infoarray["state"];
    $zip = $infoarray["zip"];
    $hphone = $infoarray["hphone"];
    $eligible = $infoarray["eligible"];
    $felony = $infoarray["felony"];
    
    if((!$ssn) || (!LastName) || (!FirstName) || (!Address1) || (!City) || (!State) || (!$zip) || (!hphone) || (!eligible) || (!felony))
    {
    $link_image1 = "<input type=\"image\" src=\"personal_green.gif\" name=\"action\" value=\"info\">";
    }
    else
    {
    $link_image1 = "blue";
    }
    echo $link_image1;
    }?></form><?
    }
    else
    {
    echo "Not Authorized!";
    }
    ?>
    [Edited by Hartmann on 11-01-2000 at 11:38 AM]

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erich, when you use an image type input it does not send the input name attribute alone but it does the send the coordinates of where the button was clicked as
    $imageinputname_x and $imageinputname_y
    So checking for the existence of the variables will allow you to know whther or not the form was submitted by clicking on the image input
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erich...would you mind editing your post and getting rid of the spaces before each line of your code?

    Thanks sir...
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  4. #4
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Thanks,
    But I don't understand... I thought you can use images to submit forms. But when I click the image it sends me back to the same page! I need a way to change the action of the button. Could I put each button in its own form?

    oh BTW, my real name isn't Erich My name is Stephan. I am real big history buff so I put Erich Hartmann as my nickname

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erich, yes the image input acts as a submit button, so it will take you to where the form action points, you may want to include each one in a separate form, but remember that each form will only submit fields that live within each form.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    So what I could do is for each button make a new form:

    <form action="<? print $PHP_SELF ?>" method="post">
    <input type="hidden" name="action" value="info">
    <input type="hidden" name="username" value="<? print $username ?>">
    <input type="hidden" name="password" value="<? print $password ?>">
    <input type="image" src="image.src">
    </form>

    And it would work.
    I know it is repetitive but I don't feel like messing with cookies LOL!

  7. #7
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am interested in that too. How can you have five differnet submit buttons have different actions each, but all be in the same form (so they submit the same variables).

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay this is realy untested and my network just went down so I can't test it but here goes you have a javascript that is called when one of the images is clicked, the image is a link with a js call in it which passes a new page to the script, the script changes the action of the form and the submits it. Please let me know if this works or not.

    javascript
    function changeaction(url) {
    document.theform.action = url;
    document.theform.submit();
    }

    <form name="theform">
    for your images use <a href="#" onClick="changeaction('onepage.php');"><img src="someimage.gif"></a>
    </form>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tested this on my server and workls great, Erich did it work for you?

    Here is the code
    <html>
    <head>
    <title>Untitled</title>
    <script language="JavaScript1.2">
    <!--
    function changeaction(url) {
    document.theform.action = url;
    document.theform.submit();
    }

    //-->
    </script>
    </head>
    <body>

    <form name="theform">
    <input type="hidden" name="name1" value="val1">
    <input type="hidden" name="name2" value="val2">
    <input type="hidden" name="name3" value="val3">

    <a href="#" onClick="changeaction('onepage.php');"><img src="banner1.gif" width="125" height="125" alt="" border="0"></a><br>
    <a href="#" onClick="changeaction('twopage.php');"><img src="banner2.gif" width="125" height="125" alt="" border="0"></a><br>
    <a href="#" onClick="changeaction('threepage.php');"><img src="banner3.gif" width="125" height="125" alt="" border="0"></a><br>

    </form>
    </body>
    </html>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Yes. It works

    I now have another problem..... Read this post lol - http://www.sitepointforums.com/showt...threadid=10566

    Thanks,

  11. #11
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    okay this is realy untested and my network just went down so I can't test it but here goes you have a javascript that is called when one of the images is clicked, the image is a link with a js call in it which passes a new page to the script, the script changes the action of the form and the submits it. Please let me know if this works or not.

    javascript
    function changeaction(url) {
    document.theform.action = url;
    document.theform.submit();
    }

    <form name="theform">
    for your images use <a href="#" onClick="changeaction('onepage.php');"><img src="someimage.gif"></a>
    </form>
    Theres a much eaiser way...in php you can just have the page reload and have differnet form actions depending on the variable. much better that using javascript and having multiple pages.

  12. #12
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah but I thought Erich wanted to have a giant form with a bunch of different fields in it, then have six different images in it and all of them are submit buttons but each one needs the form to post somewhere different. Just answering the questions for what they are.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  13. #13
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, I know. I am saying you could acheive the same thing by checking which image the clicked and then doing that form action depending on which one they clicked. it would be better than javscript...do you undetstand what i mean?

  14. #14
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not really if the form already gets submitted, unless all the processing regardless of whcih image was clicked happens on the same page, you would need to pass all that data on to another page somehow. Don't you think it would be easiest to do it before the submit the form?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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