Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » Custom Form Template - How to display submitted data

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

Page: 1
Go to End
Author Topic: 1554 Views
  • Jatinder
    Avatar
    Community Member
    23 Posts

    Custom Form Template - How to display submitted data Link to this post

    Hello,

    I have implemented a custom form with custom template. Everything works (email gets sent, data it stored in database).

    But I can't figure out how to display the submitted data. How do I list or display the submitted data?

    Please see below for my code:

    RegisterPage.php

    class RegisterPage extends Page {

    static $db = array(
    );

       static $has_many = array(
          "Submissions" => "RegisterInterestSubmission"
    );
    }

    class RegisterPage_Controller extends Page_Controller {

       function init() {
    parent::init();
    }
       
       function RegisterInterestForm() {
          return new RegisterForm($this, 'RegisterInterestForm');
       }
    }

    RegisterForm.php - My Custom Form

    class RegisterForm extends Form {

       function __construct($controller, $name) {
          // Create fields
          $fields = new FieldSet(
             new TextField('FirstName', 'First Name'),
             new TextField('Surname', 'Surname'),
             new TextField('Email', 'Email')         
          );
       
          // Create actions
          $actions = new FieldSet(
             new FormAction('doSubmit', 'Submit')
          );
          
          //Validations
          $validator = new RequiredFields('FirstName', 'Surname', 'Email');
       
          //return new Form($this, $name, $fields, $actions, $validator);
          parent::__construct($controller, $name, $fields, $actions, $validator);
       }
       
       function doSubmit($data, $form) {
          $submission = new RegisterInterestSubmission();
          $form->saveInto($submission);
          $submission->write();
       }
       
       function forTemplate() {
          return $this->renderWith(array(
             $this->class,
             'Form'
          ));
       }
    }

    RegisterInterestSubmission.php - Data object to store submissions

    class RegisterInterestSubmission extends DataObject {
       static $db = array(
          'FirstName' => 'Text',
          'Surname' => 'Text',
          'Email' => 'Text'
       );
    }

  • Puppy
    Avatar
    Community Member
    10 Posts

    Re: Custom Form Template - How to display submitted data Link to this post

    Please note I have little experience in Silverstripe so there may be better options from the community.

    From what I know I would suggest you would want to create a new page type which lists the data from the db/session/cookie and use a redirect on the submission page.

    Director::redirect('thanks-for-your-registration/');

    You could then display the data in an acceptable form.

  • Jatinder
    Avatar
    Community Member
    23 Posts

    Re: Custom Form Template - How to display submitted data Link to this post

    Thanks for the response but I am try to displaying the submitted data on the admin side. That is, on the CMS.

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: Custom Form Template - How to display submitted data Link to this post

    Have you checked out the ModelAdmin class. If you make a class in mysite/code that extends model admin and add in the managed modules array
    RegisterInterestSubmission
    It should give you CRUD and a nice export to csv option ;)

  • Jatinder
    Avatar
    Community Member
    23 Posts

    Re: Custom Form Template - How to display submitted data Link to this post

    Thank you for the information. But I am not trying to add or edit data here. I simply want to display the data already stored in the database.

    I added a new tab "Submission" and then tried using a ComplexTableField to list the data from the data object. That works partially. I get the list of submissions just fine. But when I try to view a row's details, I get an error.

    Any pointers or ideas?

  • RoMay
    Avatar
    Community Member
    1 Post

    Re: Custom Form Template - How to display submitted data Link to this post

    Similar problem: no errors, but list is empty.
    Any advice is appreciated!

    1554 Views
Page: 1
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.