SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Graphic submit button with PHP?

    Is it possible to replace the boring old Submit button with a graphic image? I have a form with <form action="<?=$PHP_SELF?>" method="post"> and I've replaced
    <input type="submit" value="Submit" name="submit">
    with
    <input type="image" src="submit.gif" name="submit" alt="Submit">
    The form comes back to self but the $submit variable is not set. Have I missed something or is it not possible?
    Last edited by gandalf458; Sep 2, 2002 at 11:18.

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    United States
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.yourhtmlsource.com/forms/imagesubmit.html

    That shows how you're suppose to do it....I found that after doing this Google search; a lot of great websites came up talking about this issue.

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks but that doesn't actually help. I seem to have the HTML correct but it doesn't work with the PHP code.

  4. #4
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the form action, it should be <?php echo($_SERVER['PHP_SELF']); ?> instead of <?php=$PHP_SELF?>. Additionally, on your page where you're getting the data, are you using $submit or $_POST['submit']? You should be using the latter. Ditto for the $_POST thing on all variables you send across pages.

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Colin. I've been using Kevin Yank's book. He never mentions $_SERVER['...']. Can you explain to an ageing hippie what is the purpose of this? When and why do I need to use it? G

  6. #6
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hey ageing hippy

    PHP has changed a little since Kevins book - to address this he has written an article here explaining what they've changed, why, and how to adapt to it

    The changes are minor and do make sense - you'll find you need to change very little to your scripts to get them up-to-date.
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  7. #7
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool. Thanks. It doesn't seem to solve my problem with the graphic button, but hey I've got enough else to do putting $_SERVERs etc in all my scripts. [Thinks - must find a decent multiple file text editor!]

    However, one question KY's article raises is what is best regarding include files -- whether to use include or require, and whether the extension for included files should be .inc or .php (or even .htm if they include no php code)?

    G

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Location
    USA
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For include vs. require, I'll leave it to the experts:
    http://www.php.net/manual/en/function.require.php
    require() and include() are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well.
    And as far as what extension to use, I always use .php if the included file contains PHP code. This way if someone stumbles upon the included file on its own, people won't see the PHP code. Of course, one could either set .inc files to parse as PHP or deny direct access to them with a .htaccess file, but making includes .php is less hassle. If the included file has no PHP code, use whatever you wish.
    Last edited by Joel; Sep 3, 2002 at 04:34.

  9. #9
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Extension really doesn't matter, I tend to use .php for parsed content and .inc for static, but afaik it is pretty irrelevent other than to "housekeeping".

    Regarding include or require:

    require() and include() are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.
    From Your best friend

    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  10. #10
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Doh!!!

    Well at least the advice is consistent
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  11. #11
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Let me know if you manage to resolve the $submit issue with graphical submit buttons. I can remember trying to resolve that a while ago and decided that I couldn't

    I will have another go though to see if I can figure it out.

    (if you use .inc people will be able to see the file if they typed in that url (so your passwords could be seen by all!!!) so I would suggest using .php and putting them all in a seperate folder so you know which are your static files and which are your standard php files. - Either that place your .inc files outside the root directory buut you might not always be able to do that.)
    Regular user

  12. #12
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I can see a .php extension is best if it contains PHP code - especially the one with my password in I followed the example in Mr Yank's book, which was .inc - not a smart move.

    G

  13. #13
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sorry that it took me so long to respond with your image as submit button question - the answer lies below

    If your HTML submit code looks like this:
    Code:
    <input type="image" src="calc.jpg" name="calculate" value="calculate">
    Now when you clickj on this image the following variables are created $calculate_x and $calculate_y (hence why $calculate wasn't working ).

    So by doing this php:
    PHP Code:
    $calculate $_POST['calculate'];

    if ((
    $calculate_x == "") && ($calculate_y == "")) { 
    Work exactly like isset....

    I haven't tried any other combinations of isset($calculate_x) or empty($calculate_x) but the if null statement works very well..

    Hope that helps

    Sarah
    Regular user

  14. #14
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    429
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah-ha! Thanks. I shan't ask why it creates two variables.

    Are you saying I only need

    $calculate = $_POST['calculate'];

    and not

    $calculate_x = $_POST['calculate_x'];
    $calculate_y = $_POST['calculate_y'];

    ?

    G :-}

  15. #15
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No you are correct that you need to do
    PHP Code:
    $calculate_x $_POST['calculate_x'];
    $calculate_y $_POST['calculate_y']; 
    etc (sorry working with reg on at present!!!)

    the reason its creates 2 variables is that it actually takes the x and y coordinates from where you clicked on the image, you can probably use only one of them but for safety if you can use both might be best.

    Sarah
    Regular user

  16. #16
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sarah is spot on.

    The reason why

    <input type="image" name="name" ...>

    returns a x and y coorinate is because
    <input type="image" ... >
    is actually a hang-over from the bad old days of server side image maps. Yes folks, there was a time when browsers couldn't handle image maps and the click on the image map would be posted back to the server (as a x and y coordinage on the image) for server side processing!

    The fact that today we use this type of input field as a submit button is somewhat of a kludge!


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
  •