2015-10-14 23 views
0

我有一个登录表单。如果我提交它而没有输入任何内容,则应该在输入字段上出现错误消息。如何访问并创建错误消息

如何从magento控制器访问错误消息?我应该如何编程消息?

<form action="<?php echo $this->getPostActionUrl() ?>" method="post"> 
     <?php echo $this->getBlockHtml('formkey'); ?> 
     <div class="block-content"> 
    <?php echo $this->__('Save your Designs');?><br>&nbsp;<br> 
      <div class="col-reg registered-account"> 
       <div class="email-input"> 
     <label for="mini-login" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label> 
        <input title="<?php echo $this->__('User Name')?>" type="text" name="login[username]" id="mini-login" class="required-entry input-text" value="<?php echo $this->__('User Name')?>" onFocus="if(this.value != '') {this.value = '';}" onBlur="if (this.value == '') {this.value = '<?php echo $this->__('User Name')?>';}" /> 
       </div> 
       <div class="pass-input"> 
     <label for="mini-password" class="required"><em>*</em>test<?php echo $this->__('Password') ?></label> 
        <input title="<?php echo $this->__('Password')?>" type="password" name="login[password]" id="mini-password" class="input-text required-entry" value="........." onFocus="if(this.value != '') {this.value = '';}" onBlur="if (this.value == '') {this.value = '.........';}" /> 
       </div> 
       <!--<div class="ft-link-p"> 
        <a title="<?php echo $this->__('Forgot your password?')?>" href="<?php echo $this->getForgotPasswordUrl() ?>" class="f-left" target="_blank"><?php echo $this->__('Forgot your password?') ?></a> 
       </div>--> 
       <div class="actions"> 
        <div class="submit-login"> 
         <input title="<?php echo $this->__('Login')?>" type="submit" class="button btn-submit-login" name="submit" value="<?php echo $this->__('LOGIN') ?>" /> 
        </div> 
       </div> 

      </div> 
      <div class="col-reg login-customer"> 
       <h2><?php echo $this->__('Registration is free and easy!');?></h2> 
       <br> 
       <ul class="list-log"> 
        <li><?php echo $this->__('Faster checkout');?></li> 
        <li><?php echo $this->__('save your own designs');?></li> 
        <li><?php echo $this->__('View and track orders and more');?></li> 
       </ul> 
       <a class="btn-reg-popup" title="<?php echo $this->__('Register')?>" href="<?php echo $this->getUrl('customer/account/create')?>"><?php echo $this->__('Create an account');?></a> 
      </div> 
      <div style="clear:both;"></div> 
     </div> 
    </form> 

回答

0

包括以下脚本PHTML文件

<script type="text/javascript"> 
//<![CDATA[ 
var Form = new VarienForm('formid', true); 
//]]> 
</script> 
to access in controller use 

if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) { 
    $error = true; 
} 
if ($error) { 
    throw new Exception(); 
} 
+0

对不起,在至极控制器文件我已经把它在至极位置? – Rene