Jump to content

Recommended Posts

Posted

Bom dia,

Estou a alterar o meu formulário de contacto e a tentar colocar uma checkbox de preenchimento obrigatório e não está a funcionar, em javascript.

o meu formulário é o seguinte:

                <form id="contactForm" class="home-contact-form contact-form">
                    <div class="row">
                        <div class="col-md-6">
                            <input type="text" id="name" name="name" placeholder="<?=$lang_home_contactos2?>">
                        </div>
                        <div class="col-md-6">
                            <input type="text" id="email" name="email" placeholder="<?=$lang_home_contactos3?>">
                        </div>
                        <div class="col-md-6">
                            <input type="text" id="phone" name="phone" placeholder="<?=$lang_home_contactos4?>">
                        </div>
                        <div class="col-md-6">
                            <input type="text" id="subject" name="subject" placeholder="<?=$lang_home_contactos5?>">
                        </div>
                        
                        <div class="col-md-12">
                            <textarea id="text" name="text" placeholder="<?=$lang_home_contactos6?>"></textarea>
                         </div>
             
                    <?If($lang=='pt'){?>
                    <div class="col-md-1">
                       <input type="checkbox" id="checkbox" name="checkbox" >
                    </div>
                    <div class="col-md-11" style="margin-top:7pt;">
                       <spam><p style="font-size:12px;line-height: 15px;margin-top:5px;"><?=$lang_menu_checkbox?></p></spam>
                    </div><?}?>
                    
                        <div class="col-md-12">
                            <button type="button" id="trySend"><?=$lang_home_contactos7?></button>
                        </div>

                    </div>
                </form>

e o meu javascript está da seguinte forma:

$(document).ready(function(){
/* == COMMON ================================================================================================ */

    var $gbMod = $('body').data('mod'),
        gbLang = $('body').data('lang');

/* ================================================================================================ COMMON == */
$(document).on('click', 'button#trySend', function(){
        var $el = $(this);
        if(!$el.hasClass('blocked')){
            $el.addClass('blocked');

            var $form = $('form#contactForm'),
                $name = $form.find('input#name'),
                $email = $form.find('input#email'),
                $phone = $form.find('input#phone'),
                $subject = $form.find('input#subject'),
                $message = $form.find('textarea#text'),
                $checkbox = $form.find('input#checkbox');
               
            

            if($name.val()!='' && $email.val()!='' && $phone.val()!='' && $subject.val()!=''  && $message.val()!=''&& $checkbox.val()!=''  ){
                $.post('/ajax/tryNewContact', {name: $name.val(), email: $email.val(), phone: $phone.val(), subject: $subject.val(), message: $message.val(), checkbox: $checkbox.val()}, function (data) {
                    if(data==1){
                       
                        var title = 'Sucesso',
                            msg = 'O seu contacto foi enviado com sucesso, seremos breves.';

                        if(gbLang=='en'){
                            title = 'Success';
                            msg = 'Your contact has been sent successfully, we will be brief.';
                        }else if(gbLang=='it'){
                            title = 'Successo';
                            msg = 'Il vostro contatto è stato inviato con successo, ci sarà breve.';
                        }else if(gbLang=='fr'){
                            title = 'Succès';
                            msg = 'Votre contact a été envoyé avec succès, nous serons brefs.';
                        }

                        swal(title, msg, 'success');
                    }
                });
            }else{
                var title = 'Atenção',
                    msg = 'Os campos são de preenchimento obrigatório.';

                if(gbLang=='en'){
                    title = 'Attention.';
                    msg = 'Fields are required.';
                }else if(gbLang=='it'){
                    title = 'Attenzione.';
                    msg = 'I campi sono obbligatori.';
                }else if(gbLang=='fr'){
                    title = 'Attention.';
                    msg = 'Les champs sont obligatoires.';
                }

                swal(title, msg, 'warning');
                $el.removeClass('blocked');
            }
            
            
        }

});

});

Alguém tem uma solução para o meu problema?

Obrigada

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.