Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Create page using Front End

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 812 Views
  • Johnny9
    Avatar
    Community Member
    15 Posts

    Create page using Front End Link to this post

    Hi, usualy we create pages in Admin Panel, but I want to allow some users (They dont have permission log in to Admin Panel) to create pages using Front End. In Admin I created pages like this "Categories/Category/CategoryPage", so how could I transfer page creation method in Front End? So users could choose Category and then add CategoryPage to it?
    Maybe where are some tutorials or maybe you could explain simple way of creating just one page in Front End with title and content which would be seen in Admin Panel and also in Front End ect.: News page? That would be a start for my idea:) Hope somebody will help, thanks

  • IOTI
    Avatar
    Community Member
    187 Posts

    Re: Create page using Front End Link to this post

    Hi Johnny9,

    To help guide you in the right direction, you would have to create a form and form handler function that creates a page for you based on the form input. It's important to remember that a "Page" in SilverStripe is really just a DataObject.

    Form tutorial: http://doc.silverstripe.org/framework/en/tutorials/3-forms

    Tutorial on Creating DataObjects from the front end: http://www.ssbits.com/tutorials/2012/s-new-post-78/ - this is an older article but should help out.

    Let me know how you make out and I will assist as best I can.

  • Johnny9
    Avatar
    Community Member
    15 Posts

    Re: Create page using Front End Link to this post

    Thanks IOTI. I will start by creating form and using these tutorials to build what I want. See you soon, because help will be needed

  • Johnny9
    Avatar
    Community Member
    15 Posts

    Re: Create page using Front End Link to this post

    So, I made upload form, with title, content and ect. All posts goes to database and I successfully return whem to front end. I did all this using that first tutorial. But what should Į do, that these database entries would be displayed in admin, like pages? Thanks for any tips

  • Johnny9
    Avatar
    Community Member
    15 Posts

    Re: Create page using Front End Link to this post

    Second tutorial is done.. But, still dont get, how to make form that could create page in admin and in front end :/

  • IOTI
    Avatar
    Community Member
    187 Posts

    Re: Create page using Front End Link to this post

    Hey Johnny

    You know how to create a dataobject using a form thanks to the first tutorial I linked to. As I said earlier a page is really just a dataobject so you'll do pretty much the same thing. Your code would look something like this.

    class Page_Controller extends ContentController {

    public function CategoryForm(){
          //Fields
          $fields = new FieldList(
             new TextField('CategoryPageName', 'Name')               
          );
          
          //action field
          $actions = new FieldList(
             new FormAction('CategoryFormHandler', 'Post')               
          );
          
          //required Fields
          $requiredFields = new RequiredFields(
             'CategoryName'                           
          );
          
          //creating form
          $form = new Form(
             $this,
             'CategoryForm',
             $fields,
             $actions,
             $requiredFields            
          );
          
          return $form;   
    }

    public function CategoryFormHandler($data,$form){
    if($data['CategoryPageName']){
    $page = new CategoryPage();

    $page->Title = Convert::raw2sql($data['CategoryPageName']);
    $page->write();

    $this->redirectBack();

    }else {
    return $this->redirectBack();
    }
    }

    }

    This is a super basic example. You'll want to add some logic to make sure that the CategoryPageName the user entered isn't already taken.

    You mentioned you also wanted the user to be able to pick a Category. You'd want to create a dynamic dropdown field that lists all of the category pages. Check out this tutorial for some tips on doing that: http://www.ssbits.com/tutorials/2010/dynamically-generating-a-dropdown-list/.

    Again let me know how you make out with this and I will assist as best I can.

  • Johnny9
    Avatar
    Community Member
    15 Posts

    Re: Create page using Front End Link to this post

    Thanks for help IOTI will try to adapt your code soon.

  • Johnny9
    Avatar
    Community Member
    15 Posts

    Re: Create page using Front End Link to this post

    Yes!! It works! When you done step by step it is realy not so hard to do:) Really appreciate your help IOTI:)

    Another step, I want to make, let users to choose Category (what I have done) and after they choose Category corresponding form appears.

    Ect. Choose: Category A, appears Form A. Choose: Catefory B - appears Form B. I have idea how to make this, but if you know any more tips how to do this in right way, please share.

    812 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.