Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Contact Page assistance
Old 02-22-2009, 11:33 AM Contact Page assistance
Madman340's Avatar
Web Designer

Posts: 571
Name: Jared
Location: Florida
Trades: 1
Hey there, my friend has helped me with my contact page thus far, but he hasn't been on in a long time and I need to get this done. I have the contact page done, can send emails and I receive them, but I want it to show specific messages depending on if they filled out all the fields or not.

If you can help me please talk to me on MSN or AIM


MSN Jaredrainman@msn.com
AIM Madman34o


I find it far too time consuming when trying to solve problems via forum posts.
__________________

Please login or register to view this content. Registration is FREE
for cheap hosting solutions.
Use the coupon code "SINGLECENT" to pay just a single cent for the first month!
Madman340 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-22-2009, 12:17 PM Re: Contact Page assistance
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
You can do it using JavaScript if you would like but I always use PHP for this. Just set the action of the form to the same page. For example action="contact.php". Then at the top of your page see if the form isset and if it is then verify. Use a flag throughout this process. At the beginning you have $flag=0; and then as you error check if their is a problem set the flag=1. Then at the end, if $flag=0 then send it, otherwise display your error message and have them fix the contact page.
__________________
DVD Movie Release Database:
Please login or register to view this content. Registration is FREE
Truly is offline
Reply With Quote
View Public Profile
 
Old 02-22-2009, 12:38 PM Re: Contact Page assistance
GhettoFish's Avatar
Average Talker

Posts: 24
Name: Martin Söderberg
Trades: 0
Hey man!

I just made a "Contact Us" page myself just a couple of days ago. Currently I am having trouble with getting the error messages to print out, but I think i have the general idea of how to tackle this.

I do this with PHP and different attributes that i can pull up with PHP to check what has happend.

First I have this in contact.php
Code:
<?PHP
    if(isset($_REQUEST['mailsent'])){
        $value = $_REQUEST['mailsent'];
        if($value == "true"){
            $message = "<h3>Your E-Mail has now been sent</h3>";
        }
    }
    if(isset($_REQIEST['mailsent']) && isset($_REQUEST['reason'])){
        $reason = $_REQUEST['reason'];
        $value = $_REQUEST['mailsent'];
        echo $reason . ', ' . $value . 'Works?';
        if($value == "false" && $reason == "1"){
            $message = "<h3>No E-Mail added.</h3>";
        }elseif($value == "false" && $reason == "2"){
            $message = "<h3>Bad E-Mail : Incorrect structure.</h3>";
        }elseif($value == "false" && $reason == "3"){
            $message = "<h3>Bad E-Mail : Incorrect domain.</h3>";
        }else{
            $message = "<h3>Invalid value returned from server. #423</h3>";
        }
    }
    if(!isset($_REQIEST['mailsent'])) {
        $contactmsg = "<h5>Contact Process</h5>
        <p>
            At the moment this page is locked for public. If you want to become a member at this page you will need to e-mail us an application. 
            This should consist of some information about yourself, what knowledge you possess and in which fields as well as why you want to become a member.
        </p><p>
            Please free to read through our EULA and ToS for further information on what we might be able to offer you. 
            The information you send us will be treated as private and not passed along to anyone else.
        </p><p>
            Have a nice day!
        </p>";        
        echo $contactmsg;
    }
    if(isset($message)){ echo $message; } 
?>
<form action="send.php" method="post">
    <div class="req"><label for="nameinput">Name:</label>*</div>
    <input type="text" tabindex="1" id="nameinput" name="nameinput" class="textinput" /><br />
    <div class="req"><label for="emailinput">E-Mail:</label>*</div>
    <input type="text" tabindex="2" id="emailinput" name="emailinput" class="textinput" /><br />
    <div class="req"><label for="subjectinput">Subject:</label>*</div>
    <input type="text" tabindex="3" id="subjectinput" name="subjectinput" class="textinput" /><br />
    <br />

    <div class="req"><label for="messageinput">Message:</label>*</div>
    <textarea id="messageinput" tabindex="4" name="messageinput" class="textarea"></textarea><br />
    <br />
    <input type="submit" id="submit" name="submit" tabindex="5"  value="Submit" class="buttonSubmit" />
    <div id="stylesheetTest"></div>
</form>
The form at the bottom send the info from the form to send.php
Code:
<?PHP

    //////////////////////////////////////
    // Code to send E-Mail through form //
    //////////////////////////////////////    
    
    // Include correct files
    include('includes/functions.php');
    include('includes/globals.php');
                
    if(isset($_POST['submit'])){
        // Assign variables to forms
        $to = "info@waah.eu";
        $from = $_POST['emailinput'];
        $name = $_POST['nameinput'];

        $subject = "Hallux :: " . $_POST['subjectinput'];
        $message = $_POST['messageinput'];
        $headers = "From: $name <$from>";
        
        // Check if the e-mail is correct.
        $verify = verify($from);
        if($verify == -1){
            header ("Location: " . $mailsent . "&mailsent=false&reason=1");
        }elseif($verify == -2){
            header ("Location: " . $mailsent . "&mailsent=false&reason=2");
        }elseif($verify == -3){
            header ("Location: " . $mailsent . "&mailsent=false&reason=3");
        }elseif($verify == -0){
            mail($to,$subject,$message,$headers);
            header ("Location: " . $mailsent . "&mailsent=true");
        }
    }else{
        echo 'Not sent correctly';
    }

?>
the verify() function checks if the field "E-Mail" is correctly filled in and if not returns a error value from -1 to -3 and 0 if the E-Mail is valid.

Here is the verify()-function
Code:
<?PHP
function verify($email){
    
    // If no e-mail address is inputted to begin with the user will get an error message.
    if(!isset($email)){
        // Return incorrect e-mail to main site.
        return -1;
    }
    
    // Check so the e-mail uses allowed chars and correct structure.
    // If match not made it sends user back to form.
    if (!preg_match('/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/i', $email)){
        // Return incorrect e-mail to main site.
        return -2;
    }
    
    // Grab the domain from the e-mail adress.
    $domain = strstr($email, '@');
    $domain = substr($domain, 1); // Shifts selection by one so not @ is added with the domain.
    
    // Checks that the domain is resolved to an IP. 
    // If hostname isn't resolved to and IP user is sent back to form.
    if (!ip2long(gethostbyname($domain))){
        // Return incorrect e-mail to main site.
        return -3;
    }
    
    // It passed all the tests, hurrah for us!
    return 0;
}
?>
Depending on what value is returned it later echoes the message in contact.php... this should work, atm it doesn't, but I think i will find the error soon enough

Hope this helps you!
__________________
“It is better to create than to be learned, creating is the true essence of life”
- Barthold Georg Niebuhr

Please login or register to view this content. Registration is FREE
GhettoFish is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Contact Page assistance
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13704 seconds with 12 queries