Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

Create page using Front End


Go to End
Reply


9 Posts   1106 Views

Avatar
Johnny9

Community Member, 21 Posts

29 August 2013 at 12:04am

Edited: 29/08/2013 12:05am

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

Avatar
copernican

Community Member, 189 Posts

29 August 2013 at 12:13am

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: [url]http://doc.silverstripe.org/framework/en/tutorials/3-forms[/url]

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

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

Avatar
Johnny9

Community Member, 21 Posts

29 August 2013 at 12:30am

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 :)

Avatar
Johnny9

Community Member, 21 Posts

29 August 2013 at 5:58am

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 :)

Avatar
Johnny9

Community Member, 21 Posts

29 August 2013 at 8:02am

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

Avatar
copernican

Community Member, 189 Posts

30 August 2013 at 12:19am

Edited: 30/08/2013 12:20am

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: [url]http://www.ssbits.com/tutorials/2010/dynamically-generating-a-dropdown-list/[/url].

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

Avatar
Johnny9

Community Member, 21 Posts

30 August 2013 at 11:04pm

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

Avatar
Johnny9

Community Member, 21 Posts

31 August 2013 at 1:43am

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.

Go to Top