表单在没有信息的情况下提交和重定向

时间:2016-12-19 15:03:51

标签: forms

我对表格非常糟糕,所以你能提供的任何帮助都会很棒。 这个表单最初有一个提交时出现的模式,但我不得不将其更改为重定向。现在它重定向没有输入任何数据。

<form id="contact-form" method="post" onsubmit="return redirect()">
              <div class="contact-form-loader"></div>
              <fieldset>
                <div class="contact-form_top-section">
                    <label class="name">
                      <input type="text" name="name" placeholder="Parent's Name:" value="" data-constraints="@Required @JustLetters">
                      <span class="empty-message">*This field is required.</span>
                      <span class="error-message">*This is not a valid name.</span>
                    </label>
                    <label class="email">
                      <input type="text" name="email" placeholder="Parent's E-mail:" value="" data-constraints="@Required @Email">
                      <span class="empty-message">*This field is required.</span>
                      <span class="error-message">*This is not a valid email.</span>
                    </label>
                    <label class="phone">
                      <input type="text" name="phone" placeholder="Parent's Cellphone:" value="" data-constraints="@JustNumbers">
                      <span class="empty-message">*This field is required.</span>
                      <span class="error-message">*This is not a valid phone.</span>
                    </label>
                    <label class="message">
                      <input type="text" name="message" placeholder="Tell us about your children:" value="" data-constraints="@Required">
                      <span class="empty-message">*This field is required.</span>
                      <span class="error-message">*The message is too short.</span>
                    </label>  
                </div>
                <div class="contact-form_bottom-section">
                  <a href="#" class="btn btn__hover" data-type="reset">Clear</a>
                  <input type="submit" class="btn btn__hover bg-color-6" value="Send">
                </div>  
              </fieldset>

.js页面有大量数据,我不确定你需要哪个部分。这是第一部分。

;(function($){
    $.fn.TMForm=function(opt){
        return this.each(TMForm)

        function TMForm(){
            var form=$(this)
            opt=$.extend({  
                    okClass:'ok'
                    ,emptyClass:'empty'
                    ,invalidClass:'invalid'
                    ,successClass:'success'
                    ,responseErrorClass:'response-error'    
                    ,responseMessageClass:'response-message'
                    ,processingClass:'processing'
                    ,onceVerifiedClass:'once-verified'
                    ,mailHandlerURL:'bat/MailHandler.php'                   
                    ,successShowDelay:'4000'
                    ,stripHTML:true
                    ,recaptchaPublicKey:''
                    ,capchaTheme:'clean'
                },opt)

            init()

            function init(){                
                form
                    .on('submit',formSubmit)
                    .on('reset',formReset)
                    .on('focus','[data-constraints]',function(){
                        $(this).parents('label').removeClass(opt.emptyClass)
                    })
                    .on('blur','[data-constraints]:not(.once-verified)',function(){
                        $(this)
                            .addClass(opt.onceVerifiedClass)
                            .trigger('validate.form')
                    })
                    .on('keyup','[data-constraints].once-verified',function(){
                        $(this).trigger('validate.form')
                    })
                    .on('keydown','input',function(e){
                        var $this=$(this)
                            ,next=$this.parents('label').next('label').find('input,textarea')
                        if(e.keyCode===13)
                            if(next.length)
                                next.focus()
                            else
                                form.submit()
                    })
                    .on('keydown','textarea',function(e){
                        if(e.keyCode===13&&e.ctrlKey)
                            $(this).parents('label').next('label').find('input,textarea').focus()
                    })
                    .on('change','input[type="file"]',function(){                       
                        $(this).parents('label').next('label').find('input,textarea').focus()
                    })                  
                    .attr({
                        method:'POST'
                        ,action:opt.mailHandlerURL
                    })

1 个答案:

答案 0 :(得分:0)

最好的办法是将重定向功能放在formSubmit函数的末尾,该函数应位于JS文件的某个位置。通过做你所做的事,你的形式永远不会碰到'formSubmit&#39;我假设的函数处理数据。