0

I want to have 2 different forms according to customer group, so how to do so? And how to call a controller in form:

                <form method="POST">
                    <input type="radio" name="type_profile" value="local" checked> Client Local<br>
                    <input type="radio" name="type_profile" value="export"> Client Export<br>
                    <input type="submit" name="submit" value="create new account " />
                </form>
                <?php
                if (isset($_POST['submit'])) {
                    if(isset($_POST['type_profile']))
                    {
                        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                        $redirect = $objectManager->get('\Magento\Framework\App\Response\Http');

                        if($_POST['type_profile']=="local") {
                            $redirect->setRedirect('http://localhost/Selecta/customer/account/create/');
                            //echo "You have selected : local";
                        }else if($_POST['type_profile']=="export") {
                            //echo "You have selected :export";
                            $redirect->setRedirect('http://localhost/Selecta/customer/account/create2/');

                        }
                    }}
                ?>
0

Call controller in form.

  1. Add Form tag like this in phtml file:

    <form action="<?php echo $block->getFormAction() ?>" method="post">
    
  2. Add function in block file like this:

    public function getFormAction()
    {
      return '/companymodule/controller_name/action'
    }
    

For more details you can refer to this link: How to Create Custom Form in Magento2

  • thanks it seems to be helpfull t will test that – Developper Magento Oct 22 '18 at 13:54
  • just one question how to do to enable customer from groups2 to register from this form is there something extra to do when creating the new form – Developper Magento Oct 22 '18 at 13:55
  • nothing happened so can you please explain more what to put in getFormAction and how to call the inscription form – Developper Magento Oct 22 '18 at 14:13
  • You need to open your block file then add new function like getFormAction() in that you have to return your action path like this (/your module/controller_name/action) – Jitendra Patel Oct 22 '18 at 14:21

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.