# Allow guests to create pages from Panel or frontend

**URL:** <https://forum.getkirby.com/t/allow-guests-to-create-pages-from-panel-or-frontend/2854>\
**Category:** Questions\
**Tags:** v2\
**Created:** [December 17, 2015, 11:18pm UTC](https://forum.getkirby.com/t/allow-guests-to-create-pages-from-panel-or-frontend/2854 "2015-12-17T23:18:00Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [January 9, 2016, 11:57am UTC](https://forum.getkirby.com/t/allow-guests-to-create-pages-from-panel-or-frontend/2854/15 "2016-01-09T11:57:01Z")

</div>

[Here’s the new Pull Request](https://github.com/getkirby/toolkit/pull/134) I created.

If you want to try it, temporarily replace your `kirby/toolkit/lib/upload.php` with the file from the PR and use the following controller code (your template is fine):

```php
<?php 

return function($site, $pages, $page) {
  $error = null;
  if(r::method() === 'POST') {
    // The form has been sent
    
    $title = get('brand') . "-" . get('tube-name');
    
    // Build an array of the data you want to allow as fields
    // get() fetches the form field value with that `name`
    $data = array(
      'tube-name' => get('tube-name'),
      'brand' => get('brand'),
      'different_manufacturer' => get('different_manufacturer'),
      'country' => get('country'),
      'code_on_tube' => get('code_on_tube'),
      'factory_code' => get('factory_code'),
      'year' => get('year'),
      'bottle_height' => get('bottle_height'),
      'Tip-Shape' => get('Tip-Shape'),
      'glass_color' => get('glass_color'),
      'Mica' => get('Mica'),
      'getter' => get('getter'),
      'getter_support' => get('getter_support'),
      'plate_look' => get('plate_look'),
      'plate_size' => get('plate_size'),
      'plate_color' => get('plate_color'),
      'pin_color' => get('pin_color'),
      'base' => get('base'),
      'special_use' => get('special_use'),
      'other_marks' => get('other_marks'),
      'notes' => get('notes'),
      'uploader_name' => get('uploader_name'),
      'uploader_email' => get('uploader_email')
    );
    
    // Create a new page as child of the current page
    // You can also use a different page by using `page('whatever')->children()->create()`
    $p = page('uploads')->children()->create($title, 'tube', $data);
    
    // Upload the images
    $missingFile = false;
    $index = 0;
    do {
      try {
        $upload = new Upload($p->root() . DS . '{safeFilename}', array('input' => 'file', 'index' => $index));
        $index++;
      } catch(Error $e) {
        switch($e->getCode()) {
          case Upload::ERROR_MISSING_FILE:
            // No more files have been uploaded
            $missingFile = true;
            break;
          // See the Upload class for other error values
        }
      }
    } while(!$missingFile);
    
    // Check if an image has been uploaded at all
    if($index === 0) {
      $error = 'No file uploaded.';
    }
  }
  
  return compact('error');
};

```

---

_[View the full topic](https://forum.getkirby.com/t/allow-guests-to-create-pages-from-panel-or-frontend/2854)._
