Jump to content

Recommended Posts

if all you want to do is redirect then follow tendolla's example. if you want your page to look like the rest of the site you can just style your php page.

 

what ill do if this was my page is do some more filtering on the other inputs and not redirect at all. ill just style the page and echo errors or success on the same page.

that's what i wanted to do from the beginning. what my "thanks" and "error" pages look like is,

respectively:

 

<div class="thankyou-message"><p>Thanks for your message! I will get back to you soon.<br>Namaste</p></div>   

 

and

 

<div class="error-message">
<p>The message has <em>not been sent</em>. Could you please check the following:</p>
<ul>
<li>Your name is missing</li>
<li>Your company/organization name is missing</li>
<li>Your email is missing</li>
<li>Please provide phone number or Skype username</li>
<li>Please provide short message</li>
</ul>
</div>

 

i'd really like to trigger those messages on the same page as my html form.

 

is that what you mean?

 

and, if so, how would i implement that with:

 

<?php
//If the form is POSTed, do the following
if($_SERVER['REQUEST_METHOD'] == 'POST') {

    //Get the POSTed data and store in the $ variables
   $name           = $_POST['name'];
   $company         = $_POST['company'];
   $email          = $_POST['email'];
   $phone          = $_POST['phone'];
   $message   = $_POST['message'];

   //If the name field is blank, retun the below error
   if(!$name) 
   {
   echo "You must enter a name.";
   }

   //If the email address field is blank, retun the below error
   if(!$email) 
   {
   echo "You must enter an email address";
   }

   //If the email address entered appears to be of an incorrect format return the below error
   elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
   { 
   echo "You must enter a valid email address";
   }

   //If the phone number field is blank, retun the below error
   if(!$phone) 
   {
   echo "You must enter a phone number";
   }

if(!$errors)
   {
   $msg = "Full Name: $name\n\nCompany: $company\n\nEmail Address: $email\n\nPhone: $phone\n\nMessage: $message\n\n";
   
   mail("youremail@yourdomain.com", "Website Enquiry", $msg, "From: $name  <$email>");
   
   header('Location: http://mysite.com/confirm.html');
   }
   }
?>

 

 
    
    <form id="contact-form"  method="post" action="/scripts/mailer2.php">
        
        
        <fieldset>
            <h2>Your info</h2>
            <div class="field">
                <div class="col col-left">
                    <label for="name">Your name</label><br>
                    <input name="name" id="name" class="input-text" type="text">
                </div>
                <div class="col col-right">
                    <label for="company">Company or organization</label><br>
                    <input name="company" id="company" class="input-text" type="text">
                </div>
            </div>
            <div class="field last-field">
                <div class="col col-left">
                    <label for="email">E-mail</label><br>
                    <input name="email" id="email" class="input-text" type="text">
                </div>
                <div class="col col-right">
                    <label for="phone">Phone or Skype</label><br>
                    <input name="phone" id="phone" class="input-text" type="text">
                </div>
            </div>
      	</fieldset>

        <fieldset>
            
            <h2>Additional Info / Message</h2>            
                        
            <div class="field">
                <label for="message">Please add a short message:</label><br>
                <textarea name="message" id="message" cols="50" rows="5"></textarea>
            </div>
            
            <div class="field last-field">
                    <p class="smallnote">Individuals, please include any injuries or preexisting physical conditions.
                     <br><br>
                    Companies, please include number of employees and days requested.</p>
                </div>
            

            
        </fieldset>    
        
        <fieldset id="button-fieldset">
            <label for="cc" class="label-check">
                <input class="input-check" name="cc" id="cc" value="1" checked="checked" type="checkbox"> Receive a copy of this message?
            </label>
            <input class="input-hidden" name="submited" value="1" type="hidden">        
            <input class="input-image" src="img/send-message.gif" alt=" [ send message ] " onmouseover="this.src='img/send-message-hover.gif';" onmouseout="this.src='img/send-message.gif';" onmousedown="this.src='img/send-message-active.gif';" type="image">
        </fieldset>
        
    </form>

 

i know this thread is getting way too long. i do appreciate all of the help. i've run out of time to really learn anything new. it's a new business, taken all of my money to start and i really have to get out and start marketing. like yesterday. so, again, i appreciate the help.

Okay kinda lost...so you want everything on one page? If that' so all you have to do is escape php and start the html. Like this:

<?php
//If the form is POSTed, do the following
if($_SERVER['REQUEST_METHOD'] == 'POST') {

    //Get the POSTed data and store in the $ variables
   $name           = $_POST['name'];
   $company         = $_POST['company'];
   $email          = $_POST['email'];
   $phone          = $_POST['phone'];
   $message   = $_POST['message'];

   //If the name field is blank, retun the below error
   if(!$name) 
   {
   echo "You must enter a name.";
   }

   //If the email address field is blank, retun the below error
   if(!$email) 
   {
   echo "You must enter an email address";
   }

   //If the email address entered appears to be of an incorrect format return the below error
   elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
   { 
   echo "You must enter a valid email address";
   }

   //If the phone number field is blank, retun the below error
   if(!$phone) 
   {
   echo "You must enter a phone number";
   }

if(!$errors)
   {
   $msg = "Full Name: $name\n\nCompany: $company\n\nEmail Address: $email\n\nPhone: $phone\n\nMessage: $message\n\n";
   
   mail("youremail@yourdomain.com", "Website Enquiry", $msg, "From: $name  <$email>");
   
   header('Location: http://mysite.com/confirm.html');
   }
   }
?>


    
    <form id="contact-form"  method="post" action="/scripts/mailer2.php">
        
        
        <fieldset>
            <h2>Your info</h2>
            <div class="field">
                <div class="col col-left">
                    <label for="name">Your name</label><br>
                    <input name="name" id="name" class="input-text" type="text">
                </div>
                <div class="col col-right">
                    <label for="company">Company or organization</label><br>
                    <input name="company" id="company" class="input-text" type="text">
                </div>
            </div>
            <div class="field last-field">
                <div class="col col-left">
                    <label for="email">E-mail</label><br>
                    <input name="email" id="email" class="input-text" type="text">
                </div>
                <div class="col col-right">
                    <label for="phone">Phone or Skype</label><br>
                    <input name="phone" id="phone" class="input-text" type="text">
                </div>
            </div>
      	</fieldset>

        <fieldset>
            
            <h2>Additional Info / Message</h2>            
                        
            <div class="field">
                <label for="message">Please add a short message:</label><br>
                <textarea name="message" id="message" cols="50" rows="5"></textarea>
            </div>
            
            <div class="field last-field">
                    <p class="smallnote">Individuals, please include any injuries or preexisting physical conditions.
                     <br><br>
                    Companies, please include number of employees and days requested.</p>
                </div>
            

            
        </fieldset>    
        
        <fieldset id="button-fieldset">
            <label for="cc" class="label-check">
                <input class="input-check" name="cc" id="cc" value="1" checked="checked" type="checkbox"> Receive a copy of this message?
            </label>
            <input class="input-hidden" name="submited" value="1" type="hidden">        
            <input class="input-image" src="img/send-message.gif" alt=" [ send message ] " onmouseover="this.src='img/send-message-hover.gif';" onmouseout="this.src='img/send-message.gif';" onmousedown="this.src='img/send-message-active.gif';" type="image">
        </fieldset>
        
    </form>


 

The errors will appear ontop of your form.

i know. not explaining myself, i guess.

 

see how my divs are titled: div class="thankyou-message" and div class="error-message"

 

by errors or successful completion, depending on which, i'd like to trigger one div class or another on the same page as the contact form - right below:

 

<form id="contact-form"  method="post" action="/scripts/mailer2.php">

 

if that's not possible, i'd like to have separate pages for error messages.

 

thanks for your reply. you guys have been a big help as, currently, my form is up and running.

 

 

 

 

 

Not the best and haven't tested but I'm guessing you want something like the below.

Basically if any of the field is left blank then it'll show the div error message with the bullets. If it's not blank then it'll send the email. I'm sure the below can be coded in a different way better. It's a start.

 

   
    <form id="contact-form"  method="post" action="/scripts/mailer2.php">
        
        
        <fieldset>
            <h2>Your info</h2>
            <div class="field">
                <div class="col col-left">
                    <label for="name">Your name</label><br>
                    <input name="name" id="name" class="input-text" type="text">
                </div>
                <div class="col col-right">
                    <label for="company">Company or organization</label><br>
                    <input name="company" id="company" class="input-text" type="text">
                </div>
            </div>
            <div class="field last-field">
                <div class="col col-left">
                    <label for="email">E-mail</label><br>
                    <input name="email" id="email" class="input-text" type="text">
                </div>
                <div class="col col-right">
                    <label for="phone">Phone or Skype</label><br>
                    <input name="phone" id="phone" class="input-text" type="text">
                </div>
            </div>
      	</fieldset>

        <fieldset>
            
            <h2>Additional Info / Message</h2>            
                        
            <div class="field">
                <label for="message">Please add a short message:</label><br>
                <textarea name="message" id="message" cols="50" rows="5"></textarea>
            </div>
            
            <div class="field last-field">
                    <p class="smallnote">Individuals, please include any injuries or preexisting physical conditions.
                     <br><br>
                    Companies, please include number of employees and days requested.</p>
                </div>
            

            
        </fieldset>    
        
        <fieldset id="button-fieldset">
            <label for="cc" class="label-check">
                <input class="input-check" name="cc" id="cc" value="1" checked="checked" type="checkbox"> Receive a copy of this message?
            </label>
            <input class="input-hidden" name="submited" value="1" type="hidden">        
            <input class="input-image" src="img/send-message.gif" alt=" [ send message ] " onmouseover="this.src='img/send-message-hover.gif';" onmouseout="this.src='img/send-message.gif';" onmousedown="this.src='img/send-message-active.gif';" type="image">
        </fieldset>
        
    </form>
    
<?php
//If the form is POSTed, do the following
if($_SERVER['REQUEST_METHOD'] == 'POST') {

    //Get the POSTed data and store in the $ variables
   $name           = $_POST['name'];
   $company         = $_POST['company'];
   $email          = $_POST['email'];
   $phone          = $_POST['phone'];
   $message   = $_POST['message'];

//If any field is blank display error
if ( empty($name) || empty($company) || empty($email) || empty($phone) || empty($message) ) {
echo '<div class="error-message"><p>The message has <em>not been sent</em>. Could you please check the following:</p><ul>';

   	//If the name field is blank, retun the below error
   	if(!$name) 
   	{
   	echo "<li>Your name is missing</li>";
   	}
   	//If the organization field is blank, retun the below error
   	if(!$company) 
   	{
   	echo "<li>Your company/organization name is missing</li>";
   	}   
   	//If the email address field is blank, retun the below error
   	if(!$email) 
   	{
   	echo "<li>Your email is missing</li>";
   	}   
   	//If the email address entered appears to be of an incorrect format return the below error
   	elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
   	{ 
   	echo "<li>You must enter a valid email</li>";
   	}   
   	//If the phone number field is blank, retun the below error
   	if(!$phone) 
   	{
   	echo "<li>Please provide phone number or Skype username</li>";
   	}
   	//If the message field is blank, retun the below error
   	if(!$message) 
   	{
   	echo "<li>Please provide us with a short message</li>";
   	}         
echo '</ul></div>';

}
else { //No blanks

   $msg = "Full Name: $name\n\nCompany: $company\n\nEmail Address: $email\n\nPhone: $phone\n\nMessage: $message\n\n";
   mail("youremail@yourdomain.com", "Website Enquiry", $msg, "From: $name  <$email>");
   echo '<div class="thankyou-message"><p>Thanks for your message! I will get back to you soon.<br>Namaste</p></div>';

}

}
?>    

pneudralics. that's awesome.  :D

 

it doesn't give me styling. but, at least it's a start. definitely better than what i had before.

 

here's what i'm wondering. is there a way to get these messages to show up above the contact form, on the same page?

 

maybe using "display: none" on my div's and hiding them on the contact page where i'd like them to show up. would there be a way to trigger them to display through php?

 

that's what i'd like to accomplish.

 

either that, or i'd like to integrate styling into the mailer.php page, so it looks like the rest of my site.

 

again, thanks a million. we're definitely on the right track.

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.