Something went wrong, if the error continue please contact us

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>


1.1k
edited Oct '15

OK, lets try this comment again. Hopefully it won't log me out like it did last time and then make me re-type the whole darn thing again. This forum using Phalcon by chance? Anyway, I found that the app is in fact faking the 500 error, hence why there's nothing in the apache error log. I also found that the error is being generated during the save attempt, which is where I presume the validation is taking place. How do I troubleshoot the save issue?

Here's the code from the RegisterController.php file.

if ($user->save() == false) {
             die("after trying to save.");  
                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');
            }
edited Oct '15

there is lots of code and I can't see what can be wrong. I recommend you using xdebug and go step by step to see where the application crashes. That's a good way to debug everything in php.

If you don't want to use xdebug try uncommenting parts of the code on controller, form, model, do var_dump(); die;. Also you have some function in model that you can use beforeSave, beforeUpdate, beforeInsert. Use them and do some var_dump(); die;. This way you'll know if the application gets there and what returns.

https://docs.phalconphp.com/en/latest/reference/models.html#initializing-preparing-fetched-records

P.S.: the forum is written in phalcon using Phalcon 2.0.8

https://github.com/phalcon/forum