title: while using ajax to save data in yii 2.0 it save twice and null value in database
body: <p>i am newbie in yii and php. i try to save data using ajax in yii framework but it save twice in database with null value. and after insert it redirect to other page and show {"success":"True"}. I want success message under the text field.
   Here is my code :(index.php)</p>
  
  <pre><code>&lt;div class="news_letter"&gt;
   &lt;?php $form =ActiveForm::begin([
           'id'=&gt;'newslatter',
           'method' =&gt; 'post',
           'action' =&gt; ['home/save'],
          //'action' =&gt; ['newslatter/Save'],
           'enableAjaxValidation'=&gt;true,
         // 'validationUrl'=&gt;['home/validate'],
  
   ]);?&gt;
  
  
   &lt;?php  $model= new Addnewslatter;?&gt;
  
      &lt;div class="container"&gt;
          &lt;h1&gt;Subscribe to the newsletter&lt;/h1&gt;
          &lt;span&gt;We'll never bother you, we promise!&lt;/span&gt;
         &lt;!--   &lt;input type="text" name="txt1" placeholder="Email..." class="email"&gt;--&gt;
          &lt;?=$form-&gt;field($model,'email')-&gt;textInput(['maxlength' =&gt; 255,'class' =&gt; 'email','placeholder'=&gt;' Enter Email'])-&gt;label(false) ?&gt;
          &lt;?= Html::submitButton('submit', ['class' =&gt; 'submit']) ?&gt;
  
  &lt;/div&gt;
  
  &lt;script&gt;
  $(document).ready(function() {
  
    $('body').on('beforeSubmit', '#newslatter', function () {
          var form = $(this);
           // return false if form still have some validation errors
           if (form.find('.has-error').length) {
                return false;
           }
           // submit form
           $.ajax({
                url: form.attr('action'),
                type: 'post',
                data: form.serialize(),
                success: function (response) {
                     // do something with response
                }
           });
           return false;
      });
  });
  
    &lt;/script&gt;
  
    &lt;?php ActiveForm::end(); ?&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>COntroller :(HomeController.php)</p>
  
  <pre><code>  public function actionSave()
      {
          $model = new AddNewslatter();
          $request = \Yii::$app-&gt;getRequest();
          if ($request-&gt;isPost &amp;&amp; $model-&gt;load($request-&gt;post())) {
              $model-&gt;attributes=$request-&gt;post();
  
  
              \Yii::$app-&gt;response-&gt;format = Response::FORMAT_JSON;
              //return ['success'=&gt;'Response'];
              return ['success' =&gt;$model-&gt;save()];
          }
  
      }
  </code></pre>
  
  <p>Model(Addnewslatter.php)</p>
  
  <pre><code>    &lt;?php
  
  namespace app\models;
  
  use Yii;
  use yii\base\Model;
  use app\controllers\Addnewscontoller;
  
  /**
   * This is the model class for table "newslatter".
   *
   * @property integer $id
   * @property string $email
   */
  class Addnewslatter extends \yii\db\ActiveRecord
  {
  
      public $email;
  
      public static function tableName()
      {
          return 'newslatter';
      }
  
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
              [['email'], 'required'],
              ['email','email']
          ];
      }
  
      /**
       * @inheritdoc
       */
      public function attributeLabels()
      {
          return [
              'id' =&gt; \Yii::t('app', 'id'),
              'email' =&gt; \Yii::t('app', 'email'),
          ];
      }
  }
  </code></pre>
  
  <p>please give me a solution if any one know.</p>