Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with php contact form

Status
Not open for further replies.

jj1234

MIS
Jan 27, 2006
46
GB
Hello,

I am trying to work out how to make the following changs to the form as l don't have much knowledge of PHP.

1. Validate each field

2. Display thank you page.

3. Display error page if all fields are not complete.


coding:

<?php
$to="jjr@club-amigos.co.uk ";
if (!isset($_POST["send"])){
// no post data -> display form
?>
<form method="POST" action="<?=$_SERVER['PHP_SELF'];?>">
To: jjr@club-amigos.co.uk

From: <input type="text" name="sender">

Subject : <input type="text" name="subject">

Message :

<textarea name="message" rows="10" cols="60" lines="20"></textarea>

<input type="submit" name="send" value="Send">

</form>
<?
}else{
// found post data .. deal with it
$from=$_POST['sender'];
// send mail :
if (mail($to,$_POST['subject'],$_POST['message'],"From: $from\n")){
// display confirmation message if mail sent successfully
echo "Your mail was indeed sent to $to.
";
}else{
// sending failed, display error message
echo "Doh! Your mail could not be sent.
";
}
}
?>
 
When you have come across a problem implementing a specific part of your code - by all means ask away... but we're not going to write your code for you. That is not the purpose of TekTips.

Show us the attempts you have made to complete your modifications... explain the problems you are experiencing... and document important information so we don't have to pry it our of you (like the validation rules you wish to implement).

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
I don't really understand php that much.

I have done a simple one which l can understand, but some one recommend this one which is supposed to be better.
As it is more complex l only have a rough idea as to where the coding would go.
If l stick to the simple one l could get spammed a lot, if l use a more complex one l don't understand l won't get spammed as much but will be out of my depth with regards to coding it.
Do you have a solution?
 
The Validation portion would go in the else part of the code you posted,. Where it says
[red]//found post data .. deal with it[/red]
In there its all a matter of capturing the form values and checking them to see if everything is as you expect.
Using the POST variable to obtain the values fo the form.
You can then check it.

For example:

Code:
$from=$_POST['sender'];

This gets the contents of the "FROM:" text field.

You can then test the variable to see if there is something there. 

if(empty($from)){
/if its empty you can set a message to tell the user it is empty.

$message.="The From Field is empty";
}

Try to check all the fields on your own, and if yopu run into any trouble, come back and we will try to help you. What we wont do is create the entire code for you.







----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Can you tell me where this code would go in the script?
 
What did I say in the post:

Vacunita said:
The Validation portion would go in the [blue]else[/blue] part of the code you posted,. Where it says
jj1234 said:
//found post data .. deal with it

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top