如何在帐户信息中不可编辑的firstname,middlename和last name
-
29-09-2020 - |
解决方案
快速解决方案,使用 一个JavaScript使这些字段 作为 readonly
.
假设文件名是禁用的。js的
document.getElementById("firstname").setAttribute("readonly", "true")
document.getElementById("lastname").setAttribute("readonly", "true")
document.getElementById("middlename").setAttribute("readonly", "true")
然后调用此文件 customer.xml
下 customer_account_edit
<reference name="head">
<action method="addJs">
<script>js/disable.js</script>
</action>
</<reference>
把这个禁用。js在 app/skin/frontend/[Your_Package]/[Your_Theme]/js
其他提示
您可以编辑 name.phtml
从 frontend/base/default/template/customer/widget/name.phtml
(要查找安装的正确路径)。
您可以将文本框类型更改为隐藏并将名称显示为标签。
<div class="field name-firstname">
<label for="<?php echo $this->getFieldId('firstname') ?>" class="required"><em>*</em><?php echo
$this->getStoreLabel('firstname') ?></label>
<div class="input-box"><?php echo
$this->escapeHtml($this->getObject()->getFirstname()) ?>
//just show the name and make the text box hidden
<input type="hidden" id="<?php echo $this->getFieldId('firstname') ?>" name="<?php echo
$this->getFieldName('firstname') ?>" value="<?php echo
$this->escapeHtml($this->getObject()->getFirstname()) ?>" title="<?php
echo $this->getStoreLabel('firstname') ?>" maxlength="255"
class="input-text <?php echo
$this->helper('customer/address')->getAttributeValidationClass('firstname') ?>" <?php echo $this->getFieldParams() ?> />
</div>
</div>
.
它只是一个想法。
打开 edit.phtml
从 app/design/frontend/theme_package/theme/template/customer/form/
或者从这里复制它在你的主题 app/design/frontend/base/default/template/customer/form/
找到这条线:
<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?>
将此行替换为以下代码:
<div class="field name-firstname">
<label class="required" for="firstname"><em>*</em>First Name</label>
<div class="input-box">
<input type="text" class="form-control input-text required-entry" maxlength="255" title="First Name"
value="<?php echo Mage::getSingleton('customer/session')->getCustomer()->getFirstname(); ?>"
name="firstname" id="firstname" readonly>
</div>
</div>
<div class="field name-lastname">
<label class="required" for="lastname"><em>*</em>Last Name</label>
<div class="input-box">
<input type="text" class="form-control input-text required-entry" maxlength="255" title="Last Name"
value="<?php echo Mage::getSingleton('customer/session')->getCustomer()->getLastname() ?>"
name="lastname" id="lastname" readonly>
</div>
</div>
保存文件清除缓存完成!
前往 app/design/frontend/Your-Package/Your-Theme/template/customer/form/edit.phtml
找到下面的代码:
<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?>
替换为:
<div class="<?php echo $this->getContainerClassName() ?>">
<?php if ($this->showPrefix()): ?>
<div class="field name-prefix">
<label
for="<?php echo $this->getFieldId('prefix') ?>"<?php if ($this->isPrefixRequired()) echo ' class="required"' ?>><?php if ($this->isPrefixRequired()) echo '<em>*</em>' ?><?php echo $this->getStoreLabel('prefix') ?></label>
<div class="input-box">
<?php if ($this->getPrefixOptions() === false): ?>
<input type="text" id="<?php echo $this->getFieldId('prefix') ?>"
name="<?php echo $this->getFieldName('prefix') ?>"
value="<?php echo $this->escapeHtml($this->getObject()->getPrefix()) ?>"
title="<?php echo $this->getStoreLabel('prefix') ?>"
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?> />
<?php else: ?>
<select id="<?php echo $this->getFieldId('prefix') ?>"
name="<?php echo $this->getFieldName('prefix') ?>"
title="<?php echo $this->getStoreLabel('prefix') ?>"
class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?>>
<?php foreach ($this->getPrefixOptions() as $_option): ?>
<option
value="<?php echo $_option ?>"<?php if ($this->getObject()->getPrefix() == $_option): ?> selected="selected"<?php endif; ?>><?php echo $this->__($_option) ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<div class="field name-firstname">
<label for="<?php echo $this->getFieldId('firstname') ?>"
class="required"><em>*</em><?php echo $this->getStoreLabel('firstname') ?></label>
<div class="input-box">
<?php echo $this->escapeHtml($this->getObject()->getFirstname()) ?>
</div>
</div>
<?php if ($this->showMiddlename()): ?>
<?php $isMiddlenameRequired = $this->isMiddlenameRequired(); ?>
<div class="field name-middlename">
<label
for="<?php echo $this->getFieldId('middlename') ?>"<?php echo $isMiddlenameRequired ? ' class="required"' : '' ?>><?php echo $isMiddlenameRequired ? '<em>*</em>' : '' ?><?php echo $this->getStoreLabel('middlename') ?></label>
<div class="input-box">
<?php echo $this->getFieldName('middlename') ?>"
value="<?php echo $this->escapeHtml($this->getObject()->getMiddlename()) ?>
</div>
</div>
<?php endif; ?>
<div class="field name-lastname">
<label for="<?php echo $this->getFieldId('lastname') ?>"
class="required"><em>*</em><?php echo $this->getStoreLabel('lastname') ?></label>
<div class="input-box">
<?php echo $this->escapeHtml($this->getObject()->getLastname()) ?>
</div>
</div>
<?php if ($this->showSuffix()): ?>
<div class="field name-suffix">
<label
for="<?php echo $this->getFieldId('suffix') ?>"<?php if ($this->isSuffixRequired()) echo ' class="required"' ?>><?php if ($this->isSuffixRequired()) echo '<em>*</em>' ?><?php echo $this->getStoreLabel('suffix') ?></label>
<div class="input-box">
<?php if ($this->getSuffixOptions() === false): ?>
<input type="text" id="<?php echo $this->getFieldId('suffix') ?>"
name="<?php echo $this->getFieldName('suffix') ?>"
value="<?php echo $this->escapeHtml($this->getObject()->getSuffix()) ?>"
title="<?php echo $this->getStoreLabel('suffix') ?>"
class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('suffix') ?>" <?php echo $this->getFieldParams() ?> />
<?php else: ?>
<select id="<?php echo $this->getFieldId('suffix') ?>"
name="<?php echo $this->getFieldName('suffix') ?>"
title="<?php echo $this->getStoreLabel('suffix') ?>"
class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('suffix') ?>" <?php echo $this->getFieldParams() ?>>
<?php foreach ($this->getSuffixOptions() as $_option): ?>
<option
value="<?php echo $_option ?>"<?php if ($this->getObject()->getSuffix() == $_option): ?> selected="selected"<?php endif; ?>><?php echo $this->__($_option) ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
上面的代码将禁用帐户编辑页面中的名字和姓氏.