title: Submit a form via Ajax in Yii. Yii is double submitting the form
body: <p>I have the following:</p>
  
  <p><strong>My View</strong></p>
  
  <pre><code>&lt;?php $form = ActiveForm::begin(['id' =&gt; 'emailForm', 'action' =&gt; 'send-email', 'method' =&gt; 'post', 'enableAjaxValidation' =&gt; false, 'options' =&gt; ['class' =&gt; '']]) ?&gt; 
  &lt;?= $form-&gt;field($emailModel, 'verifyCode')-&gt;widget(Captcha::className(), [
      'template' =&gt; '&lt;div class="row"&gt;&lt;div class="col-lg-3"&gt;{image}&lt;/div&gt;&lt;div class="col-lg-6"&gt;{input}&lt;/div&gt;&lt;/div&gt;',
  ]) ?&gt;
  &lt;?= Html::submitButton('Submit', ['class' =&gt; 'btn btn-primary', 'name' =&gt; 'email-button']) ?&gt;
  </code></pre>
  
  <p><strong>My Controller</strong></p>
  
  <pre><code>  public function actionSendEmail() {
      Yii::$app-&gt;response-&gt;format = Response::FORMAT_JSON;
      $model = new EmailModel();
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;validate()) {
        return ['info' =&gt; "Your message has been sent!"];
      } else {
        // error
        // return $model-&gt;errors;
        return ActiveForm::validate($model);
      }
  </code></pre>
  
  <p><strong>My model</strong></p>
  
  <pre><code> public function rules()
      {
          return [
              [['name', 'from', 'to', 'message'], 'required'],
              [['from', 'to'], 'email'],
              ['verifyCode', 'captcha'],
          ];
  </code></pre>
  
  <p><strong>javascript</strong></p>
  
  <pre><code>jQuery(function() {
      $('#emailForm').submit(function(event) {
          event.preventDefault();
          $.post('send-email', $( "#emailForm" ).serialize(), function(data) {
              console.log (data);
  //          $('#emailAlert').show().empty().append(data);
          });
          return false;
  enter code here
  </code></pre>
  
  <p><code>event.preventDefault();</code> and <code>return false;</code> is not stopping Yii itself from submitting the form, so it is double submitting. </p>
  
  <p><code>'enableAjaxValidation' =&gt; true</code> causes Yii to validate the form after each &amp; every change to each field, so I set it to false.</p>
  
  <p><em>Console</em> throws:</p>
  
  <pre><code>XHR finished loading: POST "http://localhost:81/shopping/send-email".send @ jquery.js
    Object {info: "Your message has been sent!"}
  XHR finished loading: POST "http://localhost:81/shopping/send-email".send @ jquery.js
    Object {info: "Your message has been sent!"}
  </code></pre>