ajax contact form conflict

Asked

Viewed 22 times

-2

Personal I am with a problem I have two contact fomularios in ajax and the one this giving conflict I know the error this in this line

$('form input[type="submit"]').bind('click', function (event) {

but I don’t know exactly how to stop the conflict from happening

$(document).ready(function () {
            var $form1 = $('#mc-embedded-subscribe-form')
            if ($form1.length > 0) {
                $('form input[type="submit"]').bind('click', function (event) {
                    if (event) event.preventDefault()
                    register($form1)
                })
            }
        })
        function register($form1) {
            $('#mc-embedded-subscribe').val('Sending...');
            $.ajax({
                type: $form1.attr('method'),
                url: $form1.attr('action'),
                data: $form1.serialize(),
                cache: false,
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                error: function (err) { alert('Could not connect to the registration server. Please try again later.') },
                success: function (data) {
                    $('#mc-embedded-subscribe').val('subscribe')
                    if (data.result === 'success') {
                        // Yeahhhh Success
                        console.log(data.msg)
                        $('#mce-EMAIL').css('borderColor', '#ffffff')
                        $('#subscribe-result').css('color', 'rgb(53, 114, 210)')
                        $('#subscribe-result').html('<p>Thank you for subscribing. We have sent you a confirmation email.</p>')
                        $('#mce-EMAIL').val('')
                    } else {
                        // Something went wrong, do something to notify the user.
                        console.log(data.msg)
                        $('#mce-EMAIL').css('borderColor', '#ff8282')
                        $('#subscribe-result').css('color', '#ff8282')
                        $('#subscribe-result').html('<p>' + data.msg.substring(4) + '</p>')
                    }
                }
            })
        };

follows the complete code

1 answer

-1

$(document).ready(function () {
            var $form1 = $('#mc-embedded-subscribe-form')
            if ($form1.length > 0) {
                $('#mc-embedded-subscribe-form input[type="submit"]').bind('click', function (event) {
                    if (event) event.preventDefault()
                    register($form1)
                })
            }
        })
        function register($form1) {
            $('#mc-embedded-subscribe').val('Sending...');
            $.ajax({
                type: $form1.attr('method'),
                url: $form1.attr('action'),
                data: $form1.serialize(),
                cache: false,
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                error: function (err) { alert('Could not connect to the registration server. Please try again later.') },
                success: function (data) {
                    $('#mc-embedded-subscribe').val('subscribe')
                    if (data.result === 'success') {
                        // Yeahhhh Success
                        console.log(data.msg)
                        $('#mce-EMAIL').css('borderColor', '#ffffff')
                        $('#subscribe-result').css('color', 'rgb(53, 114, 210)')
                        $('#subscribe-result').html('<p>Thank you for subscribing. We have sent you a confirmation email.</p>')
                        $('#mce-EMAIL').val('')
                    } else {
                        // Something went wrong, do something to notify the user.
                        console.log(data.msg)
                        $('#mce-EMAIL').css('borderColor', '#ff8282')
                        $('#subscribe-result').css('color', '#ff8282')
                        $('#subscribe-result').html('<p>' + data.msg.substring(4) + '</p>')
                    }
                }
            })
        };

was only to assign the form id and not only form on the Submit line

Browser other questions tagged

You are not signed in. Login or sign up in order to post.