0

我正在通过 login.phtml 修改我的登录/注册表单,当我使用图像按钮而不是标准 css 按钮时,“创建帐户”按钮出现问题。

我修改了这个原始代码

               <button type="button" title="<?php echo $this->__('Create an Account') ?>" class="button" onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>';"><span><span><?php echo $this->__('Create an Account') ?></span></span></button>

  <input type="image" src="http://localhost/magento/skin/frontend/default/mytemplate/images/button-createaccount.png" title="<?php echo $this->__('Create an Account') ?>"  onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>';">

并将按钮移动到右侧浮动“创建帐户”div的“内容”div中。该按钮显示正确,但每次单击创建帐户时,我的浏览器都会在左侧浮动“登录”div 中突出显示登录表单的必填字段,然后继续创建帐户页面。

当我单击原始的 css 创建帐户按钮时,在页面的下部(在另一个 div 中,既不是登录的一部分,也不是创建帐户 div)浏览器继续正确地继续,而不首先突出显示表单字段。这是否与 div 中按钮的位置或 window.location 方法有关?

这是完整的代码:

<div class="account-login"> <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
  <form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
    <div class="col2-set">
    <div class="col-2 new-users">
      <div class="content"> <?php echo $this->__('New Customers') ?>
        <p><?php echo $this->__('By creating an account with our store, you will be able to move through the checkout process faster, store multiple shipping addresses, view and track your orders in your account and more.') ?></p>
        <!-- Insert image button for Create Account in new div class "button" -->
        <div class="button">
          <input type="image" src="http://localhost/magento/skin/frontend/default/mytemplate/images/button-createaccount.png" title="<?php echo $this->__('Create an Account') ?>"  onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>';">
        </div>
        <!-- End Insert image button for Create Account in new div class "button"  --> 
      </div>
    </div>
    <div class="col-1 registered-users">
      <div class="content">
        <h2><?php echo $this->__('Registered Customers') ?></h2>
        <p><?php echo $this->__('If you have an account with us, please log in.') ?></p>
        <ul class="form-list">
          <li>
            <label for="email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
            <div class="input-box">
              <input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
            </div>
          </li>
          <li>
            <label for="pass" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
            <div class="input-box">
              <input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
            </div>
          </li>
          <?php echo $this->getChildHtml('persistent.remember.me'); ?>
        </ul>
        <?php echo $this->getChildHtml('persistent.remember.me.tooltip'); ?> 
        <!-- Insert image button for Login in div class "button" -->
        <div class="button">
          <input type="image" src="http://localhost/magento/skin/frontend/default/mytemplate/images/button-login.png" title="<?php echo $this->__('Login') ?>" name="send" id="send2">
        </div>
        <!-- End Insert image button for Login in div class "button" -->
        <div class="buttons-set"> <a href="<?php echo $this->getForgotPasswordUrl() ?>" class="f-left"><?php echo $this->__('Forgot Your Password?') ?></a> </div>
      </div>
    </div>
    <div class="col2-set">
      <div class="col-2 new-users">
        <div class="buttons-set">
          <button type="button" title="<?php echo $this->__('Create an Account') ?>" class="button" onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>';"><span><span><?php echo $this->__('Create an Account') ?></span></span></button>
        </div>
      </div>
      <div class="col-1 registered-users">
        <div class="buttons-set"> <a href="<?php echo $this->getForgotPasswordUrl() ?>" class="f-left"><?php echo $this->__('Forgot Your Password?') ?></a>
          <button type="submit" class="button" title="<?php echo $this->__('Login') ?>" name="send" id="send2"><span><span><?php echo $this->__('Login') ?></span></span></button>
        </div>
      </div>
    </div>
    <?php if (Mage::helper('checkout')->isContextCheckout()): ?>
    <input name="context" type="hidden" value="checkout" />
    <?php endif; ?>
  </form>
  <script type="text/javascript">
               var dataForm = new VarienForm('login-form', true);
    </script> 
</div>
4

1 回答 1

1

您遇到了他的问题,因为表单是在 javascript 中作为 Varien_Form 启动的:

<script type="text/javascript">
    var dataForm = new VarienForm('login-form', true);
</script>

这有许多默认行为,当它遇到它不期望的按钮和元素时,这些行为显然表现得很奇怪。这些是在 Magento 的 js 库中的某个地方定义的。

希望这有助于为您指明正确的方向。

于 2012-05-10T03:12:04.587 回答