1

I have put the form for add new address of Address book in address book index page itself without redirecting it to a new page for adding a new address. I need to open the form html on click of add address without changing the url and redirecting to the http://localhost/customer/address/new/ instead i want to remain in http://localhost/customer/address/ page

1) http://localhost/customer/address/ page UI enter image description here

2) on clicking + Add New Address i need to put the html of the form which is at http://localhost/customer/address/new/ url

enter image description here

So that Save button will work exactly like as it will in /address/new url form.

How to achieve this.

Since address has /** @var \Magento\Customer\Block\Address\Book $block */ and address new has /** @var \Magento\Customer\Block\Address\Edit $block */ block, so i cannot just put the form phtml from edit.phtml to book.phtml

I cannot put edit.phtml form code in book.phtml it throw error as in edit.phtml has it down block

<?php $_company = $block->getLayout()- 
>createBlock(\Magento\Customer\Block\Widget\Company::class) ?>
<?php $_telephone = $block->getLayout()- 
>createBlock(\Magento\Customer\Block\Widget\Telephone::class) ?>
<?php $_fax = $block->getLayout()- 
>createBlock(\Magento\Customer\Block\Widget\Fax::class) ?>

codes like this throw error

<?php if ($_company->isEnabled()): ?>
        <?= $_company->setCompany($block->getAddress()->getCompany())->toHtml() ?>
    <?php endif ?>

where $_company variable is being used

1

Add These code in your phtml

 <button>Add New Address</button>

<div class="address" style="display:none">
Your phtml code for new ADDRESS
<div>

<script>
$(document).ready(function(){
  $("button").click(function(){
    $(".address").toggle();
  });
});
</script>

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.