T
T
teodor7teodor72016-07-06 11:43:27
Yii
teodor7teodor7, 2016-07-06 11:43:27

How to validate and submit data using yiiActiveForm?

Explain how you can set parameters and validate submit to REST using js.

InitEditUser: function (event) {
    var target = $(event.target);
    var url = 'http://' + window.location.hostname + '/users/' + target.attr('id');
    $('#editUser').modal('show');
    $('#editUserForm').data('yiiActiveForm').validationUrl = "http://tr.loc";
    $.ajax({
      type: 'GET',
      url: url,
      success: function (data, textStatus, jqXHR) {
        console.log(data);
        $('#editUserInput').val(data.login);
        $('#editUserFullNameInput').val(data.full_name);
        $('#editUserEmailInput').val(data.email);
        $('#editUserForm').on('beforeSubmit', function () {
          console.log("a");
          return false;
        });
        $('#editUserForm').on('afterValidate', function () {
          console.log("b");
        });
      },
      error: function (jqXHR, textStatus, errorThrown) {
    }
    });

  },

Here is an example code, we load the data, fill out the form, but I would like to use yiiActiveForm. That is, the data is loaded and validated after being sent when clicked. Are there any implementation examples?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question