I'm trying to just make a tiny little modification to see if I can get Phalcon to work so I'm using the Invo application and all I'm trying to do is change the registration so that instead of using "full name", which is "name" in the app, to use first_name so that I can then eventually add "last_name" ****however after making a few edits, the app now complains "Something went wrong, if the error continue please contact us" when I try to submit the form with no data. Prior to the edits it would complain that full name was empty.
When I look in the Apache error log, there are no errors listed that would inidicate why a 500 error occured. It's as if the app iteslf is masquerading it's own error as an error 500.
I've changed the file RegisterForm.php thusly
<?php
use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Password;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Email;
class RegisterForm extends Form
{
public function initialize($entity = null, $options = null)
{
// Name
$first_name = new Text('first_name');
$first_name->setLabel('Your Full Name');
$first_name->setFilters(array('striptags', 'string'));
$first_name->addValidators(array(
new PresenceOf(array(
'message' => 'Name is required'
))
));
$this->add($first_name);
// Name
$name = new Text('username');
$name->setLabel('Username');
$name->setFilters(array('alpha'));
$name->addValidators(array(
new PresenceOf(array(
'message' => 'Please enter your desired user name'
))
));
$this->add($name);
// Email
$email = new Text('email');
$email->setLabel('E-Mail');
$email->setFilters('email');
$email->addValidators(array(
new PresenceOf(array(
'message' => 'E-mail is required'
)),
new Email(array(
'message' => 'E-mail is not valid'
))
));
$this->add($email);
// Password
$password = new Password('password');
$password->setLabel('Password');
$password->addValidators(array(
new PresenceOf(array(
'message' => 'Password is required'
))
));
$this->add($password);
// Confirm Password
$repeatPassword = new Password('repeatPassword');
$repeatPassword->setLabel('Repeat Password');
$repeatPassword->addValidators(array(
new PresenceOf(array(
'message' => 'Confirmation password is required'
))
));
$this->add($repeatPassword);
}
}
For the file RegisterController.php I've changed it thusly:
<?php
/**
* SessionController
*
* Allows to register new users
*/
class RegisterController extends ControllerBase
{
public function initialize()
{
$this->tag->setTitle('Sign Up/Sign In');
parent::initialize();
}
/**
* Action to register a new user
*/
public function indexAction()
{
$form = new RegisterForm;
if ($this->request->isPost()) {
$first_name = $this->request->getPost('first_name', array('string', 'striptags'));
$email = $this->request->getPost('email', 'email');
$password = $this->request->getPost('password');
$repeatPassword = $this->request->getPost('repeatPassword');
if ($password != $repeatPassword) {
$this->flash->error('Passwords are diferent');
return false;
}
$user = new Users();
$user->password = sha1($password);
$user->first_name = $first_name;
$user->email = $email;
$user->created_at = new Phalcon\Db\RawValue('now()');
$user->active = 'Y';
if ($user->save() == false) {
foreach ($user->getMessages() as $message) {
$this->flash->error((string) $message);
}
} else {
$this->tag->setDefault('email', '');
$this->tag->setDefault('password', '');
$this->flash->success('Thanks for sign-up, please log-in to start generating invoices');
return $this->forward('session/index');
}
}
$this->view->form = $form;
}
}
For the file index.volt in /views/register/index.volt, I changed it thusly:
{{ content() }}
<div class="page-header">
<h2>Register for INVO</h2>
</div>
{{ form('register', 'id': 'registerForm', 'onbeforesubmit': 'return false') }}
<fieldset>
<div class="control-group">
{{ form.label('first_name', ['class': 'control-label']) }}
<div class="controls">
{{ form.render('first_name', ['class': 'form-control']) }}
<p class="help-block">(required)</p>
<div class="alert alert-warning" id="first_name_alert">
<strong>Warning!</strong> Please enter your full name
</div>
</div>
</div>
<div class="control-group">
{{ form.label('username', ['class': 'control-label']) }}
<div class="controls">
{{ form.render('username', ['class': 'form-control']) }}
<p class="help-block">(required)</p>
<div class="alert alert-warning" id="username_alert">
<strong>Warning!</strong> Please enter your desired user name
</div>
</div>
</div>
<div class="control-group">
{{ form.label('email', ['class': 'control-label']) }}
<div class="controls">
{{ form.render('email', ['class': 'form-control']) }}
<p class="help-block">(required)</p>
<div class="alert alert-warning" id="email_alert">
<strong>Warning!</strong> Please enter your email
</div>
</div>
</div>
<div class="control-group">
{{ form.label('password', ['class': 'control-label']) }}
<div class="controls">
{{ form.render('password', ['class': 'form-control']) }}
<p class="help-block">(minimum 8 characters)</p>
<div class="alert alert-warning" id="password_alert">
<strong>Warning!</strong> Please provide a valid password
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="repeatPassword">Repeat Password</label>
<div class="controls">
{{ password_field('repeatPassword', 'class': 'input-xlarge') }}
<div class="alert" id="repeatPassword_alert">
<strong>Warning!</strong> The password does not match
</div>
</div>
</div>
<div class="form-actions">
{{ submit_button('Register', 'class': 'btn btn-primary', 'onclick': 'return SignUp.validate();') }}
<p class="help-block">By signing up, you accept terms of use and privacy policy.</p>
</div>
</fieldset>
</form>