mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FEATURE: added ability to include userdefined form nested in Content field by using $UserDefinedForm token
This commit is contained in:
parent
643d6e35f6
commit
0dfded7444
@ -9,32 +9,22 @@
|
|||||||
class UserDefinedForm extends Page {
|
class UserDefinedForm extends Page {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Action in the CMS
|
* @var String Add Action in the CMS
|
||||||
*
|
|
||||||
* @var String
|
|
||||||
*/
|
*/
|
||||||
static $add_action = "A User Form";
|
static $add_action = "A User Form";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Icon for the User Defined Form in the CMS. Without the extension
|
* @var String Icon for the User Defined Form in the CMS. Without the extension
|
||||||
* or the -file
|
|
||||||
*
|
|
||||||
* @var String
|
|
||||||
*/
|
*/
|
||||||
static $icon = "cms/images/treeicons/task";
|
static $icon = "cms/images/treeicons/task";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What level permission is needed to edit / add
|
* @var String What level permission is needed to edit / add
|
||||||
* this page type
|
|
||||||
*
|
|
||||||
* @var String
|
|
||||||
*/
|
*/
|
||||||
static $need_permission = 'ADMIN';
|
static $need_permission = 'ADMIN';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fields on the user defined form page.
|
* @var Array Fields on the user defined form page.
|
||||||
*
|
|
||||||
* @var Array
|
|
||||||
*/
|
*/
|
||||||
static $db = array(
|
static $db = array(
|
||||||
"EmailOnSubmit" => "Boolean",
|
"EmailOnSubmit" => "Boolean",
|
||||||
@ -45,10 +35,7 @@ class UserDefinedForm extends Page {
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default values of variables when this page is created
|
* @var Array Default values of variables when this page is created
|
||||||
* in the CMS
|
|
||||||
*
|
|
||||||
* @var Array
|
|
||||||
*/
|
*/
|
||||||
static $defaults = array(
|
static $defaults = array(
|
||||||
'Content' => '$UserDefinedForm',
|
'Content' => '$UserDefinedForm',
|
||||||
@ -69,7 +56,7 @@ class UserDefinedForm extends Page {
|
|||||||
*
|
*
|
||||||
* @return FieldSet
|
* @return FieldSet
|
||||||
*/
|
*/
|
||||||
function getCMSFields() {
|
public function getCMSFields() {
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
// field editor
|
// field editor
|
||||||
@ -105,45 +92,49 @@ class UserDefinedForm extends Page {
|
|||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
function FilterForm() {
|
/**
|
||||||
// Build fields
|
* Filter the Submissions page form
|
||||||
|
*
|
||||||
|
* @return Form
|
||||||
|
*/
|
||||||
|
public function FilterForm() {
|
||||||
|
|
||||||
$fields = new FieldSet();
|
$fields = new FieldSet();
|
||||||
$required = array();
|
$required = array();
|
||||||
|
|
||||||
foreach( $this->Fields() as $field ) {
|
foreach($this->Fields() as $field) {
|
||||||
$fields->push( $field->getFilterField() );
|
$fields->push($field->getFilterField());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build actions
|
|
||||||
$actions = new FieldSet(
|
$actions = new FieldSet(
|
||||||
new FormAction( "filter", _t('UserDefinedForm.SUBMIT', 'Submit') )
|
new FormAction("filter", _t('UserDefinedForm.SUBMIT', 'Submit'))
|
||||||
);
|
);
|
||||||
|
|
||||||
// set the name of the form
|
|
||||||
return new Form( $this, "Form", $fields, $actions );
|
return new Form( $this, "Form", $fields, $actions );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the submissions by the given criteria
|
* Filter the submissions by the given criteria
|
||||||
|
*
|
||||||
|
* @param Array the filter data
|
||||||
|
* @param Form the form used
|
||||||
|
* @return Array|String
|
||||||
*/
|
*/
|
||||||
function filter( $data, $form ) {
|
public function filter( $data, $form ) {
|
||||||
|
|
||||||
$filterClause = array( "`SubmittedForm`.`ParentID` = '{$this->ID}'" );
|
|
||||||
|
|
||||||
$keywords = preg_split( '/\s+/', $data['FilterKeyword'] );
|
|
||||||
|
|
||||||
|
$filterClause = array( "`SubmittedForm`.`ParentID` = '{$this->ID}'" );
|
||||||
|
$keywords = preg_split( '/\s+/', $data['FilterKeyword'] );
|
||||||
$keywordClauses = array();
|
$keywordClauses = array();
|
||||||
|
|
||||||
// combine all keywords into one clause
|
// combine all keywords into one clause
|
||||||
foreach( $keywords as $keyword ) {
|
foreach($keywords as $keyword) {
|
||||||
|
|
||||||
// escape %, \ and _ in the keyword. These have special meanings in a LIKE string
|
// escape %, \ and _ in the keyword. These have special meanings in a LIKE string
|
||||||
$keyword = preg_replace( '/([%_])/', '\\\\1', addslashes( $keyword ) );
|
$keyword = preg_replace( '/([%_])/', '\\\\1', addslashes( $keyword ) );
|
||||||
|
|
||||||
$keywordClauses[] = "`Value` LIKE '%$keyword%'";
|
$keywordClauses[] = "`Value` LIKE '%$keyword%'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( count( $keywordClauses ) > 0 ) {
|
if(count($keywordClauses) > 0) {
|
||||||
$filterClause[] = "( " . implode( ' OR ', $keywordClauses ) . ")";
|
$filterClause[] = "( " . implode( ' OR ', $keywordClauses ) . ")";
|
||||||
$searchQuery = 'keywords \'' . implode( "', '", $keywords ) . '\' ';
|
$searchQuery = 'keywords \'' . implode( "', '", $keywords ) . '\' ';
|
||||||
}
|
}
|
||||||
@ -242,6 +233,30 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
parent::init();
|
parent::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Using $UserDefinedForm in the Content area of the page shows
|
||||||
|
* where the form should be rendered into. If it does not exist
|
||||||
|
* then default back to $Form
|
||||||
|
*
|
||||||
|
* @return Array
|
||||||
|
*/
|
||||||
|
public function index() {
|
||||||
|
if($this->Content && $this->Form()) {
|
||||||
|
$hasLocation = stristr($this->Content, '$UserDefinedForm');
|
||||||
|
if($hasLocation) {
|
||||||
|
$content = str_ireplace('$UserDefinedForm', $this->Form()->forTemplate(), $this->Content);
|
||||||
|
return array(
|
||||||
|
'Content' => $content,
|
||||||
|
'Form' => ""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array(
|
||||||
|
'Content' => $this->Content,
|
||||||
|
'Form' => $this->Form
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export each of the form submissions for this UserDefinedForm
|
* Export each of the form submissions for this UserDefinedForm
|
||||||
* instance into a CSV file.
|
* instance into a CSV file.
|
||||||
@ -251,7 +266,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return HTTPResponse / bool
|
* @return HTTPResponse / bool
|
||||||
*/
|
*/
|
||||||
function export() {
|
public function export() {
|
||||||
if(!$this->canEdit()) return false;
|
if(!$this->canEdit()) return false;
|
||||||
|
|
||||||
$now = Date("Y-m-d_h.i.s");
|
$now = Date("Y-m-d_h.i.s");
|
||||||
|
@ -4,12 +4,16 @@
|
|||||||
<div class="reports" id="FormSubmissions">
|
<div class="reports" id="FormSubmissions">
|
||||||
|
|
||||||
<% if ExportLink %>
|
<% if ExportLink %>
|
||||||
<a href="$ExportLink" title="Export CSV file"><strong><% _t('EXPORTSUBMISSIONS', 'Export submissions to CSV') %></strong></a>
|
<a href="$ExportLink" title="<% _t('EXPORTCSVFILE', 'Export CSV file') %>"><strong><% _t('EXPORTSUBMISSIONS', 'Export submissions to CSV') %></strong></a>
|
||||||
|
<% end_if %>
|
||||||
|
|
||||||
|
<% if DeleteLink %>
|
||||||
|
<a href="$DeleteLink" title="<% _t('DELETEALLSUBMISSIONS', 'Delete Submissions') %>"><strong><% _t('DELETEALLSUBMISSIONS', 'Delete Submissions') %></strong></a>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
|
|
||||||
<% control Submissions %>
|
<% control Submissions %>
|
||||||
<div class="report">
|
<div class="report">
|
||||||
<span class="submitted"><% _t('SUBMITTED', 'Submitted at') %> $Created.Nice <% if Recipient %>to $Recipient<% end_if %></span>
|
<span class="submitted"><% _t('SUBMITTED', 'Submitted at') %> $Created.Nice. <a href="$DeleteLink"><% _t('DELETESUBMISSION', 'Delete Submission') %></a></span>
|
||||||
<table>
|
<table>
|
||||||
<% control FieldValues %>
|
<% control FieldValues %>
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user