...

View Full Version : Feedback Form Issue.



pminister
02-03-2010, 05:45 AM
Now I got the feedback form to work, and it gives me a confirmation page. What I really want is after the user hits the "submit" button, I want the message to be sent. And not get the confirmation page, but instead just reload or reset back to its original contact form page.

Current Code [ HTML ]



<form method="post" action="contact_a.php">


<label for="fullname">Full Name</label>
<input type="text" name="fullname" id="fullname" /><br />

<label for="email">Email</label>
<input type="text" name="email" id="email" /><br />

<label for="topic">Subject</label>
<input type="text" name="topic" id="topic" /><br />

<label for="info">Message</label>
<textarea name="info" rows="10" wrap="virtual" id="info"></textarea>

<input type="submit" value="Submit" name="submit" />
</form>


Current Code [ PHP ]



<?php
$name = $_POST['fullname'];
$email = $_POST['email'];
$title = $_POST['topic'];
$body = $_POST['info'];

$to = 'demo@email.com';
$subject = "$title";
$msg = "$body";
mail($to, $subject, $msg, 'From:' . $email);
?>


Side Note: Before you say anything about the confirmation page / PHP code, there is actually a Thank You Note in HTML form.


I'd appreciate any help. Thank You.

Coyote6
02-03-2010, 05:59 AM
I think this is what you want. You should validate all you data before sending the email. Just FYI. Not exactly a secure form but a simple one.


<?php
$name = '';
$email = '';
$title = '';
$body = '';
$message = 'Please fill out this form to send me an email.';

// Check if form is submitted.
if (isset ($_POST['submit'])) {
$name = $_POST['fullname'];
$email = $_POST['email'];
$title = $_POST['topic'];
$body = $_POST['info'];

$to = 'demo@email.com';
$subject = "$title";
$msg = "$body";

// If the email sends give the user a success message.
if (mail($to, $subject, $msg, 'From:' . $email)) {
$message = 'Thank you for your response. I will get back to you as soon as possible.';
}
else {
$message = 'Sorry there was an error sending you email.';
}
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
if ((isset ($message)) && ($message != '')) {
echo "<p>$message</p>";
}
?>
<label for="fullname">Full Name</label>
<input type="text" name="fullname" id="fullname" value="<?php echo $name; ?>" /><br />

<label for="email">Email</label>
<input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br />

<label for="topic">Subject</label>
<input type="text" name="topic" id="topic" value="<?php echo $title; ?>"/><br />

<label for="info">Message</label>
<textarea name="info" rows="10" wrap="virtual" id="info"><?php echo $body; ?>"</textarea>

<input type="submit" value="Submit" name="submit" />
</form>

pminister
02-03-2010, 06:04 AM
I appreciate the reply. But there was one thing I forgot to mention is that.......

The form is on contact.html while the php is on its own file contact_a.php

Coyote6
02-03-2010, 06:09 AM
If you want them to be able to see the form they need to be on the same script... also change the contact.html to contact.php because html files can be downloaded and php cannot. Basically I already accounted for that with the action going to $_SERVER['PHP_SELF']; So just change the form name as I mentioned and you should be good to go.

Coyote6
02-03-2010, 06:12 AM
Or if you don't want them to get the variables back or a message just add this to the bottom of your contact_a.php page.



header ('Location: http://www.example.com/contact.html');
exit();

Len Whistler
02-03-2010, 06:32 AM
I appreciate the reply. But there was one thing I forgot to mention is that.......

The form is on contact.html while the php is on its own file contact_a.php

That shows clearly in your original post. But in my opinion it's better to use one file as in Coyote6 example on post #2. It makes updating - and debugging - a lot easier with fewer files.


------------------------------

pminister
02-03-2010, 06:52 AM
Well i tried the one page method as suggested. Now when i first go to the php page, and if i dont enter any info and still hit the submit button. It will give me the thank you message anyway, but won't send me an email.

2nd thing is... Say after entering the info, then hit submit. Well it sends the email, but the info i entered stays.

Thanks again.

prasanthmj
02-03-2010, 08:21 AM
You have to validate the form input See the pages below for an example:
PHP based email contact form (http://www.html-form-guide.com/contact-form/php-email-contact-form.html)

PHP form tutorial (http://www.html-form-guide.com/php-form/php-form-tutorial.html)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum