HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Using input type="image" with php form not possibl
Post new topic   Reply to topic    HTML Help Forum Index -> PHP
View previous topic :: View next topic  
Author Message
mypointofview



Joined: 18 Mar 2005
Posts: 32
Location: Los Angeles

PostPosted: Fri Sep 02, 2005 11:55 pm     Using input type="image" with php form not possibl Reply with quote

Hi all, I'm just getting started with php but all looks good. I have my first email form up which uses php and it works Smile The input is the generic button which I would like to replace with a rollover picture of my own choice.

My personalized input button worked fine when using Matt's Form CGI script but not anymore with the php script - I need your help.

Here is the php code I use:

Code:
<?
$sendto="mynameatmydomain.com";
$emailsubject="[From website] php test form";
$thankyou="this is the text to be displayed when your visitors submit the form";

if ($submit) {

      if ($visitorName <= "")
            $message="Please enter your name.";
      else if ($visitorPhone <= "")
            $message="Please enter your phone number.";
      else if ($comments <= "")
            $message="Please write something in the message field.";
      if ($message)
            echo ($message);
      else {
            mail("$sendto",
            "$emailsubject",
            "\r\nName: $visitorName\r\nEmail: $visitorEmail\r\nComments:\r\n$comments",
            "From: $visitorName <$visitorEmail>");
            echo ("<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$thankyou");
            die();
      }
}
?>


The submit html which works is this:

Code:
<input type="submit" name="submit" value="submit form">


Here is the code that works with the CGI script but not with the php:

Code:
<input type="image" name="submit" src="http://www.mydomain.com/basicimages/send.gif" ALT="Send" width="20" height="20" onmouseover="javascript:this.src='http://www.mydomain.com/basicimages/send_2.gif';" onmouseout="javascript:this.src='http://www.mydomain.com/basicimages/send.gif';">


Why is it that it worked with CGI but not with PHP ?

I really need a personalized input logo because my site will look very graphic and those generic browser buttons which look different under each browser would destroy the look and feel of my design.

Martin

PS: the arobas (at sign) is replaced in this code above with "at" -- I don't know why - maybe a anti spambot feature of this forum?
degsy



Joined: 23 Feb 2005
Posts: 2440
Location: North East, UK

PostPosted: Sat Sep 03, 2005 4:05 am     Reply with quote

PHP uses the $_POST global variables to check values.
The Image is a strange one though.

If you do some checking then you can work out the code you need.

Code:

<form method="post" >
<input type="image" name="submit" src="http://www.mydomain.com/basicimages/send.gif" ALT="Send" width="20" height="20" onmouseover="javascript:this.src='http://www.mydomain.com/basicimages/send_2.gif';" onmouseout="javascript:this.src='http://www.mydomain.com/basicimages/send.gif';">
<input type="submit" name="submit" value="Submit" />
</form>

<?
if($_POST){
print_r($_POST);
}
if($_POST['submit_x']){
   echo "An image button was used";
}
if($_POST['submit']){
   echo "A submit button was used";
}
?>
mypointofview



Joined: 18 Mar 2005
Posts: 32
Location: Los Angeles

PostPosted: Sat Sep 03, 2005 9:31 pm     Reply with quote

Degs, I pasted the code and all I get is the echo and two inputs (image and button).

Could you help me set me up with the right code? All I need is that simple feedback form with the submit button as image...

How do I do this?

How do I use your advice? Do I have to put your code into the main php (see my initial post further up) ?

Thanks, Martin.
mypointofview



Joined: 18 Mar 2005
Posts: 32
Location: Los Angeles

PostPosted: Sat Sep 03, 2005 9:52 pm     WOOORKS :-)))) Reply with quote

Degs, you are the master of the universe - THANK YOU!! Very Happy

I figured it. Hehe, good advice makes the pupil figure out stuff himself.

Alright - all I did is change in my preceeding php part :

Code:
 if ($submit) {


changed to

Code:
 if ($submit_x) {


That little underscore and x really did it. I apparently states "if an image was clicked..." GREAT!!

Thanks again, Martin.

PS: also wonderful that now not only is my email address is hard coded as opposed to with Matt's Form Script, thus hidden from spambots, but also I don't get those x/y coordinates anymore in the email Smile
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> PHP All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial