VarieForm不适用于magento 1.9.2社区版


VarienForm not working in magento 1.9.2 community edition

你好,我正在用magento开发一个登录和注册表单。对于表单验证,我使用此代码

var registerForm = new VarienForm('register-form', true);
var loginForm = new VarienForm('login-form', true);
if (this.validator && this.validator.validate()) {
    this.form.submit();
}

当我在带有script标记的phtml中使用这段代码时,它是有效的,但当我把它放在js中并通过xml调用时,它不起作用,这是我的xml代码

<custom_abc_index>
    <reference name="root">
        <action method="setTemplate">
            <template>page/1column.phtml</template>
        </action>
    </reference>
   <reference name="head">
        <action method="addItem">
            <type>skin_js</type>
            <name>js/custom_abc/customLoginRegister.js</name>
        </action>
    </reference>
    <reference name="content">
        <block type="custom_abc/custom" name="custom" template="custom_abc/Custom.phtml"></block>
    </reference>

</custom_abc_index>

为了检查js是否正在加载,我在里面放了alert(),我得到了弹出窗口,但我不知道为什么验证代码不起作用。任何帮助都是可观的。

如果你想要简单的验证,你可以在内置的验证类表单验证中使用magento

请参阅此

表单验证类