How to get child page panel url?

Hi, I am making registration using https://getkirby.com/docs/cookbook/forms/creating-pages-from-frontend, also added sending email to admin after submission. Admin gets information about submission (child of “event” page). And then after confirmation (changing status from Draft to Unlisted), this submission (event child) is published publicly.

What is missing is easy way to confirm submissions. So I would like to include link to edit that sub-page.

I understand how to get information about event:

$data = [
    
    'pageurl' => $page->uri(),
    'pagetitle' => $page->title()

, but can’t figure out how to get the same about submissions (children of event)

You can get the Panelurl with $page->panelUrl(). But not sure I understand your question.

Yes, thank you, this is clear. The question is how to get this link not for event, but for child of event?

But in which context? In the moment you create the new page ($registration in the cookbook example, you have access to this page and could then send this information in the email).

I made sending of email in the moment of creating new page. So I would like to include link to that registration (child of event page) in panel (so that admin can go directly to registration with one click and confirm it).

I think it would be helpful if you post your code, if $registration->panelUrl() doesn’t help.

<?php

return function ($kirby, $page) {

    // if the form has been submitted…
    if ($kirby->request()->is('POST') && get('register')) {

        // check the honeypot and exit if is has been filled in
        if(empty(get('website')) === false) {
            go($page->url());
            exit;
        }

        $data = [
            'name'    => get('name'),
            'surname'    => get('surname'),
            'email'   => get('email'),
            'birthdate'    => get('birthdate'),
            'group'  => get('group'),
            'city'    => get('city'),
            'club'    => get('club'),
            'phone'   => get('phone'),
            'message' => get('message'),
            'newsletter' => get('newsletter'),
            'pageurl' => $page->uri(),
            'pagetitle' => $page->title(),
        ];

        $rules = [
            'name'  => ['required'],
            'surname'  => ['required'],
            'email' => ['required', 'email'],
        ];

        $messages = [
            'name'  => 'Please enter your (link: #name text: name)',
            'surname'  => 'Please enter your (link: #surname text: surname)',
            'email' => 'Please enter a valid (link: #email text: email address)',
        ];

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



        } else {


            // authenticate as almighty
            $kirby->impersonate('kirby');

            // everything is ok, let's try to create a new registration
            try {
                // we store registrations as subpages of the current page
                $registration = $page->createChild([
                    'slug'     => md5(str::slug($data['name'] . microtime())),
                    'template' => 'registration',
                    'content'  => $data
                ]);
                
                

                $kirby->email([
                    'template' => 'reg',
                    'from'     => 'from@example.com',
                    'replyTo'  => $data['email'],
                    'to'       => 'to@example.com',
                    'subject'  => esc($data['name']) .' '.  esc($data['surname']) . ' nauja registracija',
                    'data'     => [
                        'text'   	=> esc($data['text']),
                        'name' 		=> esc($data['name']),
                        'surname' 	=> esc($data['surname']),
                        'group' 	=> esc($data['group']),
                        'club' 	=> esc($data['club']),
                        'city' 	=> esc($data['city']),
                        'birthdate' 	=> esc($data['birthdate']),
                        'email' 	=> esc($data['email']),
                        'phone' 	=> esc($data['phone']),
                        'pageurl' 	=> esc($data['pageurl']),
                        'pagetitle' 	=> esc($data['pagetitle'])
                        
                    ]
                ]);
                
                
                

                if ($registration) {
                    // store referer and name in session
                    $kirby->session()->set([
                        'referer' => $page->uri(),
                        'regName'  => esc($data['name'])
                    ]);
                    go('success');
                }

            } catch (Exception $e) {
                $alert = ['Your registration failed: ' . $e->getMessage()];
            }
        }
    }
    
    


    // return data to template
    return [
        'alert' => $alert ?? null,
        'data'  => $data ?? false,
    ];
};

Then you can add it here:

'data'     => [
                        'text'   	=> esc($data['text']),
                        'name' 		=> esc($data['name']),
                        'surname' 	=> esc($data['surname']),
                        'group' 	=> esc($data['group']),
                        'club' 	=> esc($data['club']),
                        'city' 	=> esc($data['city']),
                        'birthdate' 	=> esc($data['birthdate']),
                        'email' 	=> esc($data['email']),
                        'phone' 	=> esc($data['phone']),
                        'pageurl' 	=> esc($data['pageurl']),
                        'pagetitle' 	=> esc($data['pagetitle']),
                        'registrationlink' => $registration? $registration->panelUrl() : null
                        
                    ]

Thanks, also just now tried this, also works (regurl) :slight_smile:

        // everything is ok, let's try to create a new registration
        try {
            // we store registrations as subpages of the current page
            $registration = $page->createChild([
                'slug'     => md5(str::slug($data['name'] . microtime())),
                'template' => 'registration',
                'content'  => $data

            ]);
            
              $datatwo = [
                'regurl' => $registration->panelUrl()
					];

            $kirby->email([
                'template' => 'reg',
                'from'     => 'info@tennisandmore.lt',
                'replyTo'  => $data['email'],
                'to'       => 'roman@overslas.lt',
                'subject'  => esc($data['name']) .' '.  esc($data['surname']) . ' nauja registracija',
                'data'     => [
                    'text'   	=> esc($data['text']),
                    'name' 		=> esc($data['name']),
                    'surname' 	=> esc($data['surname']),
                    'group' 	=> esc($data['group']),
                    'club' 	=> esc($data['club']),
                    'city' 	=> esc($data['city']),
                    'birthdate' 	=> esc($data['birthdate']),
                    'email' 	=> esc($data['email']),
                    'phone' 	=> esc($data['phone']),
                    'pageurl' 	=> esc($data['pageurl']),
                    'pagetitle' 	=> esc($data['pagetitle']),
                    'regurl' 	=> esc($datatwo['regurl'])
                    
                ]
            ]);

Yes, but that is unnecessary. And also you should do the check like in my example before call panel url()

1 Like

Thank you, tried your method, seems not to work. Maybe because ‘data’ => [ is before $registration = $page->createChild([
?

No, I meant the second data array.

I understand, removed $datatwo = [ … , left only what is in your example, this way email is sent, but without $registration->panelUrl() value

Have you included it in your email template?

Yes, same as before (with two data arrays example): <?= $regurl ?>

 <?php

    return function ($kirby, $page) {

        // if the form has been submitted…
        if ($kirby->request()->is('POST') && get('register')) {

            // check the honeypot and exit if is has been filled in
            if(empty(get('website')) === false) {
                go($page->url());
                exit;
            }

            $data = [
                'name'    => get('name'),
                'surname'    => get('surname'),
                'email'   => get('email'),
                'birthdate'    => get('birthdate'),
                'group'  => get('group'),
                'city'    => get('city'),
                'club'    => get('club'),
                'phone'   => get('phone'),
                'message' => get('message'),
                'newsletter' => get('newsletter'),
                'pageurl' => $page->uri(),
                'pagetitle' => $page->title(),
                'reglink' => $registration? $registration->panelUrl() : null

            ];

            $rules = [
                'name'  => ['required'],
                'surname'  => ['required'],
                'email' => ['required', 'email'],
            ];

            $messages = [
                'name'  => 'Please enter your (link: #name text: name)',
                'surname'  => 'Please enter your (link: #surname text: surname)',
                'email' => 'Please enter a valid (link: #email text: email address)',
            ];

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



            } else {


                // authenticate as almighty
                $kirby->impersonate('kirby');

                // everything is ok, let's try to create a new registration
                try {
                    // we store registrations as subpages of the current page
                    $registration = $page->createChild([
                        'slug'     => md5(str::slug($data['name'] . microtime())),
                        'template' => 'registration',
                        'content'  => $data

                    ]);
                    

                    $kirby->email([
                        'template' => 'reg',
                        'from'     => 'from@example.com',
                        'replyTo'  => $data['email'],
                        'to'       => 'to@example.com',
                        'subject'  => esc($data['name']) .' '.  esc($data['surname']) . ' nauja registracija',
                        'data'     => [
                            'text'   	=> esc($data['text']),
                            'name' 		=> esc($data['name']),
                            'surname' 	=> esc($data['surname']),
                            'group' 	=> esc($data['group']),
                            'club' 	=> esc($data['club']),
                            'city' 	=> esc($data['city']),
                            'birthdate' 	=> esc($data['birthdate']),
                            'email' 	=> esc($data['email']),
                            'phone' 	=> esc($data['phone']),
                            'pageurl' 	=> esc($data['pageurl']),
                            'pagetitle' 	=> esc($data['pagetitle']),
                            'regurl' 	=> esc($data['regurl'])
                            
                        ]
                    ]);
                    
                    
                    

                    if ($registration) {
                        // store referer and name in session
                        $kirby->session()->set([
                            'referer' => $page->uri(),
                            'regName'  => esc($data['name'])
                        ]);
                        go('success');
                    }

                } catch (Exception $e) {
                    $alert = ['Your registration failed: ' . $e->getMessage()];
                }
            }
        }
        
        


        // return data to template
        return [
            'alert' => $alert ?? null,
            'data'  => $data ?? false,
        ];
    };

Email template:

New registration:
    <?= $name ?> <?= $surname ?>

    <?= $city ?>

    <?= $phone ?>

    <?= $email ?>

    <?= $birthdate ?>

    <?= $group ?>

    <?= $club ?>

    <?= $regurl ?>

    <?= $pagetitle ?>

example.com/<?= $pageurl ?>

You are trying to set the regurl before the page is even created, that can’t possibly work

As I said above, define the url in the mail wrapper, not where you fetch the data from the form.

1 Like

Sorry, but I am confused now. Your first example was to put it to $data = [ …
But it was mistake?

I checked this by your last comment and it’s working now:

                $kirby->email([
                'template' => 'reg',
                'from'     => 'from@example.com',
                'replyTo'  => $data['email'],
                'to'       => 'to@example.com',
                'subject'  => esc($data['name']) .' '.  esc($data['surname']) . ' nauja registracija',
                'data'     => [
                    'text'   	=> esc($data['text']),
                    'name' 		=> esc($data['name']),
                    'surname' 	=> esc($data['surname']),
                    'group' 	=> esc($data['group']),
                    'club' 	=> esc($data['club']),
                    'city' 	=> esc($data['city']),
                    'birthdate' 	=> esc($data['birthdate']),
                    'email' 	=> esc($data['email']),
                    'phone' 	=> esc($data['phone']),
                    'pageurl' 	=> esc($data['pageurl']),
                    'pagetitle' 	=> esc($data['pagetitle']),
                    'regurl' => $registration? $registration->panelUrl() : null
                    
                ]
            ]);