PDA

View Full Version : image form submit problem


laurenced
05-24-2005, 04:00 PM
Hi all, I'm using an emailer script and I can't get an image to work as a submit button instead of a normal HTML button.

Here's my code for the form:


<form name="mailman" id="mailman" method="post" action="">
<table border="0" cellpadding=2 cellspacing=0>
<tr>
<td width="120" align=right class="contentBlue"><b>Your name:</b></td>
<td align=left><input type=text id="name" name="name" class="mailInput">
<font class="smallRed">*</font></td>
</tr>
<tr>
<td width="120" align=right class="contentBlue"><b>Your e-mail:</b></td>
<td align=left><input type=text id="email" name="email" class="mailInput">
<font class="smallRed">*</font></td>
</tr>
<tr>
<td width="120" align=right class="contentBlue"><b>Your telephone:</b></td>
<td align=left><input type=number id="telephone" name="telephone" class="mailInput">
<font class="smallRed">*</font></td>
</tr>
<tr valign=top>
<td width="120" align=right class="contentBlue"><b>Mailing address:</b></td>
<td align=left><textarea id="mailaddress" name="mailaddress" cols=30 rows=2 class="mailInput"></textarea></td>
</tr>
<tr valign=top>
<td width="120" align=right class="contentBlue"><b>Message:</b></td>
<td align=left><textarea id="message" name="msg" cols=60 rows=4 class="mailInput"></textarea>
<font class="smallRed">*</font></td>
</tr>
<tr valign=top>
<td width="120"></td>
<td align=right><font class="smallRed">* required fields</font></td>
</tr>
<tr valign=top>
<td width="120"></td>
<td align=left><a href="javascript:document.mailman.submit();"><img src="/images/sendMessage.gif"></a><INPUT id="submit" type="image" name="submit" src="images/sendMessage.gif" border="0" alt="Submit"></td>
</tr>
</table>
</form>


and it doesn't work. I've also tried this method:


<INPUT TYPE="IMAGE" SRC="/images/sendMessage.giff" ALT="Submit" BORDER="0">


but it doesn't work either. The page just reloads and none of the validation (or indeed the sending) in my PHP script works (the script works fine with an ordinary HTML button, by the way, so it's not the script that is broken here).

The java console in Firefox says 'document.mailman.sender has no properties'. I don't know what this means because there's no element called 'sender' anywhere on the page.

Any help would be much appreciated.

Laurence

_Aerospace_Eng_
05-24-2005, 04:28 PM
You have a few invalid input fields, there is no input type="number" it should be text. Reason the page reloads is because its submitting to a blank action, some php mail scripts submit to themselves. I don't get a js error in FF. Can you leave a link to the page online somewhere?

laurenced
05-24-2005, 04:39 PM
You have a few invalid input fields, there is no input type="number" it should be text. Reason the page reloads is because its submitting to a blank action, some php mail scripts submit to themselves. I don't get a js error in FF. Can you leave a link to the page online somewhere?

Thanks for your reply. Yes the form is meant to submit to the PHP file it is within.

Here's a link:

http://www.dovilproperties.com/testemailform.php?listingID=127

(the listingID is just so the page gets a variable to insert into the script)

It's a bit of a mess but you can see what I'm trying to do - use the pretty form at the top and one of the 'send message' images as a submit link. The grey form below is the original form that came with the script which worked fine.

fyo
05-24-2005, 04:41 PM
There are two, and only two, general ways of making a button that submits a form:

1) A standard submit button. That is, a button type="submit".
2) Use any other kind of button and use JavaScript (e.g. onClick) to submit the form.

This type="image" stuff you have going on... well... ;-)

-fyo

laurenced
05-24-2005, 04:42 PM
There are two, and only two, general ways of making a button that submits a form:

1) A standard submit button. That is, a button type="submit".
2) Use any other kind of button and use JavaScript (e.g. onClick) to submit the form.

This type="image" stuff you have going on... well... ;-)

-fyo

Yeah I dunno what that's about, I stole it from another site. Pah

_Aerospace_Eng_
05-24-2005, 04:50 PM
Okay I am still not getting any javascript warnings or errors in both FF and IE, what you might want to do is set the action to the name of the script so <form method="post" action="testemailform.php"> that might work, but can't tell without seeing the php script, if you can zip up the original php file, and upload as an attachment to a new post.
And the input type="image" is perfectly valid, it usually does act as a submit button, what you could do though, is use this
<input type="submit" value="" style="background:url(images/sendMessage.gif);border:0;width:202px;height:18px;">

laurenced
05-24-2005, 04:53 PM
Okay I am still not getting any javascript warnings or errors in both FF and IE, what you might want to do is set the action to the name of the script so <form method="post" action="testemailform.php"> that might work, but can't tell without seeing the php script, if you can zip up the original php file, and upload as an attachment to a new post.
I tried using the filename as the action but that didn't work.

Here's the php file attached.

laurenced
05-24-2005, 04:55 PM
Okay I am still not getting any javascript warnings or errors in both FF and IE, what you might want to do is set the action to the name of the script so <form method="post" action="testemailform.php"> that might work, but can't tell without seeing the php script, if you can zip up the original php file, and upload as an attachment to a new post.
And the input type="image" is perfectly valid, it usually does act as a submit button, what you could do though, is use this
<input type="submit" value="" style="background:url(images/sendMessage.gif);border:0;width:202px;height:18px;">



Your second suggestion didn't work either :(

scoutt
05-24-2005, 05:00 PM
how are you checking for the submitted form?

if you use a image:

<INPUT id="submit" type="image" name="submit" src="images/sendMessage.gif" border="0" alt="Submit">

and the php script is checking for "submit" than it will not work. for one, you cannot use alt="" or border in a input type submit. for two, when you submit that form the name of the submit button changes, it will be the coordinates of the image.


$_POST['submit']

// now becomes

$_POST['submit_x'] and/or $_POST['submit_y']

you will have to check in the php script. bad way to do it really as you should never rely on a button name unless you really had to.

_Aerospace_Eng_
05-24-2005, 05:44 PM
I think I will move this to the php forum seeing as how it is the script that is not working correctly. If you will like an alternative script, let me know and I can configure a script I have on my laptop.

laurenced
05-25-2005, 10:31 AM
I think I will move this to the php forum seeing as how it is the script that is not working correctly. If you will like an alternative script, let me know and I can configure a script I have on my laptop.

Thanks for your help. I'm not sure it is the PHP script that is at fault, as I said it worked fine when I just used a normal HTML button. The issue is getting an image to submit the form in exactly the same way as the HTML button does.

If you've got another script which validates which I could use, I would appreciate it very much! Thanks for all your help. Another thing I need to get working is the ability for the script to send to two addresses, but that's simple enough, I was just going to duplicate the mailing function substituting the first email address for the second one.

scoutt
05-25-2005, 11:02 AM
Thanks for your help. I'm not sure it is the PHP script that is at fault, as I said it worked fine when I just used a normal HTML button. The issue is getting an image to submit the form in exactly the same way as the HTML button does.
.
I just told you what is wrong. when you use a regular buton it sends the value "submit" but when you use a image it sends "submit_x" no need to change anything but the php script.

read my post again. it will work

laurenced
05-25-2005, 11:09 AM
how are you checking for the submitted form?

if you use a image:

<INPUT id="submit" type="image" name="submit" src="images/sendMessage.gif" border="0" alt="Submit">

and the php script is checking for "submit" than it will not work. for one, you cannot use alt="" or border in a input type submit. for two, when you submit that form the name of the submit button changes, it will be the coordinates of the image.


$_POST['submit']

// now becomes

$_POST['submit_x'] and/or $_POST['submit_y']

you will have to check in the php script. bad way to do it really as you should never rely on a button name unless you really had to.


That works fine. Thanks for your help.

-L