[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/plugins/ -> function.contact_form.php (source)

   1  <?php
   2  
   3  # CMSMS - CMS Made Simple
   4  #
   5  # (c)2004 by Ted Kulp (wishy@users.sf.net)
   6  #
   7  # This project's homepage is: http://cmsmadesimple.org
   8  #
   9  # This program is free software; you can redistribute it and/or modify
  10  # it under the terms of the GNU General Public License as published by
  11  # the Free Software Foundation; either version 2 of the License, or
  12  # (at your option) any later version.
  13  #
  14  # This program is distributed in the hope that it will be useful,
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17  # GNU General Public License for more details.
  18  # You should have received a copy of the GNU General Public License
  19  # along with this program; if not, write to the Free Software
  20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21  
  22  function smarty_cms_function_contact_form($params, &$smarty) {
  23  
  24      global $gCms;
  25  
  26      if (FALSE == empty($params['captcha']) && $params['captcha'] && isset($gCms->modules['Captcha'])) 
  27      {
  28          $captcha =& $gCms->modules['Captcha']['object'];
  29      }
  30  
  31      if (empty($params['email'])){
  32          echo '<div class="formError">An email address must be specified in order to use this plugin.</div>';
  33          return;
  34      }else{
  35          $to = $params['email'];
  36      }
  37      
  38      $style = true; // Use default styles
  39      if (FALSE == empty($params['style']) && $params['style'] === "false" ) $style = false; // Except if "false" given in params
  40      
  41      // Default styles
  42      $inputStyle = 'style="width:100%;border: 1px solid black; margin:0 0 1em 0;"'; // input boxes
  43      $taStyle = 'style="width:100%; border: 1px solid black; margin:0 0 1em 0;"'; // TextArea boxes
  44      $formStyle = 'style="width:30em; important; font-weight: bold;"'; // form
  45      $errorsStyle = 'style="color: white; background-color: red; font-weight: bold; border: 3px solid black; margin: 1em;"'; // Errors box (div)
  46          $labelStyle = 'style="display:block;"';
  47          $buttonStyle = 'style="float:left; width:50%;"';
  48          $fieldsetStyle = 'style="padding:1em;"';
  49          $captchaStyle = 'style="margin-bottom:1em; text-align: center;"';
  50  
  51      $errors=$name=$email=$subject=$message = '';
  52      if (FALSE == empty($params['subject_get_var']) && FALSE == empty($_GET[$params['subject_get_var']]))
  53        {
  54          $subject = $_GET[$params['subject_get_var']];
  55        }
  56      if($_SERVER['REQUEST_METHOD']=='POST'){
  57          if (!empty($_POST['name'])) $name = cfSanitize($_POST['name']);
  58          if (!empty($_POST['email'])) $email = cfSanitize($_POST['email']);
  59          if (!empty($_POST['subject'])) $subject = cfSanitize($_POST['subject']);
  60          if (!empty($_POST['message'])) $message = $_POST['message'];
  61          
  62          if (FALSE == empty($params['captcha']) && $params['captcha'] && isset($gCms->modules['Captcha'])) 
  63          {
  64              if (!empty($_POST['captcha_resp'])) { $captcha_resp = $_POST['captcha_resp']; }
  65          }
  66  
  67          //Mail headers
  68          $extra = "From: $name <$email>\r\n";
  69          $charset = isset($gCms->config['default_encoding']) && $gCms->config['default_encoding'] != '' ? $gCms->config['default_encoding'] : 'utf-8';
  70          $extra .= "Content-Type: text/plain; charset=" . $charset . "\r\n";
  71          
  72          if (empty($name)) $errors .= "\t\t<li>" . 'Please Enter Your Name' . "</li>\n";
  73          if (empty($email)) $errors .= "\t\t<li>" . 'Please Enter Your Email Address' . "</li>\n";
  74          elseif (!validEmail($email)) $errors .= "\t\t<li>" . 'Your Email Address is Not Valid' . "</li>\n";
  75          if (empty($subject)) $errors .= "\t\t<li>" . 'Please Enter a Subject' . "</li>\n";
  76          if (empty($message)) $errors .= "\t\t<li>" . 'Please Enter a Message' . "</li>\n";
  77          if (FALSE == empty($params['captcha']) && $params['captcha'] && isset($gCms->modules['Captcha']))
  78          {
  79              if (empty($captcha_resp)) $errors .= "\t\t<li>" . 'Please enter the text in the image' . "</li>\n";
  80              elseif (! ($captcha->checkCaptcha($captcha_resp))) $errors .= "\t\t<li>" . 'The text from the image was not entered correctly' . "</li>\n";
  81          }
  82          
  83          if (!empty($errors)) {
  84              echo '<div class="formError" ' . (($style) ? $errorsStyle:'') . '>' . "\n";
  85              echo '<p>Error(s) : </p>' . "\n";
  86              echo "\t<ul>\n";
  87              echo $errors;
  88              echo "\t</ul>\n";
  89              echo "</div>";
  90          }
  91          elseif (@mail($to, $subject, $message, $extra)) {
  92              echo '<div class="formMessage">Your message was successfully sent.</div>' . "\n";
  93              return;
  94          }
  95          else {
  96              echo '<div class="formError" ' . (($style) ? $errorsStyle:'') . '>Sorry, the message was not sent. The server may be down!</div>' . "\n";
  97              return;
  98          }
  99      }
 100  
 101      if (isset($_SERVER['REQUEST_URI'])) 
 102      {
 103      $action = $_SERVER['REQUEST_URI'];
 104      }
 105      else
 106      {
 107      $action = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
 108      if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') 
 109      {
 110          $action .= '?'.$_SERVER['QUERY_STRING'];
 111      }
 112      }
 113  ?>
 114  
 115      <!-- CONTACT_FORM -->
 116      <form action="<?php echo $action ?>" method="post" <?php echo ($style) ? $formStyle:''; ?>>
 117                   <fieldset <?php echo ($style) ? $fieldsetStyle:''; ?>>
 118                          <legend>Contact</legend>
 119              <label for="name" <?php echo ($style) ? $labelStyle:''; ?> >Your name :</label>
 120              <input type="text" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" <?php echo ($style) ? $inputStyle:''; ?>/>
 121  
 122              <label for="email" <?php echo ($style) ? $labelStyle:''; ?> >Your email address : </label>
 123              <input type="text" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" <?php echo ($style) ? $inputStyle:''; ?>/>
 124  
 125              <label for="subject" <?php echo ($style) ? $labelStyle:''; ?> >Subject : </label>
 126              <input type="text" id="subject" name="subject" value="<?php echo htmlspecialchars($subject); ?>" <?php echo ($style) ? $inputStyle:''; ?>/>
 127  
 128              <label for="message" <?php echo ($style) ? $labelStyle:''; ?> >Message : </label>
 129              <textarea id="message" name="message" rows="12" cols="48" <?php echo ($style) ? $taStyle:''; ?>><?php echo $message; ?></textarea>
 130  
 131  <?php
 132  if (FALSE == empty($params['captcha']) && $params['captcha'] && isset($gCms->modules['Captcha'])) 
 133  {
 134  ?>
 135              <label for="captcha_resp" <?php echo ($style) ? $labelStyle:''; ?> >Enter the text from the image below : </label>
 136              <input type="text" id="captcha_resp" name="captcha_resp" value="" <?php echo ($style) ? $inputStyle:''; ?>/>
 137  
 138  <?php
 139      echo "<div $captchaStyle>" . $captcha->getCaptcha() . '</div>';
 140  }
 141  ?>
 142  
 143                  <input type="submit" class="button" value="Submit" <?php echo ($style) ? $buttonStyle: ''; ?> /> 
 144                          <input type="reset"  class="button" value="Clear" <?php echo ($style) ? $buttonStyle: ''; ?> />
 145                   </fieldset>
 146      </form>
 147      <!-- END of CONTACT_FORM -->
 148  
 149  <?php
 150  }
 151  
 152  function smarty_cms_help_function_contact_form() {
 153      ?>
 154      <h3>What does this do?</h3>
 155      <p>Display's a contact form. This can be used to allow others to send an email message to the address specified.</p>
 156      <h3>How do I use it?</h3>
 157      <p>Just insert the tag into your template/page like: <code>{contact_form email="yourname@yourdomain.com"}</code><br>
 158      <br>
 159      If you would like to send an email to multiple adresses, seperate each address with a comma.</p>
 160      <h3>What parameters does it take?</h3>
 161      <ul>
 162          <li>email - The email address that the message will be sent to.</li>
 163          <li><em>(optional)</em>style - true/false, use the predefined styles. Default is true.</li>
 164          <li><em>(optional)</em>subject_get_var - string, allows you to specify which _GET var to use as the default value for subject.
 165                 <p>Example:</p>
 166                 <pre>{contact_form email="yourname@yourdomain.com" subject_get_var="subject"}</pre>
 167               <p>Then call the page with the form on it like this: /index.php?page=contact&subject=test+subject</p>
 168               <p>And the following will appear in the "Subject" box: "test subject"
 169             </li>
 170          <li><em>(optional)</em>captcha - true/false, use Captcha response test (Captcha module must be installed). Default is false.</li>
 171      </ul>
 172      </p>
 173      <?php
 174  }
 175  
 176  function smarty_cms_about_function_contact_form() {
 177      ?>
 178      <p>Author: Brett Batie &lt;brett-cms@classicwebdevelopment.com&gt; &amp; Simon van der Linden &lt;ifmy@geekbox.be&gt;</p>
 179      <p>Version: 1.4 (20061010)</p>
 180      <p>
 181      Change History:<br/>
 182          <ul>
 183          <li>l.2 : various improvements (errors handling, etc.)</li>
 184          <li>1.3 : added subject_get_var parameter (by elijahlofgren)</li>
 185          <li>1.4 : added captcha module support (by Dick Ittmann)</li>
 186          </ul>
 187      </p>
 188      <?php
 189  }
 190  
 191  function cfsanitize($content){
 192      return str_replace(array("\r", "\n"), "", trim($content));
 193  }
 194  
 195  function validEmail($email) {
 196      if (!preg_match("/^([\w|\.|\-|_]+)@([\w||\-|_]+)\.([\w|\.|\-|_]+)$/i", $email)) {
 197          return false;
 198          exit;
 199      }
 200      return true;
 201  }
 202  
 203  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7