27/02/2017 5:45pm

PHP | Problem -


<?php


class TestimonialPage_Controller extends Page_Controller {

private static $allowed_actions = array(
'AddForm'
);

public function AddForm() {

$fTestimonial = TextAreaField::create("Testimonial", "Testimonial")
->setRows(6)
->setColumns(70)
->setFieldHolderTemplate('ContactUsBootstrapTextAreaHolder')
->setAttribute('placeholder', 'Testimonial*');

$fFirstName = TextField::create('FirstName', 'First Name')
->setFieldHolderTemplate('ContactUsBootstrapFieldHolder')
->setAttribute('placeholder', 'First Name*');

$fLastName = TextField::create('LastName', 'Surname')
->setFieldHolderTemplate('ContactUsBootstrapFieldHolder')
->setAttribute('placeholder', 'Surname*');

$fCompany = TextField::create('Company', 'Company')
->setFieldHolderTemplate('ContactUsBootstrapFieldHolder')
->setAttribute('placeholder', 'Company*');

$fJobTitle = TextField::create('JobTitle', 'Job Title')
->setFieldHolderTemplate('ContactUsBootstrapFieldHolder')
->setAttribute('placeholder', 'Job Title');

$fields = new FieldList(
$fFirstName,
$fLastName,
$fCompany,
$fJobTitle,
$fTestimonial
);

$actions = new FieldList(
FormAction::create('doSubmit', 'Submit')
->setStyle("primary")
->addExtraClass("btn btn-lg")
->setUseButtonTag(true)
->setTemplate('ContactUsBootstrapFormAction')
);

$validator = new RequiredFields('FirstName', 'LastName', 'Testimonial', 'Company');

$form = BootstrapForm::create($this, 'AddForm', $fields, $actions, $validator)
->setTemplate('ContactUsBootstrapForm');

$form->enableSpamProtection()
->fields()->fieldByName('Captcha')
->setTitle("Captcha")
->setDescription("Please tick the box to prove you're a human and help us stop spam.");

$form->enableSpamProtection();

return $form;

}

public function doSubmit($data, $form) {

$submission = new Testimonial();
$submission->Visible = FALSE;
$submission->write();
$form->saveInto($submission);
$submission->write();

return $this->redirect($this->Link("?success=1"));
}

}