Reputation:
In my controller, i need some instructions to be launched only if a form has been sent.
This is my controller:
public function indexAction()
{
$form = array();
$submit = $this->getRequest()->getParam('submit');
if (!empty($submit))
{
$lastname = $this->getRequest()->getParam('last-name');
$name = $this->getRequest()->getParam('name');
$email = $this->getRequest()->getParam('email');
$form = array(
'lastname' => $lastname,
'name' => $name,
'email' => $email);
$confirm = Tools::checkInscription($form);
var_dump($confirm);
exit();
if ($confirm === true)
{
Tools::saveUser($form);
}
else
{
// Mets une variable a true pour savoir dans ta vu que tu as une erreur.
$this->_redirect('/inscription');
}
}
}
the problem is $submit always seems returning null.
My view:
<form id="formulaire">
<div class="msg">
<p class="error">Merci de vérifier les champs en rouge</p>
</div>
<div class="last-name">
<input type="text" class="error" id="last-name" name="last-name" placeholder="Votre nom" />
</div>
<div class="name">
<input type="text" id="name" name="name" placeholder="Votre prénom"/>
</div>
<div class="email">
<input type="text" id="email" name="email" placeholder="Votre email"/>
</div>
<button type="submit" title="Valider"></button>
</form>
Can anyone help to find what i'm doing wrong thanks in advance
Upvotes: 0
Views: 105
Reputation: 603
Try
<input type="submit" title="Valider">
instead of
<button type="submit" title="Valider"></button>
And change
<form id="formulaire" action="" method="post">
instead of
<form id="formulaire">
Upvotes: 0
Reputation: 6617
If you set your form method to POST you can check it with this:
if ($this->getRequest()->isPost()) {
}
Upvotes: 1
Reputation: 16351
Your submit button should be an input :
<input type="submit" title="Valider" />
And your form should have an action :
<form id="formulaire" method="POST" action="some_page.php">
Upvotes: 0