mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FEATURE: added LiteralField option to user defined forms
This commit is contained in:
parent
b1a0026d05
commit
9887201bf5
64
code/editor/EditableLiteralField.php
Normal file
64
code/editor/EditableLiteralField.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Editable Spam Protecter Field. Used with the User Defined Forms module (if
|
||||
* installed) to allow the user to have captcha fields with their custom forms
|
||||
*
|
||||
* @package SpamProtection
|
||||
*/
|
||||
|
||||
class EditableLiteralField extends EditableFormField {
|
||||
|
||||
static $db = array(
|
||||
'Content' => 'Text'
|
||||
);
|
||||
|
||||
static $singular_name = 'Literal Field';
|
||||
static $plural_name = 'Literal Fields';
|
||||
|
||||
function __construct( $record = null, $isSingleton = false ) {
|
||||
|
||||
parent::__construct( $record, $isSingleton );
|
||||
}
|
||||
|
||||
function ExtraOptions() {
|
||||
|
||||
// eventually replace hard-coded "Fields"?
|
||||
$baseName = "Fields[$this->ID]";
|
||||
|
||||
$extraFields = new FieldSet();
|
||||
$extraFields->push(new TextareaField($baseName . "[Content]", "Text", 4, 20, $this->Content));
|
||||
|
||||
return $extraFields;
|
||||
}
|
||||
|
||||
function populateFromPostData($data) {
|
||||
|
||||
$this->Content = $data['Content'];
|
||||
parent::populateFromPostData($data);
|
||||
}
|
||||
|
||||
function getFormField() {
|
||||
return $this->createField();
|
||||
}
|
||||
|
||||
function getFilterField() {
|
||||
return $this->createField(true);
|
||||
}
|
||||
|
||||
function createField() {
|
||||
return new LiteralField("LiteralField[$this->ID]",
|
||||
"<label class='left'>$this->Name</label><div class='middleColumn literalFieldArea'>". $this->Content."</div>");
|
||||
}
|
||||
/**
|
||||
* Populates the default fields.
|
||||
*/
|
||||
function DefaultField() {
|
||||
return "";
|
||||
}
|
||||
|
||||
function EditSegment() {
|
||||
return $this->renderWith( $this->class );
|
||||
}
|
||||
}
|
||||
?>
|
20
templates/EditableLiteralField.ss
Normal file
20
templates/EditableLiteralField.ss
Normal file
@ -0,0 +1,20 @@
|
||||
<div class="EditableLiteralField EditableFormField" id="$Name.Attr">
|
||||
<div class="FieldInfo">
|
||||
<img class="handle" src="sapphire/images/drag.gif" alt="<% _t('DRAG', 'Drag to rearrange order of fields') %>" />
|
||||
<img class="icon" src="userforms/images/fe_icons/literal.png" alt="<% _t('LITERALFIELD', 'Literal Field') %>" />
|
||||
$TitleField
|
||||
<a class="toggler" href="#" title="<% _t('MORE', 'More options') %>"><img src="cms/images/edit.gif" alt="<% _t('MORE', 'More options') %>" /></a>
|
||||
<a class="delete" href="#" title="<% _t('DELETE', 'Delete this field') %>"><img src="cms/images/delete.gif" alt="<% _t('DELETE', 'Delete this field') %>" /></a>
|
||||
</div>
|
||||
<div class="ExtraOptions" id="$Name.Attr-extraOptions">
|
||||
<div class="FieldDefault" id="$Name.Attr-fieldDefault">
|
||||
$DefaultField
|
||||
</div>
|
||||
<% control ExtraOptions %>
|
||||
$FieldHolder
|
||||
<% end_control %>
|
||||
</div>
|
||||
<input type="hidden" name="$Name.Attr[CustomParameter]" value="$CustomParameter" />
|
||||
<input type="hidden" name="$Name.Attr[Type]" value="EditableLiteralField" />
|
||||
<input type="hidden" name="$Name.Attr[Sort]" value="-1" />
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user