Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the astra domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/sqrtyhjzaqx471/public_html/wp-includes/functions.php on line 6121

Home Forums PHP How to create form captcha validation using PHP and Java Script ? Reply To: How to create form captcha validation using PHP and Java Script ?

#132
softechquery
Keymaster

Use this code

<?php
$code=rand(1000,9999);
?>

<script>
    function myfun(){ 
        var x = document.getElementById('captcha1').value;
        var y = <?php echo $code  ?>;

        if (x == y) {
            return true;
        }
        else{
            return false;
        }
    }
<script>
<form>
<span-><?php echo $code;?></span>
<input id="captcha1" name="captcha" type="text">
<input id="button" type='submit'  onclick=" return myfun();" value='Submit'>
</form>
Scroll to Top