Log in

View Full Version : Mailform



chechu
11-15-2006, 10:16 AM
Hey you all,
Can anyone tell me why this code doesn't work ?



<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
</script>

</head>

<body background="bgpalet.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="80%" height="100%" border="0" cellpadding="0" cellspacing="0" align=right>
<tr><td align="center" valign="middle">

<table border="0" width=100% align=right>
<tr><td width="120" valign="middle">

</td><td valign="middle" align="right">

<FORM NAME="form1" METHOD="post" ACTION="contact.php">

<table width="100%" valign="top" align=center>
<tr><td>
<table width=100%>
<tr><td align=left>
<INPUT TYPE=TEXT NAME="name" VALUE="your name" onFocus="clearDefault(this)" style="border:1px solid #666666; width:190px">
</td></tr>
<tr><td align=left>
<INPUT TYPE=TEXT NAME="email" VALUE="your e-mail" onFocus="clearDefault(this)" style="border:1px solid #666666; width:190px">
</td></tr></table>
</td><td width=20>
&nbsp</td><td align=left valign=middle>
<INPUT TYPE="image" src="emailgo.jpg" NAME="submit" VALUE="go" style="border: 0px">
</td></tr></table>

<table width="100%" valign="top" align=center>
<tr><td align=right>
<TEXTAREA NAME="message" style="border:1px solid #666666; width:265px; height:120px">
</TEXTAREA>
</td></tr></table>


</FORM>

</td></tr></table>
</td></tr></table>

</body>
</html>

mwinter
11-15-2006, 06:53 PM
You might want to start by suggesting what's wrong with it. The phrase "doesn't work" isn't very enlightening.

Out of curiosity, just how many nested tables do you want?! Don't use tables to effect layout. Use CSS.

Mike

chechu
11-16-2006, 10:20 AM
I have no idea what is wrong with it, that's why I asked ... I guess it has someting to do with this:
<INPUT TYPE="image" src="emailgo.jpg" NAME="submit" VALUE="go" style="border: 0px">

About the tables: everything looks fine, so I stick to something I know. Unless you can explain me more about how the css would work ?

mwinter
11-16-2006, 10:07 PM
I have no idea what is wrong with it ...

Clearly you do: you said that "this code doesn't work", so you must have some expectations of what it's supposed to do.

Mike

chechu
11-17-2006, 10:35 AM
Dear Mike,

Okay, so as everyone knows, especially a "professor", a mailform is supposed to send the input data to a mailserver, or in this case, be processed by another file called "contact.php".
As this expected action hasn't been taken,something must be wrong ? But it could have various reasons:
- the .php file (correct ?)
- the html code without the <form> tags (correct ?)
- the <form> itself (correct ?)

Actually, someone that doesn't know what this code is supposed to do, shouldn't reply. Luckily, in the meantime, someone that did understand this code (a student by the way), checked it and confirmed me by personal mail that the code is entirely correct. So there is another reason, maybe the .php(to be confirmed).

Is it clear now, Mike ?

codeexploiter
11-17-2006, 10:53 AM
What kind of error you are getting while executing the above mentioned page, you haven't mentioned nothing about that.

BLiZZaRD
11-17-2006, 11:05 AM
Dear Mike,

Okay, so as everyone knows, especially a "professor", a mailform is supposed to send the input data to a mailserver, or in this case, be processed by another file called "contact.php".
As this expected action hasn't been taken,something must be wrong ? But it could have various reasons:
- the .php file (correct ?)
- the html code without the <form> tags (correct ?)
- the <form> itself (correct ?)

Actually, someone that doesn't know what this code is supposed to do, shouldn't reply. Luckily, in the meantime, someone that did understand this code (a student by the way), checked it and confirmed me by personal mail that the code is entirely correct. So there is another reason, maybe the .php(to be confirmed).

Is it clear now, Mike ?

Flattery will get you nowhere :D

What Mike was asking was not what is the code supposed to do, rather, what are your expectations for said code, and what is failing to meet those expectations?

If the code works once and then never again, or if you get a blank response, or other problem.

Posting a code snippet and saying "fix it" isn't going to get fixed. Those trying to help you will need to know what you have done to try and solve it yourself, as well as what you are expecting from the code and what it is or isn't doing.

oh, and BTW the student/teacher/professor thing, just means how much we talk, not how much we know ;) Except in Mike's case (and a handful of others...) Who have probably forgotten more than you and I will ever know.. back off the insults and just answer the questions needed to get the help you want.

chechu
11-17-2006, 12:41 PM
No insults, opinions !
Nothing appears; it remains the same page.
- the .php file is correct
- the html code without the <form> tags (correct ?)
- the <form> itself (correct ?)
So something is wrong in the code ?

BLiZZaRD
11-17-2006, 01:46 PM
That or your server is not set up to allow/support PHP... by saying "nothing appears" do you mean you have a blank page?

If so you might not have php support there.... or you may have to adapt a .htaccess file to include php on an html page...

chechu
11-17-2006, 02:24 PM
The same page remains (doesn't change)

That or your server is not ...
My server supports .php, so ...
Can anyone please tell me why this code doesn't work ?

mwinter
11-17-2006, 11:32 PM
There's nothing functionally wrong with the markup you've posted, so the problem lies elsewhere. Have you used a protocol analyser or looked at your server logs to determine what's being sent back and forth between you and the server, or if errors are being generated somewhere?

Mike

chechu
11-18-2006, 09:18 AM
Thanks a lot guys !
I'll have a chat with my provider.

chechu
11-18-2006, 12:54 PM
Nope. Server should be OK, but still doesn't work. Can anyone download the two codes and see what is wrong, please ?

Code of the mailform:

<html>
<head>

<script language="JavaScript" type="text/JavaScript">
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
</script>

</head>

<body background="bgpalet.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="80%" height="100%" border="0" cellpadding="0" cellspacing="0" align=right>
<tr><td align="center" valign="middle">

<table border="0" width=100% align=right>
<tr><td width="120" valign="middle">

</td><td valign="middle" align="right">

<FORM NAME="form1" METHOD="post" ACTION="contactEN.php">

<table width="100%" valign="top" align=center>
<tr><td>
<table width=100%>
<tr><td align=left>
<INPUT TYPE=TEXT NAME="name" VALUE="your name" onFocus="clearDefault(this)" style="border:1px solid #666666; width:190px">
</td></tr>
<tr><td align=left>
<INPUT TYPE=TEXT NAME="email" VALUE="your e-mail" onFocus="clearDefault(this)" style="border:1px solid #666666; width:190px">
</td></tr></table>
</td><td width=20>
&nbsp</td><td align=left valign=middle>
<INPUT TYPE="image" src="emailgo.jpg" NAME="submit" VALUE="go" style="border: 0px">
</td></tr></table>

<table width="100%" valign="top" align=center>
<tr><td align=right>
<TEXTAREA NAME="message" style="border:1px solid #666666; width:265px; height:120px">
</TEXTAREA>
</td></tr></table>
</FORM>

</td></tr></table>
</td></tr></table>

</body>
</html>


And this is the .php code:


<html>
<head>
</head>

<body background="bgpalet.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align="center" valign="middle">

<table border="0" width=100%>
<tr><td width="120" valign="middle">

</td><td valign="middle" align="right">

<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR VALIGN=TOP ALIGN=center><TD WIDTH=300>

<img src="emailsent.gif" border="0">
<p>

<?
if ($_POST["Submit"]){

if ($_POST["name"] and $_POST["email"] and $_POST["message"] ){

mail (
"info@casariegoart.com",
"via website (EN)",
"
Name: ".$_POST['name']."
E-mail: ".$_POST['email']."
Message: ".$_POST['message']."

",
"From: ".$_POST['name']." <".$_POST['email'].">");

echo '<p align="center"><font color="#003366">Thanks !<br>Your message has been sent.<br> We will get back to you as soon as we can.</font></p>';
}
else{
echo '<p align="center"><font color="#FF0000">Please fill in all data!<br>All fields are obligatory.</font></p><p><a href="contactEN.html">[back]</a>';

}
}
?>


</td></tr></table>
</td></tr></table>
</td></tr></table>

</body>
</html>

What is wrong ???

chechu
11-19-2006, 11:14 AM
Tried again, and the thing is that the form works when I place a submit button. When I place an image to submit, then it goes to the .php page, but only shows an image and no text.

So is this the problem:

<INPUT TYPE="image" src="emailgo.jpg" NAME="submit" VALUE="go" style="border: 0px">

It is really confusing me. Could someone please upload these codes and check them out.

penguin
11-19-2006, 02:23 PM
easy fix,
the problem is you don't have a submit button
forms have to be "submitted"
an image is not a submit button
you can style submit buttons, they HAVE to be SUBMIT buttons though.

for testing do this
add
input type=submit name=submit value=Send

echo something [maybe your values from your form] to the screen on you contact.php page that would be a good start for you.

hope this helps you out.

S

mwinter
11-19-2006, 03:43 PM
The problem is that you are looking for the wrong name within the $_POST superglobal. Image input elements send co-ordinates of the click location within the image (with values of zero if a pointing device wasn't used), and these values take the form, name.x and name.y. These names aren't used within PHP: instead they are changed to name_x and name_y, respectively.

Your mail form allows for spamming through the Cc and Bcc headers as you don't validate input properly.




the problem is you don't have a submit button

Incorrect.



an image is not a submit button

No, but an input element of type, submit, is.

Mike

chechu
11-19-2006, 03:47 PM
So the .html is correct ?
And what changes do I have to make in the php ?
You explained it very well, thanks, but I do not know how to solve it ...

mwinter
11-19-2006, 04:04 PM
So the .html is correct ?

Yes.



And what changes do I have to make in the php ?

To solve the immediate problem, you need to check for the right name: not "Submit", but "submit_x" or "submit_y":



if (isset($_POST['submit_x'])) {
/* ... */
}

You should use a similar style to check for the presence of the other fields to avoid notices being generated in the PHP error log.

You need much more stringent checks on those fields: the name should not be allowed to contain carriage return or line feed characters, and the e-mail address should conform to the mailbox production in RFC 2822. You can find code to check the latter on the Web.

Mike

chechu
11-19-2006, 04:40 PM
You need much more stringent checks on those fields: the name should not be allowed to contain carriage return or line feed characters, and the e-mail address should conform to the mailbox production in RFC 2822. You can find code to check the latter on the Web.

This I do not understand. What you are talking about, can you change that in the code ?