1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1280 Views |
-
Custom Form Template - How to display submitted data

17 August 2010 at 6:25pm Last edited: 17 August 2010 6:26pm
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'
);
} -
Re: Custom Form Template - How to display submitted data

17 August 2010 at 9:10pm
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.
-
Re: Custom Form Template - How to display submitted data

17 August 2010 at 9:49pm
Thanks for the response but I am try to displaying the submitted data on the admin side. That is, on the CMS.
-
Re: Custom Form Template - How to display submitted data

18 August 2010 at 2:46pm
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 ;) -
Re: Custom Form Template - How to display submitted data

18 August 2010 at 3:46pm
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?
-
Re: Custom Form Template - How to display submitted data

19 October 2012 at 11:52pm
Similar problem: no errors, but list is empty.
Any advice is appreciated!
| 1280 Views | ||
|
Page:
1
|
Go to Top |



