Note that there are some explanatory texts on larger screens.

plurals
  1. POZend Ajax submit form
    text
    copied!<p>I have a little problem that I don't know how to solve. Ajax validation works perfect via zend. Pressing the submit button does validate, but when I got the right email and password it won't go to the user page. It just remains on that form. I know it has to do with the <code>return false</code> and <code>true</code> on the submit via Ajax.</p> <p>Can someone help me to solve that please. I have no idea how to <code>return true</code> on the submit if it detect no errors on validation.</p> <p>here's my code: Ajax and Javascript</p> <pre><code>$(function() { $('input').blur(function() { var formElementId = $(this).get(0).id; doValidation(formElementId); }); }); **$(function() { $('#btn_login').click(function() { var email = document.getElementById('email').id; var password = document.getElementById('password').id; doValidation(email); doValidation(password); return false; }); });** function doValidation(id) { var url = '/users/validationform'; var data = {}; $('input').each(function() { data[$(this).attr('name')] = $(this).val(); }); $.post(url,data,function(resp) { $("#" + id).parent().find('.errors').remove(); $("#" + id).parent().append(getErrorHtml(resp[id], id)); }, 'json'); } function getErrorHtml(formErrors, id) { var o = '&lt;div id="login-error" style="color:red"&gt;&lt;ul id="errors-'+id+'" class="errors" style="list-style-type:none;"&gt;'; for(errorKey in formErrors) { o += '&lt;li&gt;- ' + formErrors[errorKey] + '&lt;/li&gt;'; } o += '&lt;/ul&gt;&lt;/div&gt;'; return o; } </code></pre> <p>Zend controller:</p> <pre><code>public function validationformAction() { $loginForm = new Application_Form_UserLogin(); $loginForm-&gt;isValidPartial($_POST); header('Content-type: application/json'); $this-&gt;_helper-&gt;json($loginForm-&gt;getMessages()); } public function loginFormAction() { $this-&gt;_helper-&gt;layout()-&gt;disableLayout(); //$this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender(true); $email = $this-&gt;getRequest()-&gt;getParam('email'); $password = $this-&gt;getRequest()-&gt;getParam('password'); $loginForm = new Application_Form_UserLogin(); if ($this-&gt;getRequest()-&gt;isPost()) { /************ Login Form ************/ if ($loginForm-&gt;isValid($this-&gt;getRequest()-&gt;getParams())) { $user = $this-&gt;_helper-&gt;model('Users')-&gt;createRow($loginForm-&gt;getValues()); $user = $this-&gt;_helper-&gt;model('Users')-&gt;fetchRowByFields(array('email' =&gt; $email, 'hash' =&gt; $password)); if($user) { Zend_Session::rememberMe(86400 * 14); Zend_Auth::getInstance()-&gt;getStorage()-&gt;write($user); $this-&gt;getHelper('redirector')-&gt;gotoRoute(array(), 'invite'); return; } else { // Error message $this-&gt;view-&gt;errorMsg = "&lt;b&gt;password&lt;/b&gt; - invalid, please try again! *"; } } else { // something } } $this-&gt;view-&gt;loginForm = $loginForm; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload