2012-11-11 37 views
-3

我有基於輸入字段的值提交給url的重定向表單。但是如果電子郵件不正確,我的表單仍然提交。我該如何解決它?此表單的網址是dokuchaeva.com/donate/。我需要驗證是電子郵件。現代瀏覽器驗證它購買默認。如果電子郵件字段錯誤,我會提醒您,但表單仍會提交。我需要提交表單並根據插入的信息重定向到預定義的url。如何驗證表單然後提交到網址?

  <form> 
       <label>DONATION AMOUNT</label> <input name="price" id="price" class="button" value="100" required size="6" tabindex="1"> RUB<br><br> 
       <label>YOUR E-MAIL</label> <input type="email" name="user_email" id="user_email" required="" placeholder="[email protected]" class="button" autofocus="autofocus" tabindex="0"> 
       <input type="submit" id="submit" value="SUBMIT" class="button" tabindex="3" onclick="location.href= 'http://secure.onpay.ru/pay/dokuchaeva?'+'pay_mode=fix&pay_for=donation&price='+$('#price').val()+'&currency=RUR&user_email='+$('#user_email').val()+'&pay_for=donation&convert=no&ln=en&url_success=dokuchaeva.com/donate/success.html&url_fail=dokuchaeva.com/donate/fail.html';"> 
      </form> 
+0

https://www.google.ch/webhp?sourceid=chrome-instant&ion=1&ie=UTF-8# HL = FR&gs_nf = 3&TOK = cFdSYRBGUrI4H-PG-avtlA&PQ = jquery的%20validate%20form%20before%20submit&CP = 38&gs_id = 10&XHR = T&q = jquery的+ + +之前驗證+形式提交&PF = p&安全=關閉&sclient = PSY-AB和OQ = jquery的+驗證+形式++之前提交&gs_l =&PBX = 1&BAV = on.2,or.r_gc.r_pw.r_cp.r_qf。&FP = f65d48ad5fdc2a1b&BPCL = 38093640&離子= 1&BIW = 1200&波黑= 649 – sdespont

回答

0

首先,您需要指定您想要的驗證類型。

如果你想只基於客戶端的驗證,將處理表單數據不提交。

檢查jQuery驗證插件,會非常方便。

http://docs.jquery.com/Plugins/Validation

如果你想同時基於客戶端和後端基礎validation.Firstly你需要驗證在客戶端使用jQuery驗證,然後提交表單,並使用你的驗證邏輯在後端。

如檢查電子郵件的數據庫,或者如果用戶名已被佔用等已經存在

+0

所有我需要驗證是電子郵件。現代瀏覽器驗證它購買默認。如果電子郵件字段錯誤,我會提醒您,但表單仍會提交。我需要提交表單並根據插入的信息重定向到預定義的url。 –

+0

然後,表單提交後,你需要在你的服務器端做你的東西,並根據預定義的url重定向用戶。 –

1

使用form.submit功能,如果你返回true你awknowledge的表單提交媒體鏈接處理還是應中止 - 作爲回報,如果回報是假的,瀏覽器通常會將其發送的形式。

<script> 
    function validateme(form) { 
     var isValid = false; // default, not true 
     for(var el in form.elements) if(form.elements.hasOwnProperty(el) { 
      // perform checks here 
      if(form.elements[el].value == "") isValid = false; 
     } 
     return !(isValid); 
    } 
</script> 
<form action="getUrlHereOrDocumentLocationIsUsed" submit="return validateme(this)"> 
... 
</form>