Входной пост плагина Sweetalert

Я пытаюсь создать функцию смены пароля, используя плагин sweetAlert с вводом по умолчанию.

Пользователь вводит свой новый пароль, и при нажатии кнопки «Отправить» появляется sweetAlert и запрашивает старый пароль или, например, вопрос. Как я могу отправить входное значение в код PHP, чтобы проверить старый пароль, а затем отправить форму? Я застрял в том месте, где нужно отправить старый пароль пользователя в php.

Что у меня есть до сих пор:

        var user_id = '<?php echo $row["user_id"] ?>';

        $("#hiddenUserID").val(user_id);
        //****************************************SUBMIT DATA ****************************************//
        $(document).on("click", "#updateProfile", function (e) {
            //$(".se-pre-con").show();

            $('#rootwizard').formValidation({
                framework: 'bootstrap',
                excluded: [':disabled'],
                icon: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },   
                live: 'enabled',

                framework: 'bootstrap',
                icon: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    userRetypePassword: {
                        validators: {
                            identical: {
                                field: 'userPassword',
                                message: 'password doesnt match'
                            }
                        }
                    },
                }
            }).on('err.field.fv', function(e, data) {
                // data.fv --> The FormValidation instance

                // Get the first invalid field
                var $invalidFields = data.fv.getInvalidFields().eq(0);

                // Get the tab that contains the first invalid field
                var $tabPane     = $invalidFields.parents('.tab-pane'),
                    invalidTabId = $tabPane.attr('id');

                // If the tab is not active
                if (!$tabPane.hasClass('active')) {
                    // Then activate it
                    $tabPane.parents('.tab-content')
                        .find('.tab-pane')
                        .each(function(index, tab) {
                        $(".fade").css("opacity", "1");
                        var tabId = $(tab).attr('id'),
                            $li   = $('a[href="#' + tabId + '"][data-toggle="tab"]').parent();

                        if (tabId === invalidTabId) {
                            // activate the tab pane
                            $(tab).addClass('active');
                            // and the associated <li> element
                            $li.addClass('active');
                        } else {
                            $(tab).removeClass('active');
                            $li.removeClass('active');
                        }
                    });

                    // Focus on the field
                    $invalidFields.focus();
                }
            }).on('success.field.fv', function(e, data) {
                // data.fv      --> The FormValidation instance
                // data.element --> The field element

                var $tabPane = data.element.parents('.tab-pane'),
                    tabId    = $tabPane.attr('id'),
                    $icon    = $('a[href="#' + tabId + '"][data-toggle="tab"]')
                .parent()
                .find('i')
                .removeClass('fa-check fa-times');

                // Check if all fields in tab are valid
                var isValidTab = data.fv.isValidContainer($tabPane);
                if (isValidTab !== null) {
                    $icon.addClass(isValidTab ? 'fa-check' : 'fa-times');
                }
            }).on('success.form.fv', function(e, data) {
                // Prevent form submission
                e.preventDefault();

                var $form    = $(e.target),
                    formData = new FormData(),
                    params   = $form.serializeArray();

                $.each(params, function(i, val) {
                    formData.append(val.name, val.value);
                });

                swal({
                    title: "password",
                    text: "enter old password",
                    type: "input",
                    showCancelButton: true,
                    closeOnConfirm: false,
                    animation: "slide-from-top",
                    inputPlaceholder: "password..."
                }, function(inputValue) {
                    if (inputValue === false) return false;
                    if (inputValue === "") {
                        swal.showInputError("type old password");
                        return false
                    }
                    $.ajax({
                        url: $form.attr('action'),
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false,
                        type: 'POST',
                        success: function(data){
                            console.log(data);
                            if(data.status == 'success'){
                                console.log("success");    
                            }else if(data.status == 'error'){
                                $(".se-pre-con").fadeOut("slow");
                            }else if(data.status == 'general_info_error'){
                                $(".se-pre-con").fadeOut("slow");
                            }     
                        },
                        error: function(jqXHR, textStatus, errorThrown, data){
                            console.log(jqXHR, textStatus, errorThrown, data);
                        }
                    });
                });
            });
        });

HTML

    <div role="tabpanel" class="tab-pane  fade in active" id="tab1">
    <div class="page-subtitle margin-bottom-0">
            <h3>Password change</h3>
            <p>Change your password</p>
        </div>
        <div class="form-group-one-unit margin-bottom-40">
            <div class="row">
                <div class="col-md-3">
                    <label>password:</label>
                    <div class="form-group form-group-custom">

                        <input type="password" class="form-control" id="userPassword" name="userPassword">
                    </div>
                </div>
                <div class="col-md-3">
                    <label>retype password</label>
                    <div class="form-group form-group-custom">

                        <input type="password" class="form-control" id="userRetypePassword" name="userRetypePassword">
                    </div>
                </div>
            </div>
        </div>
    </div>

person z0mbieKale    schedule 06.06.2016    source источник
comment
есть ли какая-нибудь скрипка?   -  person Sarath    schedule 06.06.2016
comment
@Сарат сек. создаст один   -  person z0mbieKale    schedule 06.06.2016
comment
не могу заставить скрипку работать...   -  person z0mbieKale    schedule 06.06.2016


Ответы (1)


Итак, после небольшого количества проб и ошибок я добавил входное значение к formdata и работал как шарм.

                }, function(typedPassword) {
                    if (typedPassword === false) return false;
                    if (typedPassword === "") {
                        swal.showInputError("Palun kirjutage oma parool!");
                        return false
                    }

                    var $form    = $(e.target),
                        formData = new FormData(),
                        params   = $form.serializeArray();

                    $.each(params, function(i, val) {
                        formData.append(val.name, val.value);
                    });
                    formData.append("typedPassword", typedPassword);

Надеюсь, это тоже кому-то поможет.

person z0mbieKale    schedule 06.06.2016