Skip to content

Instantly share code, notes, and snippets.

@wilr
Last active December 20, 2015 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilr/6203714 to your computer and use it in GitHub Desktop.
Save wilr/6203714 to your computer and use it in GitHub Desktop.
EditableHiddenField for UserDefinedForms
<?php
/**
* @package userforms
*/
class EditableHiddenField extends EditableFormField {
private static $singular_name = 'Hidden Field';
private static $plural_name = 'Hidden Fields';
public function getFieldConfiguration() {
$options = parent::getFieldConfiguration();
$options->push(
new TextField($this->getSettingName("Variable"), 'Value (use GET["a"]) to accept GET parameters', $this->getSetting('Variable')),
new CheckboxField(
$this->getSettingName('HideFromReports'),
_t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?'),
$this->getSetting('HideFromReports')
)
);
if($this->readonly) {
$extraFields = $options->makeReadonly();
}
return $options;
}
public function getFormField() {
$var = $this->getSetting('Variable');
if(preg_match("/^GET\[(.*)\]$/i", $var, $results)) {
$var = (isset($_GET[$results[1]])) ? $_GET[$results[1]] : "";
}
return new HiddenField($this->Name, $this->Title, $var);
}
public function showInReports() {
return (!$this->getSetting('HideFromReports'));
}
public function getFieldValidationOptions() {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment