0

I used zfc user module for authentication of user in zend framework2,But it does not show username field at registration form but it does not show username field and give error:

Statement could not be executed (23000 - 1048 - Column 'username' cannot be null)

here is my registration.phtml:

<h1>Registration</h1>

 <?php
if (!$this->enableRegistration) {
print "Registration is disabled";
return;
}
 $form = $this->registerForm;
$form->prepare();
$form->setAttribute('action', $this->url('zfcuser/register'));
$form->setAttribute('method', 'post');
?>

<?php echo $this->form()->openTag($form) ?>
<dl class="zend_form">
<?php foreach ($form as $element): ?>
    <?php if (!$element instanceof Zend\Form\Element\Button): ?>
        <dt><?php echo $this->formLabel($element) ?></dt>
    <?php endif ?>
    <?php if ($element instanceof Zend\Form\Element\Button): ?>
        <dd><?php echo $this->formButton($element) ?></dd>
    <?php elseif ($element instanceof Zend\Form\Element\Captcha): ?>
        <dd><?php echo $this->formCaptcha($element) . $this->formElementErrors($element) ?></dd>
    <?php else: ?>
        <dd><?php echo $this->formInput($element) . $this->formElementErrors($element) ?></dd>
    <?php endif ?>
<?php endforeach ?>
</dl>
<?php if ($this->redirect): ?>
    <input type="hidden" name="redirect" value="<?php echo $this->escapeHtml($this->redirect) ?>" />
<?php endif ?>
<?php echo $this->form()->closeTag() ?>

Can i enable username field on registration form?

Muhammad Arif
  • 1,014
  • 3
  • 22
  • 56

1 Answers1

1

Check your config/autoload/zfcuser.global.php and change the value to true:

     /** 
     * Enable Username
     *
     * Enables username field on the registration form, and allows users to log
     * in using their username OR email address. Default is false.
     *
     * Accepted values: boolean true or false
     */
    'enable_username' => true,

Now you should be able to see that field.

Edit: The state field is in the same file.

     /**
     * Enable user state usage
     * 
     * Should user's state be used in the registration/login process?
     */
    'enable_user_state' => false,

if you want it to be in your form's add true else false.

cptnk
  • 2,430
  • 18
  • 29
  • thanks i tried this but this error Statement could not be executed (23000 - 1048 - Column 'state' cannot be null) can you help to solve this error? – Muhammad Arif Mar 31 '14 at 08:12
  • I edited my answer. You might want to take a look at the whole config File to get a understanding of what you can enable or disable if you have further field troubles. – cptnk Mar 31 '14 at 08:27
  • thanks i changed my code according to your code but another error exist Statement could not be executed (23000 - 1048 - Column 'user_id' cannot be null) how i remove this warning? – Muhammad Arif Mar 31 '14 at 08:31
  • that one is strange are you sure you configured zfc probably? Are you overriding some of the zfc stuff? – cptnk Mar 31 '14 at 09:06
  • does your user_id field have an auto_increment? – cptnk Apr 01 '14 at 07:42