【问题标题】:Add field to Edit Account form in Magento在 Magento 中将字段添加到编辑帐户表单
【发布时间】:2013-05-30 17:49:44
【问题描述】:

我正在向模板 customer/form/edit.phtml 添加一个字段。我使用了这段代码:

<li>
     <?php 
         $attribute = Mage::getModel('eav/config')->getAttribute('customer','code_magique');
     ?>
     <label for="code_magique" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('Code') ?></label>
     <div class="input-box">
         <input type="text" name="code_magique" id="code_magique" value="<?php echo $this->htmlEscape($this->getCustomer()->getData("code_magique")) ?>" title="<?php echo $this->__('Code') ?>" class="input-text" />                   
     </div>
</li>

这会显示一个包含我的“code_magique”属性的字段,但是当我尝试修改此属性时,它不起作用,我是不是忘记了什么?

【问题讨论】:

  • 您将此输入添加到 magento 帐户仪表板的哪个部分?
  • “账户信息”一

标签: magento magento-1.7


【解决方案1】:

我快速浏览了AccountController.php,似乎有一些表单数据的后处理,而不是简单的$model-&gt;addData($post);

尝试挂接到customer_save_before 事件并手动添加您的数据。

希望您知道如何创建观察者并将数据添加到模型对象?

【讨论】:

  • 我知道如何创建一个观察者。要获取输入数据,我需要重写 AccountController editPostAction() 方法吗?如果你能在这部分帮助我,那就太好了>
  • 不,你没有。您只需在 customer_save_before 上创建一个观察者,收集数据模型(观察者的标准功能)并执行类似 $model-&gt;setData('my_stuff',Mage::app()-&gt;getRequest()-&gt;getParam("my_stuff")) 之类的操作即可
猜你喜欢
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-08
  • 1970-01-01
  • 2018-05-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多