This form validation is not working in wordpress plugin

700 views Asked by At

This form validation code is not working in wordpress plugin, form directly gets submitted as if the onsubmit event is not there at all. Please help

<?php
/**
 * Plugin Name:....
 * Description:.....
 * Version: Pre release
 * Author:....
 * Author URI:....
 **/
add_action("admin_menu", "create_menus");

function create_menus()
{
 add_menu_page("cash Details", "cash Details", 4, "form-page", "cash_deals_form_page");
}

function cash_deals_form_page()
{
?>
<script>
    function validateForm() {
        var x = document.forms["myForm"]["clientName"].value;
        if (x == "") {
            alert("Name must be filled out");
            return false;
        } else {
            return confirm('Do you really want to submit this entry?');
        }
    }
</script>
<div style='display:inline-block; width:48%;'>
    <form name="myForm" method='post' onsubmit="return validateForm()" action="<?php echo $_SERVER['REQUEST_URI'];?>">
        Client Email (Type the Email Id of the client whom you want to allot cash):
        <br/>
        <input type='text' id='input1' name='clientName' maxlength='100'>
        <br/>
        <br/> Type the cash to be added in the client's account:
        <br/>
        <input type='number' id='input2' name='cash' min='-10000' max='100000000'>
        <br/>
        <br/> Type your comments here (optional):
        <br/>
        <textarea rows='4' cols='60' name='adminComment' maxlength='500'></textarea>
        <br/>
        <br/>
        <input type='submit' name='submit'>
        <br/>
    </form>
</div>
<?php
}
?>
1

There are 1 answers

0
user7324674 On

I found the problem, it turned out that validateForm() is a predefined function in wordpress, just changing that name solved the problem!!!!!!