1 Reply Latest reply on Aug 20, 2011 11:19 AM by garywpaul

    Html5 and php feeback form

    jpfcastella

      Hi Guys/gals

       

      Recently bought a template so i could start learning and create my first site, but i have come stuck on the Feeback form.

      I know how to get introduce the mailto: code to send email, but what i really want is a php code to do it for me. here is what i have so far.

       

      Form Code:

       

      <form id="ContactForm" action="mailto:email@person.com" method="post">
                  <div>
                   <label><span class="input"><input type="text" value="Name:" onBlur="if(this.value=='') this.value='Name:'" onFocus="if(this.value =='Name:' ) this.value=''" /></span></label>
                   <label><span class="input"><input type="text" value="E-mail:" onBlur="if(this.value=='') this.value='E-mail:'" onFocus="if(this.value =='E-mail:' ) this.value=''" /></span></label>
                   <label><span class="input"><input type="text" value="Subject:" onBlur="if(this.value=='') this.value='Subject:'" onFocus="if(this.value =='Your Country:' ) this.value=''" /></span></label>
                   <span class="textarea"><textarea onBlur="if(this.value=='') this.value='Your Message:'" onFocus="if(this.value =='Your Message:' ) this.value=''"  >Your Message:</textarea></span>
                  </div>
                  <div class="alignright">
                   <a href="#" class="link" onClick="document.getElementById('ContactForm').reset()"><span><span>clear</span></span>< /a>
                   <a href="#" class="link" onClick="document.getElementById('ContactForm').submit()"><span><span>send</span></span>< /a>
                  </div>
                 </form>

       

      And here is my PHP:

       

      <?php
      function spamcheck($field)
        {
        //filter_var() sanitizes the e-mail
        //address using FILTER_SANITIZE_EMAIL
        $field=filter_var($field, FILTER_SANITIZE_EMAIL);

        //filter_var() validates the e-mail
        //address using FILTER_VALIDATE_EMAIL
        if(filter_var($field, FILTER_VALIDATE_EMAIL))
          {
          return TRUE;
          }
        else
          {
          return FALSE;
          }
        }

      if (isset($_REQUEST['email']))
        {//if "email" is filled out, proceed

        //check if the email address is invalid
        $mailcheck = spamcheck($_REQUEST['email']);
        if ($mailcheck==FALSE)
          {
          echo "Invalid input";
          }
        else
          {//send email
      $name = $_REQUEST['name'] ;
          $email = $_REQUEST['email'] ;
          $subject = $_REQUEST['subject'] ;
          $message = $_REQUEST['message'] ;
          mail("email@person.com", "Subject: $subject",
          $message, "From: $email" );
          echo "Thank you for using our mail form";
          }
        }
      else
        {//if "email" is not filled out, display the form
        echo "<form method='post' action='mailform.php'>
        Email: <input name='email' type='text' /><br />
        Subject: <input name='subject' type='text' /><br />
        Message:<br />
        <textarea name='message' rows='15' cols='40'>
        </textarea><br />
        <input type='submit' />
        </form>";
        }
      ?>

       

      Can someone plase let me know where i am going wrong.

       

      Thanx in advance.

       

      Pedro

        • 1. Re: Html5 and php feeback form
          garywpaul Level 5

          In your action, it should not be action="mailto:email@person.com", it should be the name of the processing file.  So if your php is on a page name process.php, then the action would be action="process.php", if it is in a different folder you will have to show the path to it.

           

          You can process the form all on one page, but if you are just learing, it is better to create a second page, once you get the bugs worked out and have a better understanding, you can change it to just one page is you prefer.

           

          See if that helps

           

          Gary