3

I have added following affiliate email field (custom attribute) to the customer registration form. Now I want to validate that if value already exists in the database table.

 <div class="control">
        <input type="text" name="affiliate_email" id="affiliate_email" value="<?= $block->escapeHtml($block->getFormData()->getCustomField()) ?>" title="<?= __('CustomField') ?>" class="input-text"  data-mage-init='{"validation":{}}'>
    </div>

What is the best way to do this ?

2 Answers 2

1

You can check that if the value is already present or not & also print it there into the input box with the below code

<div class="field custom_attribute">
    <label class="label" for="customer_attribute”><span><?php /* @escapeNotVerified */ echo __('Custom Attribute') ?></span></label>
    <div class="control">
    <?php $affiliate_email = $block->escapeHtml($block->getCustomer()->getCustomAttribute('affiliate_email')->getValue());?>
        <input type="text" name="affiliate_email" id="affiliate_email" value="<?php if(!empty($affiliate_email)){ echo $affiliate_email; } ?>" title="<?php /* @escapeNotVerified */ echo __('Custom Attribute') ?>" class="input-text" data-validate="{required:true}"/>
    </div>
</div>

It will look for that particular attribute & if it is having any value then it will add it as a value into your input field

0

Where email is your database field value.

data-validate="{required:true, 'validate-email':true,equalTo:'#email'}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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