0

How to auto filled data, when I enter URL like xxx.com/customer/account/create?firstname=test it shows value test in firstname field as per the screenshot

enter image description here

Here is the path and code of first name.

/vendor/magento/module-customer/view/frontend/templates/widget/name.php

<div class="field field-name-firstname required">
            <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('firstname')) ?></span></label>
            <div class="control">
                <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>"
                       name="<?= $block->escapeHtmlAttr($block->getFieldName('firstname')) ?>"
                       value="<?= $block->escapeHtmlAttr($block->getObject()->getFirstname()) ?>"
                       title="<?= $block->escapeHtmlAttr($block->getStoreLabel('firstname')) ?>"
                       class="input-text <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('firstname')) ?>" <?= ($block->getAttributeValidationClass('firstname') == 'required-entry') ? ' data-validate="{required:true}"' : '' ?>>
            </div>
0

All the data for form value populating were got from $block->getFormData()

For example

<?= $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Name::class)->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>

Look into https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Customer/Block/Form/Register.php#L132 where you could populate data for your account register form.

You could plugin after into this Magento\Customer\Block\Form\Register:getFormData()

and modify the result, here your is parameter firstname you could get from Magento\Framework\App\RequestInterface

On plugin of Magento\Customer\Block\Form\Register

$subject->getRequest()->getParam('firstname');

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.