2014-01-11 134 views
0

我在PHP文件(在Wordpress插件中)中有一个如下所示的表单。表单也在同一个文件内处理。通过AJAX提交表单步骤

我想将此表单保存为“步骤”。例如,用户将在第1页上选择4-5个选项,然后我希望AJAX发布选择。然后用户进入第2页,再次保存选择等。最后一页将有最后提交的验证码(如果更重要,我不知道在这个特定情况下)。

我想将整个界面作为一个表单使用,然后使用jQuery隐藏/显示<div>中的每个页面。

我想知道:

1)如何提交使用AJAX的用户选择这种特定类型的形式。

2)在“步骤”中浏览此表单的最有效方式是什么?

3)我还希望每个页面在表单验证时都能独立运行。是否有可能做到这一点?

  <form id="quotation_form" name="form" action="#" method="post"> 
       <div id="page1"> 
       <div id="step0_header" class="steps-headers" onClick="step0ToggleClick();">Step 1<span style="margin-left:30px;">Sun Exposure</span></div> 
       <div id="step0" class="quotation-steps"><strong>Describe the sun exposure of your planter...</strong><br/> 
        <div class="radio-container"><input type="radio" name="sun_exposure" id="sun_exposure_sunny_most" value="sunny_most"<?php checked('sunny_most',$_POST['sun_exposure']); ?> /><label class="label-quotation-steps">Sunny most of the day</label><br class="clear"/></div> 
        <div class="radio-container"><input type="radio" name="sun_exposure" id="sun_exposure_shady_morning" value="shady_morning"<?php checked('shady_morning',$_POST['sun_exposure']); ?> /><label class="label-quotation-steps">Shady Morning (Sunny Afternoon)</label><br class="clear"/></div> 
        <div class="radio-container"><input type="radio" name="sun_exposure" id="sun_exposure_sunny_morning" value="sunny_morning"<?php checked('sunny_morning',$_POST['sun_exposure']); ?> /><label class="label-quotation-steps">Sunny Morning (Shady Afternoon)</label><br class="clear"/></div> 
        <div class="radio-container"><input type="radio" name="sun_exposure" id="sun_exposure_shady_most" value="shady_most"<?php checked('shady_most',$_POST['sun_exposure']); ?> /><label class="label-quotation-steps">Shady most of the day</label><br class="clear"/><br class="clear"/></div> 
       </div> 

       <div id="step1_header" class="steps-headers" onClick="step1ToggleClick();">Step 2<span style="margin-left:30px;">Height</span></div> 
        <div id="step1" class="quotation-steps"><strong>What is the height of your planter?</strong><br /> 
        <div class="radio-container"><input type="radio" name="height" id="height_1" value="height_1"<?php checked('height_1',$_POST['height']); ?>/><label class="label-quotation-steps">8 to 14 inches</label><br class="clear"/></div> 
        <div class="radio-container"><input type="radio" name="height" id="height_2" value="height_2"<?php checked('height_2',$_POST['height']); ?>/><label class="label-quotation-steps">15 to 20 inches</label><br class="clear"/></div> 
        <div class="radio-container"><input type="radio" name="height" id="height_3" value="height_3"<?php checked('height_3',$_POST['height']); ?>/><label class="label-quotation-steps">21 inches or more</label><br class="clear"/><br class="clear"/></div> 
        </div> 

        <input type="button" name="get_quote" id="get_quote" value="Save choices and continue..." class="request_quotation_btn" /> 
        <input type="hidden" name="submit" value="true" /> 
       </div> <!-- #page1 --> 

       <div id="page2"> 
       <!-- Page2 stuff will go here, and is located in this same form. --> 
       </div> 
      </form> 
+0

看一看:http://www.smarttutorials.net/multi-step-signup-form-using-jquery-ajax-php-html5-and-css3/ –

回答