本文整理汇总了PHP中Pieform类的典型用法代码示例。如果您正苦于以下问题:PHP Pieform类的具体用法?PHP Pieform怎么用?PHP Pieform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pieform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pieform_rule_required
/**
* Checks whether the field has been specified.
*
* @param Pieform $form The form the rule is being applied to
* @param string $value The value of the field
* @param array $element The element to check
* @param string $check Whether to check the element
* @return string The error message, if the value is invalid.
*/
function pieform_rule_required(Pieform $form, $value, $element, $check)
{
/*{{{*/
if ($check && ($value == '' || $value == array())) {
return $form->i18n('rule', 'required', 'required', $element);
}
}
示例2: pieform_rule_email
/**
* Returns whether the given field is a valid e-mail address.
*
* Currently, the check is [anything]@[anything]. Someone is welcome to write
* something better, this was made just for testing.
*
* @param Pieform $form The form the rule is being applied to
* @param string $value The e-mail address to check
* @param array $element The element to check
* @return string The error message, if there is something wrong with
* the address.
*/
function pieform_rule_email(Pieform $form, $value, $element)
{
/*{{{*/
if (!preg_match('/^[A-Za-z0-9\\._%-]+@(?:[A-Za-z0-9-]+\\.)+[a-z]{2,4}$/', $value)) {
return $form->i18n('rule', 'email', 'email', $element);
}
}
示例3: changerole_validate
function changerole_validate(Pieform $form, $values)
{
global $user, $group;
if (!group_can_change_role($group->id, $user->id, $values['role'])) {
$form->set_error('role', get_string('usercannotchangetothisrole', 'group'));
}
}
示例4: pieform_element_radio
/**
* Renders a set of radio buttons for a form
*
* @param array $element The element to render
* @param Pieform $form The form to render the element for
* @return string The HTML for the element
*/
function pieform_element_radio(Pieform $form, $element)
{
/*{{{*/
if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) {
throw new PieformException('Radio elements should have at least one option');
}
$result = '';
$form_value = $form->get_value($element);
$id = $element['id'];
$separator = "\n";
if (isset($element['separator'])) {
$separator = $element['separator'] . $separator;
}
foreach ($element['options'] as $value => $data) {
$uid = $id . substr(md5(microtime()), 0, 4);
$element['id'] = $uid;
if (is_array($data)) {
$text = $data['text'];
$description = isset($data['description']) ? $data['description'] : '';
} else {
$text = $data;
$description = '';
}
$result .= '<input type="radio"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($value) . '"' . ($form_value == $value ? ' checked="checked"' : '') . '> <label for="' . $form->get_name() . '_' . $uid . '">' . Pieform::hsc($text) . "</label>" . ($description != '' ? '<div class="radio-description">' . $description . '</div>' : '') . $separator;
}
$result = substr($result, 0, -strlen($separator));
return $result;
}
示例5: pieform_element_captcha_get_value
function pieform_element_captcha_get_value(Pieform $form, $element)
{
global $SESSION;
$name = $element['name'];
$global = $form->get_property('method') == 'get' ? $_GET : $_POST;
return isset($global[$name]) && strtolower($global[$name]) == strtolower($SESSION->get($form->get_name() . '_' . $name));
}
示例6: networkingform_submit
function networkingform_submit(Pieform $form, $values)
{
$reply = '';
if ($form->get_submitvalue() === 'deletekey') {
global $SESSION;
$openssl = OpenSslRepo::singleton();
$openssl->get_keypair(true);
$SESSION->add_info_msg(get_string('keydeleted', 'admin'));
// Using cancel here as a hack to get it to redirect so it shows the new keys
$form->reply(PIEFORM_CANCEL, array('location' => get_config('wwwroot') . 'admin/site/networking.php'));
}
if (get_config('enablenetworking') != $values['enablenetworking']) {
if (!set_config('enablenetworking', $values['enablenetworking'])) {
networkingform_fail($form);
} else {
if (empty($values['enablenetworking'])) {
$reply .= get_string('networkingdisabled', 'admin');
} else {
$reply .= get_string('networkingenabled', 'admin');
}
}
}
if (get_config('promiscuousmode') != $values['promiscuousmode']) {
if (!set_config('promiscuousmode', $values['promiscuousmode'])) {
networkingform_fail($form);
} else {
if (empty($values['promiscuousmode'])) {
$reply .= get_string('promiscuousmodedisabled', 'admin');
} else {
$reply .= get_string('promiscuousmodeenabled', 'admin');
}
}
}
$form->reply(PIEFORM_OK, array('message' => $reply == '' ? get_string('networkingunchanged', 'admin') : $reply, 'goto' => '/admin/site/networking.php'));
}
示例7: pieform_renderer_div
/**
* Renders form elements inside <div>s.
*
* @param Pieform $form The form the element is being rendered for
* @param array $element The element to be rendered
* @return string The element rendered inside an appropriate container
*/
function pieform_renderer_div(Pieform $form, $element)
{
/*{{{*/
$formname = $form->get_name();
// Set the class of the enclosing <div> to match that of the element
$result = '<div';
if (isset($element['name'])) {
$result .= ' id="' . $formname . '_' . $element['name'] . '_container"';
}
if (!empty($element['class'])) {
$result .= ' class="' . $element['class'] . '"';
}
$result .= '>';
if (isset($element['labelhtml'])) {
$result .= $element['labelhtml'];
}
//$result .= $builtelement;
$result .= $element['html'];
if (isset($element['helphtml'])) {
$result .= ' ' . $element['helphtml'];
}
// Description - optional description of the element, or other note that should be visible
// on the form itself (without the user having to hover over contextual help
if ((!$form->has_errors() || $form->get_property('showdescriptiononerror')) && !empty($element['description'])) {
$result .= '<div class="description"> ' . Pieform::hsc($element['description']) . "</div>";
}
if (!empty($element['error'])) {
$result .= '<div class="errmsg">' . Pieform::hsc($element['error']) . '</div>';
}
$result .= "</div>\n";
return $result;
}
示例8: pieform_renderer_oneline
/**
* Renders form elements all on one line.
*
* @param Pieform $form The form the element is being rendered for
* @param array $element The element that is being rendered
* @return string The element rendered inside an appropriate container
*/
function pieform_renderer_oneline(Pieform $form, $element)
{
/*{{{*/
$formname = $form->get_name();
// Set the class of the enclosing <div> to match that of the element
$result = '<span';
if (isset($element['name'])) {
$result .= ' id="' . $formname . '_' . Pieform::hsc($element['name']) . '_container"';
}
if (!empty($element['class'])) {
$result .= ' class="' . Pieform::hsc($element['class']) . '"';
}
$result .= '>';
if (isset($element['labelhtml'])) {
$result .= $element['labelhtml'];
}
if (isset($element['prehtml'])) {
$result .= '<span class="prehtml">' . $element['prehtml'] . '</span>';
}
$result .= $element['html'];
if (isset($element['posthtml'])) {
$result .= '<span class="posthtml">' . $element['posthtml'] . '</span>';
}
$result .= "</span>";
return $result;
}
示例9: pieform_element_cancelbackcreate
/**
* Renders a submit and cancel button
*
* @param array $element The element to render
* @param Pieform $form The form to render the element for
* @return string The HTML for the element
*/
function pieform_element_cancelbackcreate(Pieform $form, $element)
{
$form->include_plugin('element', 'submit');
$form->include_plugin('element', 'cancel');
$cancelelement = $element;
$cancelelement['value'] = $element['value'][0];
$backelement = $element;
$backelement['name'] = 'back';
$backelement['id'] = 'back';
$backelement['value'] = $element['value'][1];
$submitelement = $element;
$submitelement['value'] = $element['value'][2];
if (isset($element['confirm']) && isset($element['confirm'][0])) {
$cancelelement['confirm'] = $element['confirm'][0];
} else {
unset($cancelelement['confirm']);
}
if (isset($element['confirm']) && isset($element['confirm'][1])) {
$backelement['confirm'] = $element['confirm'][1];
} else {
unset($backelement['confirm']);
}
if (isset($element['confirm']) && isset($element['confirm'][2])) {
$submitelement['confirm'] = $element['confirm'][2];
} else {
unset($submitelement['confirm']);
}
return pieform_element_cancel($form, $cancelelement) . ' ' . pieform_element_submit($form, $backelement) . ' ' . pieform_element_submit($form, $submitelement);
}
示例10: contactus_validate
function contactus_validate(Pieform $form, $values)
{
$captcharequired = get_config('captcha_on_contact_form');
if ((is_null($captcharequired) || $captcharequired) && !$values['captcha']) {
$form->set_error('captcha', get_string('captchaincorrect'));
}
}
示例11: pieform_element_button
/**
* Renders an <input type="button"> element.
*
* The element must have the 'value' field set.
*
* @param Pieform $form The form to render the element for
* @param array $element The element to render
* @return string The HTML for the element
* @todo rename to inputbutton
*/
function pieform_element_button(Pieform $form, $element)
{
/*{{{*/
if (!isset($element['value'])) {
throw new PieformException('Button elements must have a value');
}
if (isset($element['confirm'])) {
$element['data-confirm'] = Pieform::hsc($element['confirm']);
}
$element['class'] .= ' btn';
if (isset($element['usebuttontag']) && $element['usebuttontag'] === true) {
$value = '';
$action = '';
$type = 'type="submit" ';
if (isset($element['content'])) {
$content = $element['content'];
$value = 'value="' . Pieform::hsc($element['value']) . '" ';
} else {
$content = $element['value'];
}
if (isset($element['action'])) {
$action = 'formaction="' . Pieform::hsc($element['action']) . '" ';
}
$button = '<button ' . $value . $action . $type . $form->element_attributes($element) . '>' . $content . '</button>';
} else {
$button = '<input type="button"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($element['value']) . '">';
}
return $button;
}
示例12: importeuropassform_validate
function importeuropassform_validate(Pieform $form, $values)
{
global $USER, $SESSION;
$filetype = $values['file']['type'];
if (!$filetype || $filetype != 'text/xml') {
$form->set_error('file', get_string('notvalidxmlfile', 'artefact.europass'));
}
// Check if at least one import option is checked...
$options = array();
if (!empty($values['identification'])) {
$options[] = 'identification';
}
if (!empty($values['application'])) {
$options[] = 'application';
}
if (!empty($values['workexperience'])) {
$options[] = 'workexperience';
}
if (!empty($values['education'])) {
$options[] = 'education';
}
if (!empty($values['languages'])) {
$options[] = 'languages';
}
if (!empty($values['skills'])) {
$options[] = 'skills';
}
if (!empty($values['additionalinfo'])) {
$options[] = 'additionalinfo';
}
if (empty($options)) {
$form->set_error('additionalinfo', get_string('nocheckedoptions', 'artefact.europass'));
}
}
示例13: pieform_element_submitcancel
/**
* Renders a submit and cancel button
*
* @param Pieform $form The form to render the element for
* @param array $element The element to render
* @return string The HTML for the element
*/
function pieform_element_submitcancel(Pieform $form, $element)
{
/*{{{*/
if (!isset($element['value']) || !is_array($element['value']) || count($element['value']) != 2) {
throw new PieformException('The submitcancel element "' . $element['name'] . '" must have a two element array for its value');
}
$form->include_plugin('element', 'submit');
$form->include_plugin('element', 'cancel');
$submitelement = $element;
$submitelement['class'] = isset($submitelement['class']) ? $submitelement['class'] . ' submit' : 'submit';
$submitelement['value'] = $element['value'][0];
$cancelelement = $element;
$cancelelement['class'] = isset($cancelelement['class']) ? $cancelelement['class'] . ' cancel' : 'cancel';
$cancelelement['value'] = $element['value'][1];
if (isset($element['confirm']) && isset($element['confirm'][0])) {
$submitelement['confirm'] = $element['confirm'][0];
} else {
unset($submitelement['confirm']);
}
if (isset($element['confirm']) && isset($element['confirm'][1])) {
$cancelelement['confirm'] = $element['confirm'][1];
} else {
unset($cancelelement['confirm']);
}
return pieform_element_submit($form, $submitelement) . ' ' . pieform_element_cancel($form, $cancelelement);
}
示例14: editgroup_validate
function editgroup_validate(Pieform $form, $values)
{
$cid = get_field('group', 'id', 'name', $values['name']);
if ($cid && $cid != $values['id']) {
$form->set_error('name', get_string('groupalreadyexists', 'group'));
}
}
示例15: personalinformation_submit
function personalinformation_submit(Pieform $form, $values)
{
global $personalinformation, $USER;
$userid = $USER->get('id');
$errors = array();
try {
if (empty($personalinformation)) {
$personalinformation = new ArtefactTypePersonalinformation(0, array('owner' => $userid, 'title' => get_string('personalinformation', 'artefact.resume')));
}
foreach (array_keys(ArtefactTypePersonalInformation::get_composite_fields()) as $field) {
$personalinformation->set_composite($field, $values[$field]);
}
$personalinformation->commit();
} catch (Exception $e) {
$errors['personalinformation'] = true;
}
if (empty($errors)) {
$form->json_reply(PIEFORM_OK, get_string('resumesaved', 'artefact.resume'));
} else {
$message = '';
foreach (array_keys($errors) as $key) {
$message .= get_string('resumesavefailed', 'artefact.resume') . "\n";
}
$form->json_reply(PIEFORM_ERR, $message);
}
}