本文整理汇总了PHP中JFormField::setup方法的典型用法代码示例。如果您正苦于以下问题:PHP JFormField::setup方法的具体用法?PHP JFormField::setup怎么用?PHP JFormField::setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JFormField
的用法示例。
在下文中一共展示了JFormField::setup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
/**
* Method to attach a JForm object to the field.
* Catch upload files when form setup.
*
* @param object &$element The JXmlElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
parent::setup($element, $value, $group);
if (JRequest::getVar($this->element['name'] . '_delete') == 1) {
$this->value = '';
} else {
// Upload Image
// ===============================================
if (isset($_FILES['jform']['name']['profile'])) {
foreach ($_FILES['jform']['name']['profile'] as $key => $var) {
if (!$var) {
continue;
}
// Get Field Attr
$width = $this->element['save_width'] ? $this->element['save_width'] : 800;
$height = $this->element['save_height'] ? $this->element['save_height'] : 800;
// Build File name
$src = $_FILES['jform']['tmp_name']['profile'][$key];
$var = explode('.', $var);
$date = JFactory::getDate('now', JFactory::getConfig()->get('offset'));
$name = md5((string) $date . $width . $height . $src) . '.' . array_pop($var);
$url = "images/cck/{$date->year}/{$date->month}/{$date->day}/" . $name;
// A Event for extend.
JFactory::getApplication()->triggerEvent('onCCKEngineUploadImage', array(&$url, &$this, &$this->element));
$dest = JPATH_ROOT . '/' . $url;
// Upload First
JFile::upload($src, $dest);
// Resize image
$img = new JImage();
$img->loadFile(JPATH_ROOT . '/' . $url);
$img = $img->resize($width, $height);
switch (array_pop($var)) {
case 'gif':
$type = IMAGETYPE_GIF;
break;
case 'png':
$type = IMAGETYPE_PNG;
break;
default:
$type = IMAGETYPE_JPEG;
break;
}
// save
$img->toFile($dest, $type, array('quality' => 85));
// Set in Value
$this->value = $url;
}
}
}
return true;
}
示例2: setup
/**
* Method to attach a JForm object to the field.
* Catch upload files when form setup.
*
* @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
parent::setup($element, $value, $group);
$container = \Windwalker\DI\Container::getInstance();
$input = $container->get('input');
$delete = isset($_REQUEST['jform']['profile'][$this->element['name'] . '_delete']) ? $_REQUEST['jform']['profile'][$this->element['name'] . '_delete'] : 0;
if ($delete == 1) {
$this->value = '';
} else {
// Upload Image
// ===============================================
if (isset($_FILES['jform']['name']['profile'])) {
foreach ($_FILES['jform']['name']['profile'] as $key => $var) {
if (!$var) {
continue;
}
// Get Field Attr
$width = $this->element['save_width'] ? $this->element['save_width'] : 800;
$height = $this->element['save_height'] ? $this->element['save_height'] : 800;
// Build File name
$src = $_FILES['jform']['tmp_name']['profile'][$key];
$var = explode('.', $var);
$date = DateHelper::getDate();
$name = md5((string) $date . $width . $height . $src) . '.' . array_pop($var);
$url = "images/cck/{$date->year}/{$date->month}/{$date->day}/" . $name;
// A Event for extend.
$container->get('event.dispatcher')->trigger('onCCKEngineUploadImage', array(&$url, &$this, &$this->element));
$dest = JPATH_ROOT . '/' . $url;
// Upload First
JFile::upload($src, $dest);
// Resize image
$img = new JImage();
$img->loadFile(JPATH_ROOT . '/' . $url);
$img = $img->resize($width, $height);
switch (array_pop($var)) {
case 'gif':
$type = IMAGETYPE_GIF;
break;
case 'png':
$type = IMAGETYPE_PNG;
break;
default:
$type = IMAGETYPE_JPEG;
break;
}
// Save
$img->toFile($dest, $type, array('quality' => 85));
// Set in Value
$this->value = $url;
// Clean cache
$thumb = $this->getThumbPath();
if (is_file(JPATH_ROOT . '/' . $thumb)) {
\JFile::delete(JPATH_ROOT . '/' . $thumb);
}
}
}
}
return true;
}
示例3: setup
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
* @since 3.2
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result == true) {
$this->contentType = (string) $this->element['content_type'];
}
return $result;
}
示例4: setup
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);
if ($return) {
$this->countertype = (string) $this->element['countertype'];
}
return $return;
}
示例5: setup
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
* @since 3.6.3
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);
if ($return) {
$this->linked = isset($this->element['linked']) ? (int) $this->element['linked'] : 'position';
}
return $return;
}
示例6: setup
/**
* Method to attach a JForm object to the field.
*
* @param object &$element The JXmlElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @since 2.5
*/
public function setup(&$element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
// Force field to be required. There's no reason to have a captcha if it is not required.
// Obs: Don't put required="required" in the xml file, you just need to have validate="captcha"
$this->required = true;
$class = $this->element['class'];
if (strpos($class, 'required') === false) {
$this->element['class'] = $class . ' required';
}
return $result;
}
示例7: setup
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);
if ($return) {
$this->max = isset($this->element['max']) ? $this->element['max'] : null;
$this->min = isset($this->element['min']) ? $this->element['min'] : null;
$this->unit = isset($this->element['unit']) ? $this->element['unit'] : null;
$this->help = isset($this->element['help']) ? $this->element['help'] : null;
$this->icon = isset($this->element['icon']) ? $this->element['icon'] : null;
$this->maxLength = isset($this->element['maxlength']) ? $this->element['maxlength'] : '';
}
return $return;
}
示例8: setup
public function setup(&$element, $value, $group = null)
{
$success = parent::setup($element, $value, $group);
if (!$success) {
return false;
}
//echo var_export($this->form);die();
return true;
// load any custom fields
$dispatcher =& JDispatcher::getInstance();
JPluginHelper::importPlugin("jevents");
$id = intval(str_replace("extras", "", $this->name));
$res = $dispatcher->trigger('onEditMenuItem', array(&$this->data, &$this->value, $this->type, $this->name, $this->id, $this->form));
return true;
}
示例9: setup
public function setup(SimpleXMLElement $element, $value, $group = null) {
$return = parent::setup($element, $value, $group);
if($return) {
if(version_compare(JVERSION,3.2,'>=')) {
$td = ($this->getAttribute('translate_default') == 'true')?true:false;
$default = ($this->value == $this->default)?$this->default:false;
} else {
$td = ($element->attributes()->translate_default == 'true')?true:false;
$default = ($this->value == $element->attributes()->default)?$element->attributes()->default:false;
}
if($td && $default) {
$this->value = JText::_($default);
}
}
return $return;
}
示例10: setup
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @since 2.5
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
$plugin = $this->element['plugin'] ? (string) $this->element['plugin'] : JFactory::getApplication()->getParams()->get('captcha', JFactory::getConfig()->get('captcha'));
if ($plugin === 0 || $plugin === '0' || $plugin === '' || $plugin === null) {
$this->hidden = true;
} else {
// Force field to be required. There's no reason to have a captcha if it is not required.
// Obs: Don't put required="required" in the xml file, you just need to have validate="captcha"
$this->required = true;
$class = $this->element['class'];
if (strpos($class, 'required') === false) {
$this->element['class'] = $class . ' required';
}
}
return $result;
}
示例11: setup
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @since 2.5
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
$app = JFactory::getApplication();
$default = $app->get('captcha');
if ($app->isSite()) {
$default = $app->getParams()->get('captcha', $default);
}
$plugin = $this->element['plugin'] ? (string) $this->element['plugin'] : $default;
$this->plugin = $plugin;
if ($plugin === 0 || $plugin === '0' || $plugin === '' || $plugin === null) {
$this->hidden = true;
} else {
// Force field to be required. There's no reason to have a captcha if it is not required.
// Obs: Don't put required="required" in the xml file, you just need to have validate="captcha"
$this->required = true;
if (strpos($this->class, 'required') === false) {
$this->class = $this->class . ' required';
}
}
$this->namespace = $this->element['namespace'] ? (string) $this->element['namespace'] : $this->form->getName();
return $result;
}
示例12: setup
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
* @since 3.2
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
// Handle the default attribute
$default = (string) $element['default'];
if ($default) {
$test = $this->form->getValue((string) $element['name'], $group);
$value = $test == $default ? $default : null;
}
$return = parent::setup($element, $value, $group);
if ($return) {
$checked = (string) $this->element['checked'];
$this->checked = $checked == 'true' || $checked == 'checked' || $checked == '1';
empty($this->value) || $this->checked ? null : ($this->checked = true);
}
return $return;
}
示例13: setup
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
* @since 3.2
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result == true) {
$inputmode = (string) $this->element['inputmode'];
$dirname = (string) $this->element['dirname'];
$this->inputmode = '';
$inputmode = preg_replace('/\\s+/', ' ', trim($inputmode));
$inputmode = explode(' ', $inputmode);
if (!empty($inputmode)) {
$defaultInputmode = in_array('default', $inputmode) ? JText::_("JLIB_FORM_INPUTMODE") . ' ' : '';
foreach (array_keys($inputmode, 'default') as $key) {
unset($inputmode[$key]);
}
$this->inputmode = $defaultInputmode . implode(" ", $inputmode);
}
// Set the dirname.
$dirname = (string) $dirname == 'dirname' || $dirname == 'true' || $dirname == '1';
$this->dirname = $dirname ? $this->getName($this->fieldname . '_dir') : false;
$this->maxLength = (int) $this->element['maxlength'];
}
return $result;
}
示例14: setup
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
* @since 3.2
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result == true) {
$assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
$this->authorField = $this->element['created_by_field'] ? (string) $this->element['created_by_field'] : 'created_by';
$this->asset = $this->form->getValue($assetField) ? $this->form->getValue($assetField) : (string) $this->element['asset_id'];
$this->link = (string) $this->element['link'];
$this->preview = (string) $this->element['preview'];
$this->directory = (string) $this->element['directory'];
$this->previewWidth = isset($this->element['preview_width']) ? (int) $this->element['preview_width'] : 200;
$this->previewHeight = isset($this->element['preview_height']) ? (int) $this->element['preview_height'] : 200;
}
return $result;
}
示例15: setup
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
* @since 3.2
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);
if ($return) {
$this->section = $this->element['section'] ? (string) $this->element['section'] : '';
$this->component = $this->element['component'] ? (string) $this->element['component'] : '';
$this->assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
}
return $return;
}