您好,欢迎来到源码搜藏!分享精神,快乐你我!提示:担心找不到本站?在百度搜索“源码搜藏”,网址永远不丢失!
  • 首 页
  • 在线工具
  • 当前位置:首页 > 网页特效 > TAB表单 >

    一个精选的 AJAX Contact 表单(A Fancy AJAX Contact Form)

    时间:2014-05-27 15:46 来源:互联网 作者:源码搜藏 浏览:收藏 挑错 推荐 打印
    效果预览 进入下载地址列表

    DEMO DOWNLOAD
    First, we are going to take a look at the XHTML markup behind the form.

    demo.php

    <div id="main-container">	<!-- The main container element -->
    
    <div id="form-container">	<!-- The form container -->
    
    <h1>Fancy Contact Form</h1>	<!-- Headings -->
    <h2>Drop us a line and we will get back to you</h2>
    
    <form id="contact-form" name="contact-form" method="post" action="submit.php">	<!-- The form, sent to submit.php -->
    
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    
    <tr>
    <td width="18%"><label for="name">Name</label></td>	<!-- Text label for the input field -->
    <td width="45%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td>
    <!-- We are using session to prevent losing data between page redirects -->
    
    <td width="37%" id="errOffset">&nbsp;</td>
    </tr>
    
    <tr>
    <td><label for="email">Email</label></td>
    <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td>
    <td>&nbsp;</td>
    </tr>
    
    <tr>
    <td><label for="subject">Subject</label></td>
    
    <!-- This select is being replaced entirely by the jqtransorm plugin -->
    
    <td><select name="subject" id="subject">
    <option value="" selected="selected"> - Choose -</option>
    <option value="Question">Question</option>
    <option value="Business proposal">Business proposal</option>
    <option value="Advertisement">Advertising</option>
    <option value="Complaint">Complaint</option>
    </select>          </td>
    <td>&nbsp;</td>
    </tr>
    
    <tr>
    <td valign="top"><label for="message">Message</label></td>
    <td><textarea name="message" id="message" class="validate[required]" cols="35" rows="5"><?=$_SESSION['post']['message']?></textarea></td>
    <td valign="top">&nbsp;</td>
    </tr>
    
    <tr>
    <td><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td>
    
    <!-- A simple captcha math problem -->
    
    <td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td>
    <td valign="top">&nbsp;</td>
    </tr>
    
    <tr>
    <td valign="top">&nbsp;</td>
    <!-- These input buttons are being replaced with button elements -->
    <td colspan="2"><input type="submit" name="button" id="button" value="Submit" />
    <input type="reset" name="button2" id="button2" value="Reset" />
    <?=$str?>
    
    <!-- $str contains the error string if the form is used with JS disabled -->
    
    <img id="loading" src="img/ajax-load.gif" width="16" height="16" alt="loading" />
    <!-- the rotating gif animation, hidden by default -->
    </td></tr>
    
    </table>
    </form>
    
    <?=$success?>
    <!-- The $success variable contains the message that is shown if JS is disabled and the form is submitted successfully -->
    
    </div>
    </div>	<!-- closing the containers -->

    As you can see from line 8, we are submitting our form to submit.php. We are using this file to handle both the regular form submit (for visitors with JS disabled) and the AJAX form submit. This allows the code to be updated easily with no need to merge changes between files.

    Later you can see that we use the $_SESSION array to populate the values of the input fields. This is done to insure that the data is not lost during page redirects, which occur when the form is submitted to submit.php during the regular form submit.

    Another important aspect are the classes assigned to the input fields –classs=”validate[required,custom[onlyLetter]]”. These classes are used by the validation plug-in to define the validation rules for every input field, or text area. We are basically saying that the field is required, and only letters are allowed.

    There is a number of available validation rules. You can see them at the plug-in’s homepage.

    Now lets see how the plain form is fancyfied with the use of the JQtransform plugin.

    The fancy contact form
     
    一个精选的 AJAX Contact 表单(A Fancy AJAX Contact Form)由源码搜藏网整理,转载请注明出处http://www.codesocang.com/texiao/tab/8080.html 源码搜藏承诺:本站所有资源无病毒,无弹窗,无干扰链接!
    标签:网站源码