Search code examples
yiiyii2yii2-advanced-appyii2-basic-appyii2-model

Yii2 enable second button after the submit the form


Form with buttons

I want to enable those two button after submit on same page using yii2. First time the button will be disabled, As i click on submit after successfully submit that buttons would be enabled.

How can we perform this in yii2?

Please help.

thanks in advance !!


Solution

  • You can use ajax form submit and enable buttons inside the success callback. Assuming the id of your from is myForm and your Add Slider and Add Attchment buttons have ids add-slider and add-attachment respectively.

    $(document).ready(
        $('#myform').on('beforeSubmit', function(event, jqXHR, settings) {
            var form = $(this);
            if(form.find('.has-error').length) {
                return false;
            }
    
            $.ajax({
                url: form.attr('action'),
                type: 'post',
                data: form.serialize(),
                success: function(data) {
                    $('#add-slider, #add-attachment').prop('disabled', false);
                }
            });
    
            return false;
        }),
    );