Registration form error

Hi
I’m tried to followed steps from tutorial Creating pages from frontend but I’m getting an error when I send the form Call to a member function children() on boolean and this is underline :

$newRegistration = $page->find('registrations')->children()->create(str::slug($data['lastname'] . '-' . $data['firstname'] . '-' . time()) , 'register', $data);

My controller, template, and snippets are exactly like the article said. But in case, I post them here :

Controller event.php

<?php

return function($site, $pages, $page) {

    

    $alert = null;

    if(r::is('post') && get('register')) {
        if(!empty(get('website'))) {
            // lets tell the bot that everything is ok
            go($page->url());
            exit;
        }
        $data = array(
            'firstname' => esc(get('firstname')),
            'lastname'  => esc(get('lastname')),
            'company'   => esc(get('company')),
            'email'     => esc(get('email')),
            'message'   => esc(get('message'))
        );

        $rules = array(
            'firstname' => array('required'),
            'lastname'  => array('required'),
            'email'     => array('required', 'email'),
        );
        $messages = array(
            'firstname' => 'Please enter a valid first name',
            'lastname'  => 'Please enter a valid last name',
            'email'     => 'Please enter a valid email address',
        );

        // some of the data is invalid
        if($invalid = invalid($data, $rules, $messages)) {
            $alert = $invalid;
        } else {

            // everything is ok, let's try to create a new registration
            try {

                $newRegistration = $page->find('registrations')->children()->create(str::slug($data['lastname'] . '-' . $data['firstname'] . '-' . time()) , 'register', $data);

                $success = 'Your registration was successful';
                $data = array();

            } catch(Exception $e) {
                echo 'Your registration failed: ' . $e->getMessage();
            }
        }
    }

    return compact('alert', 'data', 'success');
};

Template event.php

<?php snippet('header') ?>
<main class="main" role="main">

    <div class="text">
<?php
// if the form was successfully submitted and the page created, show the success message
if(isset($success)): ?>
  <div class="message">
    <?php echo $success; ?>
  </div>
<?php endif ?>

<?php
// if the form input does not validate, show a list of alerts
if($alert): ?>
  <div class="alert">
    <ul>
      <?php foreach($alert as $message): ?>
        <li><?php echo html($message) ?></li>
      <?php endforeach ?>
    </ul>
  </div>
<?php endif ?>

<?php if(!isset($success)) {
  // if the $success variable is not set, show the form (i.e. when the page is first loaded or the form submission was not successful)
  snippet('registration-form', compact('data'));
}
?>
    </div>
</main>
<?php snippet('footer') ?>

$page->find() should be $pages->find().

I didn’t realize it was just in front of me :triumph:

I did some changes and i use it with users()->create like that :

$user = $site->users()->create(array(
                    'firstName' => strip_tags(get('firstname')),
                    'lastName'  => strip_tags(get('lastname')),
                    'username'  => strip_tags(get('username')),
                    'email'     => strip_tags(get('email')),
                    'password'  => strip_tags(get('password')),
                )); 

It’s working well, but do you advise me to use strip_tags or esc ?
One more thing : to protect the panel, I would display a role each time a registration is done, how to include it inside the controller properly ? I already have this in my config

c::set('roles', array(
    array(
        'id'      => 'admin',
        'name'    => 'Admin',
        'default' => true,
        'panel'   => true
    ),
    array(
        'id'      => 'editor',
        'name'    => 'Editor',
        'panel'   => true
    ),
    array(
        'id'      => 'client',
        'name'    => 'Client',
        'panel'   => false
    )
));

I answer to my second question : 'role' => 'client' inside the array : is it the good way ?
But the difference between strip_tags or esc ???