2

Magento Admin Customer Edit フォームの Password フォーム要素を削除したいと考えています。

以下のように書き直しMage_Adminhtml_Block_Customer_Edit_Tab_Accountています。ただし、フォームから要素を削除した後でも、顧客情報タブにパスワード フィールドが表示されたままです。

<?php

require 'Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php';

class Mycompany_Mymodule_Block_Adminhtml_Customer_Edit_Tab_Account
    extends Mage_Adminhtml_Block_Customer_Edit_Tab_Account
{

    public function initForm()
    {
        $customer = parent::initForm();

        $customer->getForm()->removeField('password_fieldset');
        $customer->getForm()->removeField('new_password');

        return $customer;
    }
}

どんな助けでも大歓迎です。

編集:変更がフィールドに適用されるラベルなど、フォームフィールドの値を変更すると面倒です。たとえば、パスワード フォームのラベルを変更すると、実際にはラベルが変更されます。:o

public function initForm()
{
    $customer = parent::initForm();

    $customer->getForm()->getElement('new_password')->setLabel('Test Label');

    return $customer;
}
4

4 に答える 4

5

次のように、要素の親で removeField() を実行する必要があります。

foreach($this->getForm()->getElements() as $fieldset){
        $fieldset->removeField('id_of_desired_element');  
    }
于 2013-04-18T09:37:10.690 に答える
0

以下のコードをMage_Adminhtml_Block_Customer_Edit_Tab_Accountクラスから削除

アンダーinitForm()メソッド

if ($customer->getId()) {
            if (!$customer->isReadonly()) {
                // Add password management fieldset
                $newFieldset = $form->addFieldset(
                    'password_fieldset',
                    array('legend' => Mage::helper('customer')->__('Password Management'))
                );
                // New customer password
                $field = $newFieldset->addField('new_password', 'text',
                    array(
                        'label' => Mage::helper('customer')->__('New Password'),
                        'name'  => 'new_password',
                        'class' => 'validate-new-password'
                    )
                );
                $field->setRenderer($this->getLayout()->createBlock('adminhtml/customer_edit_renderer_newpass'));

                // Prepare customer confirmation control (only for existing customers)
                $confirmationKey = $customer->getConfirmation();
                if ($confirmationKey || $customer->isConfirmationRequired()) {
                    $confirmationAttribute = $customer->getAttribute('confirmation');
                    if (!$confirmationKey) {
                        $confirmationKey = $customer->getRandomConfirmationKey();
                    }
                    $element = $fieldset->addField('confirmation', 'select', array(
                        'name'  => 'confirmation',
                        'label' => Mage::helper('customer')->__($confirmationAttribute->getFrontendLabel()),
                    ))->setEntityAttribute($confirmationAttribute)
                        ->setValues(array('' => 'Confirmed', $confirmationKey => 'Not confirmed'));

                    // Prepare send welcome email checkbox if customer is not confirmed
                    // no need to add it, if website ID is empty
                    if ($customer->getConfirmation() && $customer->getWebsiteId()) {
                        $fieldset->addField('sendemail', 'checkbox', array(
                            'name'  => 'sendemail',
                            'label' => Mage::helper('customer')->__('Send Welcome Email after Confirmation')
                        ));
                        $customer->setData('sendemail', '1');
                    }
                }
            }
        } else {
            $newFieldset = $form->addFieldset(
                'password_fieldset',
                array('legend'=>Mage::helper('customer')->__('Password Management'))
            );
            $field = $newFieldset->addField('password', 'text',
                array(
                    'label' => Mage::helper('customer')->__('Password'),
                    'class' => 'input-text required-entry validate-password',
                    'name'  => 'password',
                    'required' => true
                )
            );
            $field->setRenderer($this->getLayout()->createBlock('adminhtml/customer_edit_renderer_newpass'));

            // Prepare send welcome email checkbox
            $fieldset->addField('sendemail', 'checkbox', array(
                'label' => Mage::helper('customer')->__('Send Welcome Email'),
                'name'  => 'sendemail',
                'id'    => 'sendemail',
            ));
            $customer->setData('sendemail', '1');
            if (!Mage::app()->isSingleStoreMode()) {
                $fieldset->addField('sendemail_store_id', 'select', array(
                    'label' => $this->helper('customer')->__('Send From'),
                    'name' => 'sendemail_store_id',
                    'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm()
                ));
            }
        }
于 2012-12-21T20:01:29.943 に答える