本文整理汇总了PHP中FormField类的典型用法代码示例。如果您正苦于以下问题:PHP FormField类的具体用法?PHP FormField怎么用?PHP FormField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFormField
/**
* Add a FormField
*
* @param FormField $formField FormField object to add
*/
public function addFormField(FormField $formField)
{
if (isset($this->fields[$formField->getName()])) {
throw new SWException(sprintf("Field already exists.\n\tForm: %s\n\tField name: ", $this->name, $formField->getName()));
}
$this->fields[$formField->getName()] = $formField;
}
示例2: transform
public function transform(FormField $field)
{
// Look for a performXXTransformation() method on the field itself.
// performReadonlyTransformation() is a pretty commonly applied method.
// Otherwise, look for a transformXXXField() method on this object.
// This is more commonly done in custom transformations
// We iterate through each array simultaneously, looking at [0] of both, then [1] of both.
// This provides a more natural failover scheme.
$transNames = array_reverse(array_values(ClassInfo::ancestry($this->class)));
$fieldClasses = array_reverse(array_values(ClassInfo::ancestry($field->class)));
$len = max(sizeof($transNames), sizeof($fieldClasses));
for ($i = 0; $i < $len; $i++) {
// This is lets fieldClasses be longer than transNames
if ($transName = $transNames[$i]) {
if ($field->hasMethod('perform' . $transName)) {
$funcName = 'perform' . $transName;
//echo "<li>$field->class used $funcName";
return $field->{$funcName}($this);
}
}
// And this one does the reverse.
if ($fieldClass = $fieldClasses[$i]) {
if ($this->hasMethod('transform' . $fieldClass)) {
$funcName = 'transform' . $fieldClass;
//echo "<li>$field->class used $funcName";
return $this->{$funcName}($field);
}
}
}
user_error("FormTransformation:: Can't perform '{$this->class}' on '{$field->class}'", E_USER_ERROR);
}
示例3: setCustomValidationMessage
/**
* Add is $Field is required message.
*
* @param FormField $field
* @param $title
*/
protected function setCustomValidationMessage(FormField $field, $title)
{
if (!$field->getCustomValidationMessage()) {
$message = strip_tags($title) . ' ' . _t('Site.IsRequired', ' is required');
$field->setCustomValidationMessage($message);
}
}
示例4: AJAXLinkHiddenField
/**
* Used for storing the quantity update link for ajax use.
*/
public function AJAXLinkHiddenField()
{
if ($quantitylink = $this->item->setquantityLink()) {
$attributes = array('type' => 'hidden', 'class' => 'ajaxQuantityField_qtylink', 'name' => $this->MainID() . '_Quantity_SetQuantityLink', 'value' => $quantitylink);
$formfield = new FormField('hack');
return $formfield->createTag('input', $attributes);
}
}
示例5: AJAXLinkHiddenField
/**
* Used for storing the quantity update link for ajax use.
*/
function AJAXLinkHiddenField()
{
if ($quantitylink = ShoppingCart::set_quantity_item_link($this->item->getProductIDForSerialization(), null, $this->parameters)) {
$attributes = array('type' => 'hidden', 'class' => 'ajaxQuantityField_qtylink', 'name' => $this->item->MainID() . '_Quantity_SetQuantityLink', 'value' => $quantitylink);
$formfield = new FormField('hack');
return $formfield->createTag('input', $attributes);
}
}
示例6: addPart
/**
* @return FormField
*/
public function addPart(FormField $part)
{
if (strval($part->getName()) === '') {
$part->setName(sprintf('%s-%s', $this->getName(), count($this->parts)));
}
$part->setAttribute('data-part', count($this->parts));
$this->parts[] = $part;
return $this;
}
开发者ID:helpfulrobot,项目名称:nblum-silverstripe-customizableinputfield,代码行数:12,代码来源:CustomizableInputFieldSet.php
示例7: getFormat
public function getFormat()
{
$fields = AddressFormat::getOrderedAddressFields($this->country->id, true, true);
$required = array_flip(AddressFormat::getFieldsRequired());
$format = ['id_address' => (new FormField())->setName('id_address')->setType('hidden'), 'id_customer' => (new FormField())->setName('id_customer')->setType('hidden'), 'back' => (new FormField())->setName('back')->setType('hidden'), 'token' => (new FormField())->setName('token')->setType('hidden'), 'alias' => (new FormField())->setName('alias')->setLabel($this->getFieldLabel('alias'))];
foreach ($fields as $field) {
$formField = new FormField();
$formField->setName($field);
$fieldParts = explode(':', $field, 2);
if (count($fieldParts) === 1) {
if ($field === 'postcode') {
if ($this->country->need_zip_code) {
$formField->setRequired(true);
}
}
} elseif (count($fieldParts) === 2) {
list($entity, $entityField) = $fieldParts;
// Fields specified using the Entity:field
// notation are actually references to other
// entities, so they should be displayed as a select
$formField->setType('select');
// Also, what we really want is the id of the linked entity
$formField->setName('id_' . strtolower($entity));
if ($entity === 'Country') {
$formField->setType('countrySelect');
$formField->setValue($this->country->id);
foreach ($this->availableCountries as $country) {
$formField->addAvailableValue($country['id_country'], $country[$entityField]);
}
} elseif ($entity === 'State') {
if ($this->country->contains_states) {
$states = State::getStatesByIdCountry($this->country->id);
foreach ($states as $state) {
$formField->addAvailableValue($state['id_state'], $state[$entityField]);
}
$formField->setRequired(true);
}
}
}
$formField->setLabel($this->getFieldLabel($field));
if (!$formField->isRequired()) {
// Only trust the $required array for fields
// that are not marked as required.
// $required doesn't have all the info, and fields
// may be required for other reasons than what
// AddressFormat::getFieldsRequired() says.
$formField->setRequired(array_key_exists($field, $required));
}
$format[$formField->getName()] = $formField;
}
return $this->addConstraints($this->addMaxLength($format));
}
示例8: baseTransform
/**
* @param FormField $nonEditableField
* @param FormField $originalField
* @param string $fieldname
* @return CompositeField
*/
protected function baseTransform($nonEditableField, $originalField, $fieldname)
{
/** @var CompositeField $nonEditableField_holder */
$nonEditableField_holder = CompositeField::create($nonEditableField);
$nonEditableField_holder->setName($fieldname . '_holder');
$nonEditableField_holder->addExtraClass('originallang_holder');
$nonEditableField->setValue($this->original->{$fieldname});
$nonEditableField->setName($fieldname . '_original');
$nonEditableField->addExtraClass('originallang');
$nonEditableField->setTitle(_t('Translatable_Transform.OriginalFieldLabel', 'Original {title}', 'Label for the original value of the translatable field.', array('title' => $originalField->Title())));
$nonEditableField_holder->insertBefore($originalField, $fieldname . '_original');
return $nonEditableField_holder;
}
示例9: Field
public function Field($properties = array())
{
$options = '';
foreach ($this->getSource() as $value => $title) {
if (is_array($title)) {
$options .= "<optgroup label=\"{$value}\">";
foreach ($title as $value2 => $title2) {
$disabled = '';
if (array_key_exists($value, $this->disabledItems) && is_array($this->disabledItems[$value]) && in_array($value2, $this->disabledItems[$value])) {
$disabled = 'disabled="disabled"';
}
$selected = $value2 == $this->value ? " selected=\"selected\"" : "";
$options .= "<option{$selected} value=\"{$value2}\" {$disabled}>{$title2}</option>";
}
$options .= "</optgroup>";
} else {
// Fall back to the standard dropdown field
$disabled = '';
if (in_array($value, $this->disabledItems)) {
$disabled = 'disabled="disabled"';
}
$selected = $value == $this->value ? " selected=\"selected\"" : "";
$options .= "<option{$selected} value=\"{$value}\" {$disabled}>{$title}</option>";
}
}
return FormField::create_tag('select', $this->getAttributes(), $options);
}
示例10: getHeading
/**
* Gets the heading, or label, for the interface, e.g. "Select the categories for this product"
*
* @return string
*/
public function getHeading()
{
if (!$this->get('Heading')) {
return FormField::name_to_label($this->getParentNode()->transform("BedrockComponent")->getName());
}
return $this->get('Heading');
}
示例11: getAreasForPageType
/**
* Gets an array of all areas defined for the current theme that are compatible
* with pages of type $class
* @param string $class
* @return array $areas
**/
public function getAreasForPageType($class)
{
$areas = $this->getAreasForTheme(null, false);
if (!$areas) {
return false;
}
foreach ($areas as $area => $config) {
if (!is_array($config)) {
continue;
}
if (isset($config['except'])) {
$except = $config['except'];
if (is_array($except) ? in_array($class, $except) : $except == $class) {
unset($areas[$area]);
continue;
}
}
if (isset($config['only'])) {
$only = $config['only'];
if (is_array($only) ? !in_array($class, $only) : $only != $class) {
unset($areas[$area]);
continue;
}
}
}
if (count($areas)) {
foreach ($areas as $k => $v) {
$areas[$k] = FormField::name_to_label($k);
}
return $areas;
} else {
return $areas;
}
}
示例12: updateCMSFields
public function updateCMSFields(FieldList $fields)
{
$extFields = self::$db;
$fields->removeByName(array_keys($extFields));
if (!$this->owner->WordpressID) {
return;
}
$compositeFields = array();
foreach ($extFields as $name => $type) {
$value = $this->owner->getField($name);
$compositeFields[$name] = ReadonlyField::create($name . '_Readonly', FormField::name_to_label($name), $value);
}
if ($compositeFields) {
$wordpressCompositeField = ToggleCompositeField::create('WordpressCompositeField', 'Wordpress', $compositeFields)->setHeadingLevel(4);
if ($fields->fieldByName('Metadata')) {
$fields->insertBefore($wordpressCompositeField, 'Metadata');
} else {
if ($fields->fieldByName('Root')) {
$fields->addFieldToTab('Root.Main', $wordpressCompositeField);
} else {
$fields->push($wordpressCompositeField);
}
}
}
}
开发者ID:silbinarywolf,项目名称:silverstripe-wordpressmigrationtools,代码行数:25,代码来源:WordpressImportDataExtension.php
示例13: testErrors
public function testErrors()
{
$form = Form::create()->add(Primitive::ternary('flag')->setFalseValue('0')->setTrueValue('1'))->add(Primitive::integer('old')->required())->addRule('someRule', Expression::between(FormField::create('old'), '18', '35'));
//empty import
$form->import(array())->checkRules();
//checking
$expectingErrors = array('old' => Form::MISSING, 'someRule' => Form::WRONG);
$this->assertEquals($expectingErrors, $form->getErrors());
$this->assertEquals(Form::MISSING, $form->getError('old'));
$this->assertEquals(Form::WRONG, $form->getError('someRule'));
$this->assertTrue($form->hasError('old'));
$this->assertFalse($form->hasError('flag'));
//drop errors
$form->dropAllErrors();
$this->assertEquals(array(), $form->getErrors());
//import wrong data
$form->clean()->importMore(array('flag' => '3', 'old' => '17'))->checkRules();
//checking
$expectingErrors = array('flag' => Form::WRONG, 'someRule' => Form::WRONG);
$this->assertEquals($expectingErrors, $form->getErrors());
$this->assertTrue($form->hasError('someRule'));
//marking good and custom check errors
$form->markGood('someRule')->markCustom('flag', 3);
$this->assertEquals(array('flag' => 3), $form->getErrors());
$this->assertFalse($form->hasError('someRule'));
$this->assertNull($form->getError('someRule'));
$this->assertEquals(3, $form->getError('flag'));
//import right data
$form->dropAllErrors()->clean()->importMore(array('flag' => '1', 'old' => '35'));
//checking
$this->assertEquals(array(), $form->getErrors());
}
示例14: __construct
public function __construct($name, $title = null, $value = '', $extension = null, $areaCode = null, $countryCode = null)
{
$this->areaCode = $areaCode;
$this->ext = $extension;
$this->countryCode = $countryCode;
parent::__construct($name, $title, $value);
}
示例15:
/**
* Create a new action button.
* @param action The method to call when the button is clicked
* @param title The label on the button
* @param form The parent form, auto-set when the field is placed inside a form
* @param extraData A piece of extra data that can be extracted with $this->extraData. Useful for
* calling $form->buttonClicked()->extraData()
* @param extraClass A CSS class to apply to the button in addition to 'action'
*/
function __construct($action, $title = "", $form = null, $extraData = null, $extraClass = '')
{
$this->extraData = $extraData;
$this->extraClass = ' ' . $extraClass;
$this->action = "action_{$action}";
parent::__construct($this->action, $title, null, $form);
}