0

i'm new to magento. I trying to make a form to add some user to my database (not with form from magento, i need to check if the user exists in my xml file...). When I submit my form, I need to check if the user exists (it's done and working). If the user doesn't exists, I need to redirect. If it exists, i need go redirect to another form page, so that the user can sign in by adding email and password. Or (1) I have no idea how to get parameters from the first form and my redirect is not working. I have this for my first redirect (if it doesn't exists) :

$this->_redirect('connexion/connexion/index');

And this if the user exists in my xml :

$this->_redirect('connexion/connexion/Form', array('name' => $name, 'code'=>$code));

I have two views, one for the first form and the other's got only some text to see if i'm on the right page, but nothing appear on this page (no content, only footer and header).

Please i need your help PS : i'm used to Symfony but Magento seems to be pretty different :/ PS 2 : i'm using 2.2.4 version

EDIT : now my page display some content, i'm looking for how to get parameters from the previous form and redirects still not working

0

if you are trying to receive your parameters in your php file you should use the line

$variableName = $_POST['name of form input field'] ?? '';
$variableName2 = $_POST['name of form input field'] ?? '';
$variableName3 = $_POST['name of form input field'] ?? '';

do this for each of the inputs in the form.

you can then display them on the page using

echo "<p>" . $variableName . "</p>"

I hope this helps

0

In Controller File, Code would be like this.....

protected $_customerInterface;

public function __construct(\Magento\Customer\Model\Data\customer
$customerInterface,\Magento\Framework\App\Action\Context $context)

 {
  $this->_customerInterface = $customerInterface;
  parent::__construct($context);

  }

 public function execute()
{
$postvalues  = $this->getRequest()->getPost();

$postvalues['email']  /* This is Mail address of customer.*/

$mailAddress = $this->_customerInterface->getEmail();/* get Result If Customer Session exist*/

if($mailAddress == $postvalues['email'])
{
        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setPath('*/*/');// your path
        return $resultRedirect;
}
else
{
        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setPath('*/*/');your path
        return $resultRedirect;
}
 }
  • Can you please give more details ? Is that in the execute method ? Btw, when i try to use Mage, PHPStorm is saying that Mage doesn't exists – Morgan Tartreau May 23 '18 at 15:48
  • are you working on m1 or m2? – MR.R DNATH May 23 '18 at 15:55
  • I'm working with magento 2.2.4 – Morgan Tartreau May 23 '18 at 16:00
  • Hi, I will explain again, i think we don't understand each other ^^. I have my first form (with two fields, name and code). If the code exists, I want to redirect to another page with the second part of the form (with mail, password and the two values previously declared). So here i'm a bit confused, where am i suppose to use your code ? – Morgan Tartreau May 24 '18 at 7:45

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.