Create listed/unlisted page from frontend instead of draft

Hi again!
title saids it all. Is this possible through $page->createchild()

I guess this is because of security vulnerabilities? The website I’m building will be part of an art installation. Which means it’s a local app which will not interact with any server.

Something like:

$registration = $page->createChild([
    'slug'     => md5($data['uid'] . microtime()),
    'template' => 'drawing',
    'content'  => $data,
    'status'   => 'unlisted'
]);

I tried it, but with little effect.

This works for listed pages

 $p = Page::create([

    'parent' => page('photography'),
    'isDraft' => false,
    'status' => 'listed',
    'num' => page('photography')->children()->listed()->count() + 1,
    'slug' => 'some-slug',
    'template' => 'album'
  ]);

Tried several options for unlisted, like setting num to null and calling ->save(), but that didn’t work.

Alternative would be to call changeStatus on the page after creation.

1 Like

For some reason Page::create made an endless loop creating multiple drafted pages.

I tried your alternative solution and it works like charm!

$registration = $page->createChild([
    'slug'     => md5($data['A'] . microtime()),
    'template' => 'drawing',
    'num' => $page->children()->listed()->count() + 1,
    'content'  => $data,
]);                

if ($registration) {
    // change registration to listed
    $registration->changeStatus('listed');
    go('drawings');
}

Thanks again :slight_smile:
have a great day!