0

I want to change the firstname and lastname field validation in registration form.

I want first name and last name should be only characters with maxlength 15.

And in which file I can find the code for first name and last name.

How can I?

2 Answers 2

1

You need to change in below files for validation of firstname and last name

Copy file from

app/design/frontend/base/default/template/customer/widget/name.phtml

to

app/design/frontend/Your-Theme/Your-Package/template/customer/widget/name.phtml

change as per your requirement

add validation in

js/prototype/validation.js

I suggest you to add validation add your own class to that field and create validation for it.

0
0

To put desired validation on input fields. You can do following changes.

Copy file from app/design/frontend/base/default/template/customer/widget/name.phtml to app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/customer/widget/name.phtml

Add maxlength="15" attribute in your input tag like following and Add css class validate-length maximum-length-15 in your firstname and lastname input tags.

Add following code in app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/customer/widget/name.phtml file :

<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 Mage::helper('core')->quoteEscape($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 Mage::helper('core')->quoteEscape($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">
            <input type="text" id="<?php echo $this->getFieldId('firstname')?>" name="<?php echo $this->getFieldName('firstname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getFirstname()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('firstname')) ?>" maxlength="15" class="input-text validate-length maximum-length-15 <?php echo $this->helper('customer/address')->getAttributeValidationClass('firstname') ?>" <?php echo $this->getFieldParams() ?> />
        </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">
            <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; ?>
    <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">
            <input type="text" id="<?php echo $this->getFieldId('lastname')?>" name="<?php echo $this->getFieldName('lastname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getLastname()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('lastname')) ?>" maxlength="15" class="input-text validate-length maximum-length-15 <?php echo $this->helper('customer/address')->getAttributeValidationClass('lastname') ?>" <?php echo $this->getFieldParams() ?> />
        </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 Mage::helper('core')->quoteEscape($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 Mage::helper('core')->quoteEscape($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>

Hope it helps

3
  • In which file I need to change? I am not able to find that firstname and lastname field in file Mar 7, 2016 at 7:12
  • First tell: what you want to do?. Update your question with proper requirements Mar 7, 2016 at 7:13
  • @Jatin Try my code. It will work. Mar 7, 2016 at 7:50

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.