Jump to content

PHP - Return results in html editable region.


chisao101

Recommended Posts

I am using Dreamweaver CS4 to build a website. On my contact page, I made a form with spry validation. I used a tutvid tutorial to learn a simple form handler script (I'm a complete newb at PHP) and everything works great. The only problem I'm having is, in my Dreamweaver template, I have an editable region that has the form. When  the user clicks to submit the form, a new html page opens up that looks nothing like my website.

What I'm trying to accomplish is having the form disappear and be replaced in the same editable region with my "thank you" message. This way, the user just submits, the form disappears, and they get a thank you message on the same page, in the same place where the form was.

 

Here is the form code:

 

<form id="frmContact" name="frmContact" method="post" action="contact_form.php">
     <fieldset><legend>Submit a question or comment...</legend>
     
       <p>
         <label for="name">Name:</label>
         <span id="spryName">
         <input type="text" name="name" id="name" />
         <span class="textfieldRequiredMsg">Name is required.</span><span class="textfieldMinCharsMsg">Must have at least 3 characters.</span><span class="textfieldMaxCharsMsg">Must not exceed 20 characters.</span></span></p>
       <p>
         <label for="email">Email:</label>
         <span id="spryPassword">
         <input type="text" name="email" id="email" tabindex="10" />
         <span class="textfieldRequiredMsg">Email address is required.</span><span class="textfieldInvalidFormatMsg">Not a valid email address.</span><span class="textfieldMinCharsMsg">Not a valid email address.</span><span class="textfieldMaxCharsMsg">Not a valid email address.</span></span></p>
       <p>
         <label id="message" for="question">Please tell us how we can help you:</label><br />
         <span id="spryText">
         <textarea name="question" id="question" cols="45" rows="5" tabindex="20"></textarea><br />
         <span class="textareaRequiredMsg">A question or comment is required.</span><span class="textareaMinCharsMsg">Must have 16 characters minimum</span><span class="textareaMaxCharsMsg">Must not exceed 500 characters.</span></span></p>
       <p>
         <input type="submit" name="submit" id="submit" value="Submit" tabindex="30" />
       </p>
     </fieldset>
     </form>

 

 

Here is the PHP script:

 

<?php

/* Subject and Email variables */

$emailSubject = 'Contact Form Response';
$webMaster = 'centerline.computers@gmail.com';

/* Gather Data variables */

$nameField = $_POST['name'];
$emailField = $_POST['email'];
$questionField = $_POST['question'];

$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Message: $questionField <br>
EOD;

$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);


/* Results rendered as HTML */


$theResults = <<<EOD
<html><body>
<h2>Thank you for submitting.</h2>
<p>We will get back to you as soon as possible.</p>

</body>
</html>
EOD;
echo "$theResults";

?>

 

Thanks for any help you might have for me!

Link to comment
Share on other sites

You should combine the two scripts (if it is two separate scripts) and have the form submit to itself. You can accomplish that by leaving the action attribute of the form tag blank.

 

Then code something like this

 

<?php
if(isset($_POST['field'])) {
//Your form has been submitted. Process it, and display the code that produces the thank you message
} else {
//Display your form
}
?>

Link to comment
Share on other sites

The PHP and the form are on the same html page and there is no other php involved.

 

I was thinking (more like an uneducated guess) that using the form as an include may be the way to do it. Then when the submit is done, just include the message instead. I just don't know how to do that exactly.

 

If I use the method you posted, would I just add that code to my existing script and take out the action on the form? I really am a beginner here, so I don't understand full how to do this stuff yet.

 

Thanks for your help.

 

You should combine the two scripts (if it is two separate scripts) and have the form submit to itself. You can accomplish that by leaving the action attribute of the form tag blank.

 

Then code something like this

 

<?php
if(isset($_POST['field'])) {
//Your form has been submitted. Process it, and display the code that produces the thank you message
} else {
//Display your form
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.