I am trying to add custom form validation. This is what i am using.

    /* include file in magento scope */
    include_once 'app/Mage.php';
    $basePath= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
    $media = Mage::getBaseDir('media');

        echo "form submitted thanks.";die;

<link media="all" href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'adminhtml/default/default/boxes.css'; ?>" type="text/css" rel="stylesheet">
<link media="all" href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'adminhtml/default/default/reset.css';?>" type="text/css" rel="stylesheet">

<script type="text/javascript" src="<?php echo $basePath?>js/prototype/prototype.js"></script>
<script type="text/javascript" src="<?php echo $basePath?>js/prototype/validation.js"></script>
<script type="text/javascript" src="<?php echo $basePath?>js/varien/js.js"></script>
<script type="text/javascript" src="<?php echo $basePath?>js/varien/form.js"></script>

    <div class="entry-edit">  
    <div class="entry-edit-head">
        <h4>Model Information</h4>
    <div id="product_options_container">
        <div id="product_options_container_top"></div>
        <div id="product_options_container">
            <div id="product_options_container_top"></div>
            <div class="hor-scroll">
                <form enctype="multipart/form-data" method="post" id="model_add_two" name="model_add2">

                <table cellspacing="0" class="form-list">
                    <td class="label"><label for="fonts_f_name">Model Name<span class="required">*</span></label></td>
                    <td class="value">
                        <input type="text"  name="model_name" class="input-text required-entry" id="model_name">

                    <td class="label"><label for="fonts_f_name">Status<span class="required">*</span></label></td>
                    <td class="value">
                        <select class="required-entry" id="status" name="status">
                            <option selected="selected" value="">Select Status</option>
                            <option value="1">Enable</option> 
                            <option value="0">Disable</option>                         

                    <td class="label"><label for="short_price"></label></td>
                    <td class="value">
                <input name="add_button" id="add_button" type="submit" class="scalable save"><span>Save</span></button>  </td>
          <div id="formSuccess" style="display:none;">&nbsp;</div>
          <!-- End code-->

<script type="text/javascript">
    var formId = 'model_add_two';
    var myForm = new VarienForm(formId, true);
    var postUrl = '<?php echo $_SERVER['PHP_SELF']; ?>';
    function doAjax() {
        if (myForm.validator.validate()) {
            new Ajax.Updater(
                { success:'formSuccess' }, postUrl, {
                    onComplete:function(request, json) {
                    onLoading:function(request, json){
                    parameters: $(formId).serialize(true),

    new Event.observe(formId, 'submit', function(e){

enter image description here This is what i get after these steps. 1)click on save button - validation works. 2)fill all fields. and click on save button - form doesn't get submit. What is the issue here.

  • 1
    "When i click on Save button without adding any data to fields, validation works but form doesn't submit.". What does this mean? If you don't add any data of course the form is not going to submit. Because it does not pass the validation.
    – Marius
    Nov 7, 2014 at 14:01
  • I am pretty sure you're also required to add the hidden 'formkey' for security validation.
    – tecjam
    Nov 7, 2014 at 14:06
  • Please explain "When i directly add all fields and click on save button form gets submitted. What is the issue here?" Nov 7, 2014 at 15:11
  • Where should the form be submitted to? You don't seem to have an action attribute in the form.
    – user4351
    Nov 8, 2014 at 9:31
  • i am using ajax.updater to submit the form as i have this file on root directory of magento.
    – HungryDB
    Nov 8, 2014 at 9:32

1 Answer 1


Couldn't find any solution for this. I had to use simple jQuery validation for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.