1

I am using magento version 1.9.2.3.

In,edit account information section, i would not like to provide the fields first name and last name as editable.

How could i change that?

enter image description here

0

Quick Solution,using a JavaScript make those fields as readonly.

Assume that file name is disable.js

   document.getElementById("firstname").setAttribute("readonly", "true")
  document.getElementById("lastname").setAttribute("readonly", "true")
  document.getElementById("middlename").setAttribute("readonly", "true")

Then call this files at customer.xml under customer_account_edit

<reference name="head">
<action method="addJs">
                <script>js/disable.js</script>
</action>
</<reference>

And put this disable.js at app/skin/frontend/[Your_Package]/[Your_Theme]/js

1

You can edit the name.phtml from frontend/base/default/template/customer/widget/name.phtml (you want to find the correct path of your installation).

You can change the text box type to hidden and show the name as a label.

<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>

Its just an idea.

1

Open edit.phtml from app/design/frontend/theme_package/theme/template/customer/form/ or Copy it from here in your theme app/design/frontend/base/default/template/customer/form/ and find this line:

 <?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?>

replace this line with following code:

<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>

Save the file clear the cache done!

0

Go to app/design/frontend/Your-Package/Your-Theme/template/customer/form/edit.phtml

Find below code:

<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?>

Replace with:

<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>

Above code will disable first name and last name in account edit page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.