PDA

View Full Version : Contact form



katerina
31 May 2009, 06:58 AM
Hi all,
I develop my site and I would like to add a contact form.

Something like that :


<form method="POST" action="mailto:a@yahoo.com?" name="form1" id="form1" onsubmit="return validateFormOnSubmit(this);">
fullname : <input value="" size="45" id="name" name="name" type="text">
Email : <input value="" size="45" id="email" name="email" type="text">
subject <input value="" size="45" id="sub" name="sub" type="text">
MEssage : <textarea rows="4" cols="45" id="notes" name="notes">
</textarea>
<input value="ok" id="1" name="1" type="submit">
</form>


An user types all the fields and I would like to see all the information in my e-mail a@yahoo.com.

Any help ??


Thanks

Alan
31 May 2009, 02:22 PM
Hi all,
I develop my site and I would like to add a contact form.

Something like that :


<form method="POST" action="mailto:a@yahoo.com?" name="form1" id="form1" onsubmit="return validateFormOnSubmit(this);">
fullname : <input value="" size="45" id="name" name="name" type="text">
Email : <input value="" size="45" id="email" name="email" type="text">
subject <input value="" size="45" id="sub" name="sub" type="text">
MEssage : <textarea rows="4" cols="45" id="notes" name="notes">
</textarea>
<input value="ok" id="1" name="1" type="submit">
</form>


An user types all the fields and I would like to see all the information in my e-mail a@yahoo.com.

Any help ??


Thanks

Just a few notes:

Your validation can be bypassed if Javascript has been turned off. Javascript is generally only used to save time and provide a more pleasent user experience.

Your action must be targeting a script that will process the form's post variables. (method="post"). Such as contact_form.php.

The contact_form.php will access PHP's POST array (it's where post variables are stored) and deal with them in whatever way you want. A basic contact form would go like this:



<?php
if(isset($_POST['name']) && !empty($_POST['name']))
{
$name = $_POST['name'];
(isset($_POST['email']) && !empty($_POST['email']) ? $email = $_POST['email'] : $email = '';
(isset($_POST['sub']) && !empty($_POST['sub']) ? $sub = $_POST['sub'] : $sub = '';
(isset($_POST['notes']) && !empty($_POST['notes']) ? $notes = $_POST['notes'] : $notes = '';

if(!empty($name) && !empty($email) && !empty($sub) && !empty($notes))
{
$headers = ''; // Insert your headers here
if(mail('a@yahoo.com',$sub,$notes,$headers))
echo "Message sent successfully.";
else
echo "Message failed. Contact an administrator.";
}
else
echo "You did not enter all the required information.";
}
?>


Simple as that. :) Bear in mind that there is no validation on this script, and it is very insecure. :) But you'll figure it out.