2

If it is possible Customer Middle Name/Initial is required, Now I use this code to required this field but can not work

<?php if ($this->showMiddlename()): ?>
<?php $isMiddlenameRequired = $this->isMiddlenameRequired(); ?>
    <div class="field name-middlename">
        <label for="<?php echo $this->getFieldId('middlename')?>"><em>*</em><?php echo $isMiddlenameRequired ? ' class="required"' : '' ?><?php echo $isMiddlenameRequired ? '<em>*</em>' : '' ?><?php echo $this->getStoreLabel('middlename') ?></label>
        <div class="input-box">
            <input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->escapeHtml($this->getObject()->getMiddlename()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('middlename')) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('middlename') ?>" <?php echo $this->getFieldParams() ?> />
        </div>
    </div>
<?php endif; ?>

so if any suggestions guy's so, please tell me. Thanks.

3

Adding required-entry in the class attribute of the input field will make the field required.

Try to add below code

<input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->htmlEscape($this->getObject()->getMiddlename()) ?>" title="<?php echo $this->getStoreLabel('middlename') ?>" class="input-text required-entry" <?php echo $this->getFieldParams() ?> />
  • 1
    Hi @sumit Thanks for the helping this code is work now. – Rohit Gohel Sep 26 at 7:57
3

To make the the middle name required add

class="input-text required-entry"

something like this :

<input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->htmlEscape($this->getObject()->getMiddlename()) ?>" title="<?php echo $this->getStoreLabel('middlename') ?>" class="input-text required-entry" <?php echo $this->getFieldParams() ?> />
  • Hi @Yigen Also, thank you for the right answer you are also right. – Rohit Gohel Sep 26 at 7:58
  • Glad it helped ! – Ylgen Guxholli Sep 26 at 8:00
  • 1
    +1 for the right answer. – Sumit Sep 26 at 9:04
  • 1
    Thank you Sumit – Ylgen Guxholli Sep 26 at 9:34

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.