WordPress.org

Ready to get started?Download WordPress

Forums

Captcha
[resolved] Validation not working in custom form (2 posts)

  1. crancherry
    Member
    Posted 9 months ago #

    I have a custom form. I have gotten the CAPTCHA to display, but no matter where I enter the CAPTCHA validation lines to the section of validation code, it breaks the validation for the form and also does not try to validate the CAPTCHA. I even had the developer of my theme try to place the lines and they could not figure it out. I have read all of the forum questions and see that anytime someone is asking this question, the answer is a copy-paste of the generic instructions. Can someone please assist with specific info about placing of the validation code?

    Here is the validation code from my form:

    <?php
                    $subject_error_msg = get_option('contact_subject_error_message');
                    $name_error_msg = get_option('contact_name_error_message');
                    $email_error_msg = get_option('contact_email_error_message');
                    $message_error_msg = get_option('contact_message_error_message');
                    $mail_success_msg = get_option('contact_message_successful');
                    $mail_error_msg = get_option('contact_message_unsuccessful');
    
                    ?>
    
                    <!-- Validate script -->
    
                    <script type="text/javascript">
                        function validate_email(field,alerttxt)
                        {
                            with (field)
                            {
                                apos=value.indexOf("@");
                                dotpos=value.lastIndexOf(".");
                                if (apos<1||dotpos-apos<2)
                                {$('#contact-error').empty().append(alerttxt);return false;}
                                else {return true;}
                            }
                        }
    
                        function check_field(field,alerttxt,checktext){
                            with (field)
                            {
                                var checkfalse = 0;
                                if(field.value == ""){
                                    $('#contact-error').empty().append(alerttxt);
                                    field.focus();checkfalse=1;}
    
                                if(field.value==checktext)
                                {
                                    $('#contact-error').empty().append(alerttxt);
                                    field.focus();checkfalse=1;}
    
                                if(checkfalse==1){return false;}else{return true;}
                            }
                        }
    
                        function checkForm(thisform)
                        {
                            with (thisform)
                            {
    
                                var error = 0;
    
                                var message = document.getElementById('message');
                                if(check_field(message,"<?php echo $message_error_msg?>","")==false){
                                    error = 1;
                                }
    
                                var email = document.getElementById('email');
                                if (validate_email(email,"<?php echo $email_error_msg?>")==false)
                                {email.focus();error = 1;}
    
                                var contactname = document.getElementById('contactname');
                                if(check_field(contactname,"<?php echo $name_error_msg?>","")==false){
                                    error = 1;
                                }
    
                                if(error == 0){
                                    var contactname = document.getElementById('contactname').value;
                                    var email = document.getElementById('email').value;
                                    var message = document.getElementById('message').value;
    
                                    return true;
                                }
    
                                return false;
    
                            }
    
                        }
    
                    </script>
    
                    <!-- end of script -->

    http://wordpress.org/plugins/captcha/

  2. bestwebsoft
    Member
    Plugin Author

    Posted 9 months ago #

    Hi crancherry,

    You have a script validation, i.e. you should you make it either in php or ajax-request by creating a function in the php file.
    We can help you implement captcha, but it is a paid service.

    Sincerely,
    Support Team

Reply

You must log in to post.

About this Plugin

About this Topic