Posts tagged ‘jquery’

June 28th, 2010

jQuery Tools Form + PHP mail() (PHP 4, PHP 5)

jquery php email form

jquery php email form

This example shows how to integrate php mail which is is used to send emails from inside a script with jQuery Tools form which is a collection of essential form building tools. Validation, range- and date inputs for humans. Those two make a great combination and are easy to implement to any website. Here is the example. The code speaks for itself so there is not much commenting on it.

Standalone example can be found HERE.
Source code HERE.

PHP:


if(isset($_POST['submit'])){
  $to      = $_POST['email'];
  $subject = "You've got mail";
  $message = "*** eMail: ".$_POST['email']."*** Website: ".$_POST['url']."*** Name: ".$_POST['name']."*** Age; ".$_POST['age'];
  $headers = 'From: webmaster@example.com' . "\r\n" .
      'Reply-To: webmaster@example.com' . "\r\n" .
      'X-Mailer: PHP/' . phpversion();

  mail($to, $subject, $message, $headers);
  
  echo "Email to ".$_POST['email']." was sent successfuly! <br />";
}

HTML:


<form id="myform" method="post">

   <fieldset>
      <h3>PHP + JQuery Tools Sample email form</h3>
      
      <p> Enter bad values and then press the email button. </p>
      
      <p>
         <label>email *</label>
         <input type="email" name="email" required="required" />
      </p>
      <p>
         <label>website *</label>
         <input type="url" name="url" required="required" />
      </p>
      <p>
         <label>name *</label>
         <input type="text" name="name" pattern="[a-zA-Z ]{5,}" maxlength="30" />
      </p>
      <p>
         <label>age</label>
         <input type="number" name="age" size="4" min="5" max="50" />
      </p>
      <input type='hidden' name='submit' />
      
      <button type="submit">Email form</button>
      <button type="reset">Reset</button>
   </fieldset>

</form>


<script>
$("#myform").validator();
</script>

November 16th, 2009

How to use SMARTY variables in JavaScript

This is a simple example of how to use Smarty variables in JavaScript.


{literal}

     &lt;script&gt;

          $(window).load(function() {  var sample='/sample.php?v=<strong>{/literal}{$smarty_variable}{literal}</strong>';  });

    &lt;/script&gt;

{/literal}