Question

How i can create a simple login form with HTML on Zend Framework 2, like this:

<form class="twocolumns" action="auth" method="post">
<table align="center" id="login_table">
<tr>
<td align="right"><strong>Email</strong></td>
<td align="left"><input type="text" name="username" value="" class="finput" style="width: 250px;"></td>
</tr>
<tr>
<td align="right"><strong>Password</strong></td>
<td align="left"><input type="password" name="password" class="finput" style="width: 250px;"></td>
</tr>
<tr>
<td align="right"></td>
<td align="left">Remember me <input type="checkbox" name="save_login" id="save_login" value="1"></td>
</tr>
<tr>
<td>
<button type="submit" class="fbutton green">Login</button><br>
</td>
<td align="left">
<a href="/online_contest/user/restore_password/" class="button">Forgot password</a><br>
<a href="/online_contest/user/register/" onclick="$('.popup').show(0); return(false);" class="button">Register</a><br>
</td>
</tr>
</table>
</form>

I found this. But this is not a complete solution (without tables tag (table,tr,td and other), link ):

namespace StickyNotes\Form;

use Zend\Form\Form;
use Zend\Form\Element;

class AuthorizationForm extends Form
{
public function __construct($name = null)
 {
    parent::__construct('auth');
    $this->setAttribute('method', 'post');

     $this->add(array(
         'name' => 'email',
         'attributes' => array(
             'type'  => 'text',
             'style' => 'width: 250px;',
         ),
     ));

    $this->add(array(
        'name' => 'password',
        'attributes' => array(
            'type'  => 'password',
            'style' => 'width: 250px;',
         ),
    ));

    $this->add(array(
        'name' => 'submit',
        'attributes' => array(
            'type'  => 'submit',
            'value' => 'Login',
            'id' => 'submitbutton',
            'class' => 'fbutton green',
            ),
    ));

     $this->add(array(
         'type' => 'Zend\Form\Element\Checkbox',
         'name' => 'save_login',
         'options' => array(
             'label' => 'Remember me ',
             'checked_value' => '1',
         ),
     ));
   }

}

Thanks anyone for the answer.

Was it helpful?

Solution

Create a form in your login.phtml with your html.

For Login authentication, you have to get the requested post form data (username & password) in Controller and check the credentials with your DB data when submitting a form.

Here, You have to implement a client side validation for login form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top