Making a "Contact Us" Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AricC
    Recognized Expert Top Contributor
    • Oct 2006
    • 1885

    #16
    Post the page minus the php we gave you and we will re-post it with the correct code.

    Aric

    Comment

    • popnbrown
      New Member
      • Oct 2006
      • 24

      #17
      this is the original code w/o
      my form itself

      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
      <head>
      <title>Codetuts-CppInquiry</title>
      <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
      <meta name="description" content="Your description goes here." />
      <meta name="keywords" content="your,keywords,goes,here" />
      <meta name="author" content="Brett Hillesheim" />
      <link rel="stylesheet" href="css.css" type="text/css" media="screen" />
      <link href="/contact.css" rel="stylesheet" type="text/css" media="screen" />
      </head>
      
      <body>
      <div id="container">
      <div id="sitename">
      <h1>Codetuts-CppInquiry</h1>
      
      </div>
      
      <div class="tabsF" id="tabsF" dir="ltr" lang="en" onclick="http://www.codetuts.com
      ">
        <ul>
          <li><a href="index.html" title="CppInquiry"><span>Home</span></a></li>
          <li><a href="programs.html" title="Programs/Source"><span>Programs/Source</span></a></li>
          <li><a href="construction.html" title="Tutorials"><span>Tutorials</span></a></li>
          <li><a href="construction.html" title="Articles"><span>Articles</span></a></li>
      
          <li><a href="construction.html" title="Forum"><span>Forum</span></a></li>
          <li><a href="http://www.codetuts.com" title="Codetuts.com"><span>Codetuts</span></a></li>
      	<li class="linklist"><a href="construction.html" title="Archives"><span>Archives </span></a></li>
      	<li><a href="#" title="Contact Us"><span>Contact Us</span></a></li>
          </ul>
      </div>
       
      <div #tabsf>
        <ul>
          <il>
          <a> <span></span></a>
        </ul>
      </div>
      <div id="wrap">
      <br/><br/>
      <div id="rightside">
      <h1>Links</h1>
      <ul class="linklist">
      <li><a href="http://www.omnamo.com">Omnamo</a></li>
      <li><a href="construction.html">Gallery</a></li>
      <li><a href="construction.html">Affiliates</a></li>
      
      <li><a href="http://oswd.org">OSWD.org</a></li>
      </ul>
      
      
      <h1>&nbsp;</h1>
      
      <h1>Latest Announcements</h1>
      
      <div id="scroll2">
        <p><strong>Year of 2006 </strong></p>
        <p><strong>Dec.11: </strong>Creation of Codetuts-Sravan ftp site</p>
        <p><strong>Dec.13: </strong>First uploading of the site's layout thanks to Brett7481</p>
        <p><strong>Dec. 15:</strong> Change of name to CppInquiry </p>
        <p><strong>Dec. 16: </strong>Programs/Source section is up</p>
        <p><strong>Dec. 16: </strong>Created "Under Constructions" pages for CppInquiry</p>
      </div>
      <h1>&nbsp;</h1>
      </div>
      <div id="contentalt" >
        <div id="scroll">
      
      </div>
      <p>&nbsp;</p>
      </div>
      
      <div class="clearingdiv">&nbsp;</div>
      </div>
      
      <div id="footer">@2006 Codetuts-CppInquiry| Design by <a href="http://www.ibentmywookie.org">Brett7481</a></div>
      </div>
      </body>
      </html>

      Comment

      • popnbrown
        New Member
        • Oct 2006
        • 24

        #18
        I need the form in the part where it says

        [HTML]<div id="contenalt" >
        <div id="scroll2">

        </div>
        <p>&nbsp;</p>
        </div>[/HTML]

        Comment

        • AricC
          Recognized Expert Top Contributor
          • Oct 2006
          • 1885

          #19
          Originally posted by popnbrown
          I need the form in the part where it says

          [HTML]<div id="contenalt" >
          <div id="scroll2">

          </div>
          <p>&nbsp;</p>
          </div>[/HTML]
          Inbetween the paragraph tags?

          Comment

          • popnbrown
            New Member
            • Oct 2006
            • 24

            #20
            no between the div tags.
            the div tags make like a scrollbox for the main content. I would like it there.

            Thnks a ton

            Comment

            • AricC
              Recognized Expert Top Contributor
              • Oct 2006
              • 1885

              #21
              I don't have your style sheet but try this:
              Code:
              <?php
              ##################################################  ###############################
              #
              # mail.php - general-purpose email form and script
              #
              # copyright June 2005 by Charles Reace
              #
              # This software available as open source software under the Gnu General Public
              # License: http://www.gnu.org/licenses/gpl.html
              #
              ##################################################  ##############################
              ##################################################  ##############################
              # user-defined variables - update for your email address(es) ##################################################  ##############################
              # home page for link at top of page:
              $home = "http://www.yourdomain.com/";
              # Modify the following variables to set up where emails will be sent.
              # $toName will be concatenated with a "@" and then $toDomain to create
              # the complete email address.
              $toName   = "johndoe";         # the part that goes before the @
              $toDomain = "yourdomain.com";  # the part that comes after the @
              # uncomment and edit the next two lines if you want to cc someone:
              $ccName   = "ccname";
              $ccDomain = "ccdomain.com";
              # uncomment and edit the next two lines if you want to bcc someone:
              $bccName   = "bccname";
              $bccDomain = "bccdomain.com";
              #################################
              # end of user-defined variables 
              ##################################
              # email address validation function
              # kudos to http://iamcal.com/publish/articles/php/parsing_email/pdf/
              function is_valid_email_address($email) {  
                $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';  
                $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';  
                $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
                        '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';  
                $quoted_pair = '\\x5c\\x00-\\x7f';  
                $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";  
                $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";  
                $domain_ref = $atom;  
                $sub_domain = "($domain_ref|$domain_literal)";  
                $word = "($atom|$quoted_string)";  
                $domain = "$sub_domain(\\x2e$sub_domain)*";  
                $local_part = "$word(\\x2e$word)*";  
                $addr_spec = "$local_part\\x40$domain";  
                return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
              }
              # Init. some variables:
              $error = "";
              $success = FALSE;
              
              # process form if submitted:
              if(isset($_POST['submit'])){
                foreach($_POST as $key => $val)  {
                    if (empty($_POST[$key]))    {
                       $error .= "You must enter a value for " .
                                  ucwords(str_replace("_"," ",$key)) . ". ";
                    }    
                    else  { 
                       if(get_magic_quotes_gpc())      {
                            $_POST[$key] = stripslashes($val);      
                       }    
                    }    
                    if($key != 'message')    {
                       $_POST[$key] = preg_replace('/[\r\n]/', ' ', $val);
                    }  
                }  
                if($_POST['email_address'] != $_POST['repeat_email'])  {
                  $error .= "Email Address is not the same as Repeat Email. ";  
                }  
                elseif(is_valid_email_address($_POST['email_address']) == 0)  {
                  $error .= "'{$_POST['email_address']}' does not appear to be a valid email address. "; 
                }  
                if(empty($error))  # no errors in input, so go ahead and email it.  
                {
                  $to = "$toName@$toDomain";
                  $headers = "From: ".preg_replace('/[\r\n]+/',' ', $_POST['email_address']);
                  if(!empty($ccName) and !empty($ccDomain))    {
                    $headers .= "\r\nCc: $ccName@$ccDomain";
                  }
                  if(!empty($bccName) and !empty($bccDomain))    {
                    $headers .= "\r\nBcc: $bccName@$bccDomain\r\n\r\n";    
                  }    
                  $headers .= "\r\nX-Mailer: PHP/" . phpversion();
                  $msg = "From {$_POST['name']} ({$_POST['email_address']})";
                  $msg .= "\n\n\n{$_POST['message']}";
                  echo "<pre>$headers"; exit;
                  $result = @mail($to,
                                  stripslashes($_POST['subject']),
                                  $msg,
                                  $headers);
                  if(!$result)    {
                    $error = "There was an unknown error while attempting to send your email.";
                  }
                  else    {
                    header("Location: http://www.charles-reace.com/Email_Me/thanks.php");
                  }
                }
              }
              ?>
              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
              "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
              <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
              <head>
              <title>Codetuts-CppInquiry</title>
              <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
              <meta name="description" content="Your description goes here." />
              <meta name="keywords" content="your,keywords,goes,here" />
              <meta name="author" content="Brett Hillesheim" />
              <link rel="stylesheet" href="css.css" type="text/css" media="screen" />
              <link href="/contact.css" rel="stylesheet" type="text/css" media="screen" />
              </head>
              
              <body>
              <div id="container">
              <div id="sitename">
              <h1>Codetuts-CppInquiry</h1>
              
              </div>
              
              <div class="tabsF" id="tabsF" dir="ltr" lang="en" onclick="http://www.codetuts.com
              ">
                <ul>
                  <li><a href="index.html" title="CppInquiry"><span>Home</span></a></li>
                  <li><a href="programs.html" title="Programs/Source"><span>Programs/Source</span></a></li>
                  <li><a href="construction.html" title="Tutorials"><span>Tutorials</span></a></li>
                  <li><a href="construction.html" title="Articles"><span>Articles</span></a></li>
              
                  <li><a href="construction.html" title="Forum"><span>Forum</span></a></li>
                  <li><a href="http://www.codetuts.com" title="Codetuts.com"><span>Codetuts</span></a></li>
              	<li class="linklist"><a href="construction.html" title="Archives"><span>Archives </span></a></li>
              	<li><a href="#" title="Contact Us"><span>Contact Us</span></a></li>
                  </ul>
              </div>
               
              <div #tabsf>
                <ul>
                  <il>
                  <a> <span></span></a>
                </ul>
              </div>
              <div id="wrap">
              <br/><br/>
              <div id="rightside">
              <h1>Links</h1>
              <ul class="linklist">
              <li><a href="http://www.omnamo.com">Omnamo</a></li>
              <li><a href="construction.html">Gallery</a></li>
              <li><a href="construction.html">Affiliates</a></li>
              
              <li><a href="http://oswd.org">OSWD.org</a></li>
              </ul>
              
              
              <h1>&nbsp;</h1>
              
              <h1>Latest Announcements</h1>
              
              <div id="scroll2">
                <p><strong>Year of 2006 </strong></p>
                <p><strong>Dec.11: </strong>Creation of Codetuts-Sravan ftp site</p>
                <p><strong>Dec.13: </strong>First uploading of the site's layout thanks to Brett7481</p>
                <p><strong>Dec. 15:</strong> Change of name to CppInquiry </p>
                <p><strong>Dec. 16: </strong>Programs/Source section is up</p>
                <p><strong>Dec. 16: </strong>Created "Under Constructions" pages for CppInquiry</p>
              </div>
              <h1>&nbsp;</h1>
              </div>
              <div id="contentalt" >
                <div id="scroll">
              
              <h2>Email Me</h2>
              <form action='<?php echo $_SERVER['PHP_SELF'] ?>' method=post>
              <fieldset>
              <legend>Your Contact Information</legend>
              <p><label for='name' class='lab'>Name:</label>
              <input type='text' name='name' id='name' size='30' maxlength='40'<?php
              if(!empty($_POST['name'])){  
                echo "value='{$_POST['name']}'";
              }
              ?>></p>
              <p><label for='email_address' class='lab'>Email Address:</label>
              <input type='text' name='email_address' id='email_address' size='30' maxlength='40'<?php
              if(!empty($_POST['email_address'])){  
                echo "value='{$_POST['email_address']}'";
              }
              ?>></p>
              <p><label for='repeat_email' class='lab'>Repeat Email:</label>
              <input type='text' name='repeat_email' id='repeat_email' size='30' maxlength='40'<?php
              if(!empty($_POST['repeat_email'])) {  
                echo "value='{$_POST['repeat_email']}'";
              }
              ?>></p>
              </fieldset>
              <p> </p>
              <fieldset>
              <legend>Message</legend>
              <p><label for='subject' style="margin-left:3px;display: block; float: left; width: 9em;">Subject:</label>
              <input type='text' name='subject' id='subject' size='50' maxlength='60'<?php
              if(!empty($_POST['subject'])){  
                echo " value='{$_POST['subject']}'";
              }
              ?>></p>
              <p><label for='message' style="margin-left:3px;display: block; float: left; width: 9em;">Message:</label>
              <textarea name='message' id='message' cols='50' rows='8'
              style="width: 375px"><?php
              if(!empty($_POST['message'])){  
                echo $_POST['message'];
              }
              ?></textarea></p>
              <p style="text-align: center;"><input type='submit' name='submit' value="Send Email"></p>
              </fieldset>
              </form>
              
              
              
              
              </div>
              <p>&nbsp;</p>
              </div>
              
              <div class="clearingdiv">&nbsp;</div>
              </div>
              
              <div id="footer">@2006 Codetuts-CppInquiry| Design by <a href="http://www.ibentmywookie.org">Brett7481</a></div>
              </div>
              </body>
              </html>
              Also you need to read the script there is information that you need to fill out in there like your email address.

              Comment

              • CMK
                New Member
                • Dec 2006
                • 1

                #22
                There are a number of ways of doing this i.e. server side and client side. The suggestion below is client side using Javascript, this way you won't need a server to test it out, although you will for the second of your queries(some on to that later).

                Right number 1: validating the form. You want to generate a pop up window when a user has not filled in a particular field. This is Javascript.

                Here's what you do.
                In the html change method="put" to "post"
                <form method="post" id="contact" onsubmit="retur n checkall(this); " action="i'll come onto this later">

                It's easiest to stick this your html rather than a separate file. In the 'Head' section use this.

                <script type="text/javascript">

                function checkall(contac t)
                {
                if (contact.name.v alue == "")
                {
                alert("You must enter a name");
                return (false);
                }

                if (contact.subjec t.value == "")
                {
                alert("You must enter your address");
                return (false);
                }


                }
                </script>

                The code explained: 'function checkall(contac t)' goes through the form validating whatever you have asked it to, in this script i.e. the name and subject fields.

                'if (contact.name.v alue == "")' This says "if the contact form where the value of the field name is blank then print out the error message - which can say anything you want it to, if the fields are not blank then allow the form to be processed"

                Number 2. This is where it gets a little more involved

                In order to send the form, you'll need to use a 'sever side' language, in other words first of all you need to install a server. The server you use will depend upon which laguage you want to use to process the email. One such language is PHP, so rather than go through all the possibilities i'll stick to, how to do it using PHP.

                PHP can be run on one of two servers, Apache or IIS.

                The PHP code used to send the email

                <?php
                //these 'extract' the information written by the user from the name and subject fields
                $name = $_REQUEST['name'] ;
                $subject = $_REQUEST['subject'] ;

                //sets the email address to send message from
                ini_set("sendma il_from","the-email-address-you-want-to-use-to-send-the-email-from");

                //takes the form "to-email address", "subject of the email", "then takes the 'subject and name' from the form"
                mail("youremail addressagain", "subject of message-Here's hoping this arrives, Fingers crossed!", "Comment:$subje ct", "From: $name");

                //a little thankyou message
                echo "A thankyou message-thankyou for message-or something";
                ?>

                The backslashes are used as comments in the code and do not get processed.

                Hope that helps! This is simple really, might not look it though.

                Comment

                • popnbrown
                  New Member
                  • Oct 2006
                  • 24

                  #23
                  wtf its not workin. I dont know what I'm doing wrong.

                  But anyways thanks and just want to point out that
                  when you go to the page cppinquiry.code tuts.com/contact.html
                  it starts to show some of the code starting from "$val"

                  So any suggesstions.

                  Comment

                  • popnbrown
                    New Member
                    • Oct 2006
                    • 24

                    #24
                    [QUOTE=CMK]There are a number of ways of doing this i.e. server side and client side. The suggestion below is client side using Javascript, this way you won't need a server to test it out, although you will for the second of your queries(some on to that later).

                    Right number 1: validating the form. You want to generate a pop up window when a user has not filled in a particular field. This is Javascript.

                    Here's what you do.
                    In the html change method="put" to "post"
                    <form method="post" id="contact" onsubmit="retur n checkall(this); " action="i'll come onto this later">

                    It's easiest to stick this your html rather than a separate file. In the 'Head' section use this.

                    <script type="text/javascript">

                    function checkall(contac t)
                    {
                    if (contact.name.v alue == "")
                    {
                    alert("You must enter a name");
                    return (false);
                    }

                    if (contact.subjec t.value == "")
                    {
                    alert("You must enter your address");
                    return (false);
                    }


                    }
                    </script>

                    QUOTE]


                    Ok first things first how does the computer know when to display the alert message and is "alert();" already defined somewhere (over the rainbow)!
                    And also can you explain "action" in the <form...>

                    Comment

                    • popnbrown
                      New Member
                      • Oct 2006
                      • 24

                      #25
                      Originally posted by CMK
                      Number 2. This is where it gets a little more involved

                      In order to send the form, you'll need to use a 'sever side' language, in other words first of all you need to install a server. The server you use will depend upon which laguage you want to use to process the email. One such language is PHP, so rather than go through all the possibilities i'll stick to, how to do it using PHP.

                      PHP can be run on one of two servers, Apache or IIS.

                      The PHP code used to send the email

                      <?php
                      //these 'extract' the information written by the user from the name and subject fields
                      $name = $_REQUEST['name'] ;
                      $subject = $_REQUEST['subject'] ;

                      //sets the email address to send message from
                      ini_set("sendma il_from","the-email-address-you-want-to-use-to-send-the-email-from");

                      //takes the form "to-email address", "subject of the email", "then takes the 'subject and name' from the form"
                      mail("youremail addressagain", "subject of message-Here's hoping this arrives, Fingers crossed!", "Comment:$subje ct", "From: $name");

                      //a little thankyou message
                      echo "A thankyou message-thankyou for message-or something";
                      ?>

                      The backslashes are used as comments in the code and do not get processed.

                      Hope that helps! This is simple really, might not look it though.
                      Now on to number too, are all those functions already defined (i.e ini_set(), mail())
                      Also what do the functions do, and what are the arguements according to my form(below) and my e-mail address "cppinquiry@cod etuts.com"
                      [HTML]
                      <form method="post" id="contact" onsubmit="retur n checkall(this); " action="i'll come onto this later">
                      <label>Name: </label>
                      <p>
                      <input type="text" name="name" tabindex="1" class="ina"/>
                      </p>
                      <label>E-mail: </label>
                      <p>
                      <input type="text" name="email" tabindex="2" />
                      </p>
                      <label>Subject: </label>
                      <p>
                      <input type="text" name="subject" tabindex="3" />
                      </p>
                      <label>Messag e:
                      <p>
                      <textarea name="message"> </textarea>
                      </p>
                      </label>
                      <p>
                      <input type="submit" name="Submit" value="Submit" tabindex="5" />
                      </p>
                      </form>
                      [/HTML]

                      heheh I stole ur form declaration heheheh

                      thanks for ur help
                      ill put ur name if u want in comments on this page, if you can help me with this goal
                      Last edited by popnbrown; Dec 22 '06, 11:10 PM. Reason: cause

                      Comment

                      • AricC
                        Recognized Expert Top Contributor
                        • Oct 2006
                        • 1885

                        #26
                        popnbrown are you still having problems with this?

                        Comment

                        Working...