本文整理汇总了PHP中FormValidator::addRule方法的典型用法代码示例。如果您正苦于以下问题:PHP FormValidator::addRule方法的具体用法?PHP FormValidator::addRule怎么用?PHP FormValidator::addRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormValidator
的用法示例。
在下文中一共展示了FormValidator::addRule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lp_upload_quiz_main
function lp_upload_quiz_main()
{
// variable initialisation
$lp_id = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : null;
$form = new FormValidator('upload', 'POST', api_get_self() . '?' . api_get_cidreq() . '&lp_id=' . $lp_id, '', array('enctype' => 'multipart/form-data'));
$form->addElement('header', get_lang('ImportExcelQuiz'));
$form->addElement('file', 'user_upload_quiz', get_lang('FileUpload'));
$link = '<a href="../exercice/quiz_template.xls">' . Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate')) . get_lang('DownloadExcelTemplate') . '</a>';
$form->addElement('label', '', $link);
$table = new HTML_Table(array('class' => 'table'));
$tableList = array(UNIQUE_ANSWER => get_lang('UniqueSelect'), MULTIPLE_ANSWER => get_lang('MultipleSelect'), FILL_IN_BLANKS => get_lang('FillBlanks'), MATCHING => get_lang('Matching'), FREE_ANSWER => get_lang('FreeAnswer'), GLOBAL_MULTIPLE_ANSWER => get_lang('GlobalMultipleAnswer'));
$table->setHeaderContents(0, 0, get_lang('QuestionType'));
$table->setHeaderContents(0, 1, '#');
$row = 1;
foreach ($tableList as $key => $label) {
$table->setCellContents($row, 0, $label);
$table->setCellContents($row, 1, $key);
$row++;
}
$table = $table->toHtml();
$form->addElement('label', get_lang('QuestionType'), $table);
$form->addElement('checkbox', 'user_custom_score', null, get_lang('UseCustomScoreForAllQuestions'), array('id' => 'user_custom_score'));
$form->addElement('html', '<div id="options" style="display:none">');
$form->addElement('text', 'correct_score', get_lang('CorrectScore'));
$form->addElement('text', 'incorrect_score', get_lang('IncorrectScore'));
$form->addElement('html', '</div>');
$form->addRule('user_upload_quiz', get_lang('ThisFieldIsRequired'), 'required');
$form->add_progress_bar();
$form->addButtonUpload(get_lang('Upload'), 'submit_upload_quiz');
// Display the upload field
$form->display();
}
示例2: FormValidator
/** @test */
public function バリデーション違反があれば、違反したルールを返すこと()
{
$validator = new FormValidator();
$validator->addRule(FormValidator::ZIP_CODE, 'xxx-1111', '郵便番号に誤りがあります')->addRule(FormValidator::DATE, '2015-11-11', '日付に誤りがあります');
$errors = $validator->valid();
$expected = [];
$expected[] = new ValidateRule(FormValidator::ZIP_CODE, 'xxx-1111', '郵便番号に誤りがあります');
// objectの比較のためassertEquals
$this->assertEquals($expected, $errors);
}
示例3: lp_upload_quiz_main
function lp_upload_quiz_main()
{
// variable initialisation
$lp_id = isset($_GET['lp_id']) ? Security::remove_XSS($_GET['lp_id']) : null;
$form = new FormValidator('upload', 'POST', api_get_self() . '?' . api_get_cidreq() . '&lp_id=' . $lp_id, '', array('enctype' => 'multipart/form-data'));
$form->addElement('header', get_lang('ImportExcelQuiz'));
$form->addElement('file', 'user_upload_quiz', get_lang('FileUpload'));
$link = '<a href="../exercice/quiz_template.xls">' . Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate')) . get_lang('DownloadExcelTemplate') . '</a>';
$form->addElement('label', '', $link);
$form->addElement('checkbox', 'user_custom_score', null, get_lang('UseCustomScoreForAllQuestions'), array('id' => 'user_custom_score'));
$form->addElement('html', '<div id="options" style="display:none">');
$form->addElement('text', 'correct_score', get_lang('CorrectScore'));
$form->addElement('text', 'incorrect_score', get_lang('IncorrectScore'));
$form->addElement('html', '</div>');
$form->addRule('user_upload_quiz', get_lang('ThisFieldIsRequired'), 'required');
$form->add_progress_bar();
$form->addButtonUpload(get_lang('Send'), 'submit_upload_quiz');
// Display the upload field
$form->display();
}
示例4: return_form
/**
* Returns a Form validator Obj
* @param string $url
* @param string $action add, edit
*
* @return FormValidator
*/
public function return_form($url, $action)
{
$form = new FormValidator('career', 'post', $url);
// Setting the form elements
$header = get_lang('Add');
if ($action == 'edit') {
$header = get_lang('Modify');
}
$form->addElement('header', $header);
$id = isset($_GET['id']) ? intval($_GET['id']) : '';
$form->addElement('hidden', 'id', $id);
$form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
$form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers', 'Width' => '100%', 'Height' => '250'));
$status_list = $this->get_status_list();
$form->addElement('select', 'status', get_lang('Status'), $status_list);
if ($action == 'edit') {
$form->addElement('text', 'created_at', get_lang('CreatedAt'));
$form->freeze('created_at');
}
if ($action == 'edit') {
$form->addButtonSave(get_lang('Modify'), 'submit');
} else {
$form->addButtonCreate(get_lang('Add'), 'submit');
}
// Setting the defaults
$defaults = $this->get($id);
if (!empty($defaults['created_at'])) {
$defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
}
if (!empty($defaults['updated_at'])) {
$defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
}
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
return $form;
}
示例5: createAnswersForm
/**
* function which redefines Question::createAnswersForm
* @param FormValidator $form
*/
public function createAnswersForm($form)
{
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
$nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
$obj_ex = Session::read('objExercise');
/* Mise en variable de Affichage "Reponses" et son icone, "N�", "Vrai", "Reponse" */
$html = '<table class="data_table">
<tr>
<th width="10px">
' . get_lang('Number') . '
</th>
<th width="10px">
' . get_lang('True') . '
</th>
<th width="50%">
' . get_lang('Answer') . '
</th>';
$html .= '<th>' . get_lang('Comment') . '</th>';
$html .= '</tr>';
$form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html);
$defaults = array();
$correct = 0;
$answer = false;
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
#le nombre de r�ponses est bien enregistr� sous la forme int(nb)
/* Ajout mise en forme nb reponse */
$form->addElement('hidden', 'nb_answers');
$boxes_names = array();
/* V�rification : Cr�action d'au moins une r�ponse */
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
//D�but affichage score global dans la modification d'une question
$scoreA = "0";
//par reponse
$scoreG = "0";
//Global
/* boucle pour sauvegarder les donn�es dans le tableau defaults */
for ($i = 1; $i <= $nb_answers; ++$i) {
/* si la reponse est de type objet */
if (is_object($answer)) {
$defaults['answer[' . $i . ']'] = $answer->answer[$i];
$defaults['comment[' . $i . ']'] = $answer->comment[$i];
$defaults['correct[' . $i . ']'] = $answer->correct[$i];
// start
$scoreA = $answer->weighting[$i];
}
if ($scoreA > 0) {
$scoreG = $scoreG + $scoreA;
}
//------------- Fin
//------------- Debut si un des scores par reponse est egal � 0 : la coche vaut 1 (coch�)
if ($scoreA == 0) {
$defaults['pts'] = 1;
}
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
//$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting['.$i.']');
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
$answer_number->freeze();
$form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox"');
$boxes_names[] = 'correct[' . $i . ']';
$form->addHtmlEditor('answer[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
$form->addHtmlEditor('comment[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addElement('html', '</tr>');
}
//--------- Mise en variable du score global lors d'une modification de la question/r�ponse
$defaults['weighting[1]'] = round($scoreG);
$form->addElement('html', '</div></div></table>');
//$form -> addElement ('html', '<br />');
$form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
//only 1 answer the all deal ...
$form->addElement('text', 'weighting[1]', get_lang('Score'));
global $pts;
//--------- Creation coche pour ne pas prendre en compte les n�gatifs
$form->addElement('checkbox', 'pts', '', get_lang('NoNegativeScore'));
$form->addElement('html', '<br />');
// Affiche un message si le score n'est pas renseign�
$form->addRule('weighting[1]', get_lang('ThisFieldIsRequired'), 'required');
global $text, $class;
if ($obj_ex->edit_exercise_in_lp == true) {
$form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers');
$form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers');
$form->addButtonSave($text, 'submitQuestion');
// setting the save button here and not in the question class.php
//.........这里部分代码省略.........
示例6: array
$form->addElement('hidden', 'description');
}
// Action
$form->addElement('hidden', 'action');
// Groups per user
$group = array();
$group[] = $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'));
$possible_values = array();
for ($i = 1; $i <= 10; $i++) {
$possible_values[$i] = $i;
}
$possible_values[GroupManager::GROUP_PER_MEMBER_NO_LIMIT] = get_lang('All');
$group[] = $form->createElement('select', 'groups_per_user', null, $possible_values);
$group[] = $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartAfterNumber'));
$form->addGroup($group, 'limit_group', get_lang('GroupLimit'), ' ', false);
$form->addRule('limit_group', get_lang('MaxGroupsPerUserInvalid'), 'callback', 'check_groups_per_user');
$form->addElement('html', '<br /><br /><div class="sectiontitle" >' . get_lang('DefaultSettingsForNewGroups'));
$form->addElement('html', '</div>');
// Members per group
$form->addElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT);
$group = array();
$group[] = $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, array('id' => 'max_member_selected'));
$group[] = $form->createElement('text', 'max_member', null, array('size' => 2, 'id' => 'max_member'));
$group[] = $form->createElement('static', null, null, get_lang('GroupPlacesThis'));
$form->addGroup($group, 'max_member_group', null, '', false);
$form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
// Self registration
$icon = Display::return_icon('user.png', get_lang('GroupSelfRegistration'), array(), ICON_SIZE_SMALL) . ' ';
$form->addElement('checkbox', 'self_reg_allowed', $icon . get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1);
$form->addElement('checkbox', 'self_unreg_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1);
// Documents settings
示例7: manage_form
function manage_form($default, $select_from_user_list = null, $sent_to = null)
{
$group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null;
$message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null;
$param_f = isset($_GET['f']) && $_GET['f'] == 'social' ? 'social' : null;
$form = new FormValidator('compose_message', null, api_get_self() . '?f=' . $param_f, null, array('enctype' => 'multipart/form-data'));
if (empty($group_id)) {
if (isset($select_from_user_list)) {
$form->addText('id_text_name', get_lang('SendMessageTo'), true, array('id' => 'id_text_name', 'onkeyup' => 'send_request_and_search()', 'autocomplete' => 'off'));
$form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('html', '<div id="id_div_search" style="padding:0px" class="message-select-box" > </div>');
$form->addElement('hidden', 'user_list', 0, array('id' => 'user_list'));
} else {
if (!empty($sent_to)) {
$form->addLabel(get_lang('SendMessageTo'), $sent_to);
}
if (empty($default['users'])) {
//fb select
$form->addElement('select_ajax', 'users', get_lang('SendMessageTo'), array(), ['multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH) . 'message.ajax.php?a=find_users']);
} else {
$form->addElement('hidden', 'hidden_user', $default['users'][0], array('id' => 'hidden_user'));
}
}
} else {
$userGroup = new UserGroup();
$group_info = $userGroup->get($group_id);
$form->addElement('label', get_lang('ToGroup'), api_xml_http_response_encode($group_info['name']));
$form->addElement('hidden', 'group_id', $group_id);
$form->addElement('hidden', 'parent_id', $message_id);
}
$form->addText('title', get_lang('Subject'), true);
$form->addHtmlEditor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250'));
if (isset($_GET['re_id'])) {
$message_reply_info = MessageManager::get_message_by_id($_GET['re_id']);
$default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_reply_info['title'];
$form->addElement('hidden', 're_id', intval($_GET['re_id']));
$form->addElement('hidden', 'save_form', 'save_form');
//adding reply mail
$user_reply_info = api_get_user_info($message_reply_info['user_sender_id']);
$default['content'] = '<p><br/></p>' . sprintf(get_lang('XWroteY'), $user_reply_info['complete_name'], Security::filter_terms($message_reply_info['content']));
}
if (empty($group_id)) {
$form->addElement('label', '', '<div id="filepaths" class="form-group">
<div id="filepath_1">
<label>' . get_lang('FilesAttachment') . '</label>
<input type="file" name="attach_1"/>
<label>' . get_lang('Description') . '</label>
<input id="file-descrtiption" type="text" name="legend[]" class="form-control"/>
</div>
</div>');
$form->addElement('label', '', '<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</a></span> (' . sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message.message_max_upload_filesize'))) . ')');
}
$form->addButtonSend(get_lang('SendMessage'), 'compose');
$form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>');
if (!empty($group_id) && !empty($message_id)) {
$message_info = MessageManager::get_message_by_id($message_id);
$default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_info['title'];
}
$form->setDefaults($default);
$html = '';
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$user_list = $default['users'];
$file_comments = $_POST['legend'];
$title = $default['title'];
$content = $default['content'];
$group_id = isset($default['group_id']) ? $default['group_id'] : null;
$parent_id = isset($default['parent_id']) ? $default['parent_id'] : null;
if (is_array($user_list) && count($user_list) > 0) {
//all is well, send the message
foreach ($user_list as $user) {
$res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id);
if ($res) {
$html .= MessageManager::display_success_message($user);
}
}
} else {
Display::display_error_message('ErrorSendingMessage');
}
}
Security::clear_token();
} else {
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
$html .= $form->returnForm();
}
return $html;
}
示例8: urldecode
}
</script>';
// Database table definitions
if (!empty($_GET['message'])) {
$message = urldecode($_GET['message']);
}
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$tool_name = get_lang('AddGroups');
// Create the form
$form = new FormValidator('group_add');
$form->addElement('header', $tool_name);
// name
$form->addElement('text', 'name', get_lang('Name'), array('size' => 60, 'maxlength' => 120));
$form->applyFilter('name', 'html_filter');
$form->applyFilter('name', 'trim');
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
// Description
$form->addElement('textarea', 'description', get_lang('Description'), array('rows' => 3, 'cols' => 58, 'onKeyDown' => "text_longitud()", 'onKeyUp' => "text_longitud()"));
$form->applyFilter('description', 'html_filter');
$form->applyFilter('description', 'trim');
// url
$form->addElement('text', 'url', get_lang('URL'), array('size' => 35));
$form->applyFilter('url', 'html_filter');
$form->applyFilter('url', 'trim');
// Picture
$form->addElement('file', 'picture', get_lang('AddPicture'));
$allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
$form->addRule('picture', get_lang('OnlyImagesAllowed') . ' (' . implode(', ', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
//Group Parentship
$groups = array();
$groups[0] = get_lang('NoParentship');
示例9: return_item_form
/**
* @param $url
* @param $action
* @return FormValidator
*/
public function return_item_form($url, $action)
{
$form = new FormValidator('item_form', 'post', $url);
// Setting the form elements
$header = get_lang('Add');
if ($action == 'edit') {
$header = get_lang('Modify');
}
$form->addElement('header', $header);
$id = isset($_GET['id']) ? intval($_GET['id']) : '';
$parent_id = isset($_GET['parent_id']) ? intval($_GET['parent_id']) : '';
$form->addElement('hidden', 'parent_id', $parent_id);
$form->addElement('hidden', 'id', $id);
$form->addElement('text', 'headline', get_lang('Name'));
//@todo fix this
$form->addElement('text', 'start_date', get_lang('StartDate'), array('size' => '70'));
$form->addElement('text', 'end_date', get_lang('EndDate'), array('size' => '70'));
$form->addElement('textarea', 'text', get_lang('TimelineItemText'));
$form->addElement('text', 'media', get_lang('TimelineItemMedia'), array('size' => '70'));
$form->addElement('text', 'media_caption', get_lang('TimelineItemMediaCaption'), array('size' => '70'));
$form->addElement('text', 'media_credit', get_lang('TimelineItemMediaCredit'), array('size' => '70'));
$form->addElement('text', 'title_slide', get_lang('TimelineItemTitleSlide'), array('size' => '70'));
$form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('start_date', get_lang('ThisFieldIsRequired'), 'required');
//$form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Careers','Width' => '100%', 'Height' => '250'));
if ($action == 'edit') {
// Setting the defaults
$defaults = $this->get($id);
$form->addButtonSave(get_lang('Modify'), 'submit');
} else {
$form->addButtonCreate(get_lang('Add'), 'submit');
}
/*if (!empty($defaults['created_at'])) {
$defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
}
if (!empty($defaults['updated_at'])) {
$defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
}*/
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required');
return $form;
}
示例10: array
// the exercices
$tbl_exercices = Database::get_course_table(TABLE_QUIZ_TEST);
$course_id = api_get_course_int_id();
$sql = "SELECT iid,title,type,description, results_disabled\n FROM {$tbl_exercices} WHERE c_id = {$course_id} AND active<>'-1' AND session_id=" . $session_id . "\n ORDER BY title ASC";
$result = Database::query($sql);
$exercises['-'] = '-' . get_lang('SelectExercice') . '-';
while ($row = Database::fetch_array($result)) {
$exercises[$row['iid']] = Text::cut($row['title'], EXERCISE_MAX_NAME_SIZE);
}
$form->addElement('select', 'exercice', get_lang('Exercice'), $exercises);
// generate default content
$form->addElement('checkbox', 'is_content', null, get_lang('DefaultContent'), array('checked' => true));
// the submit button
$form->addElement('style_submit_button', 'SubmitCreateQuestion', get_lang('CreateQuestion'), 'class="add"');
// setting the rules
$form->addRule('exercice', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('exercice', get_lang('YouHaveToSelectATest'), 'numeric');
$form->registerRule('validquestiontype', 'callback', 'check_question_type');
$form->addRule('question_type_hidden', get_lang('InvalidQuestionType'), 'validquestiontype');
if ($form->validate()) {
$values = $form->exportValues();
$answer_type = $values['question_type_hidden'];
// check feedback_type from current exercise for type of question delineation
$exercise_id = intval($values['exercice']);
$exercise = new Exercise();
$exercise->read($exercise_id);
$feedback_type = $exercise->feedback_type;
// if question type does not belong to self-evaluation (immediate feedback) it'll send an error
if ($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1 || $feedback_type == 1 && ($answer_type != HOT_SPOT_DELINEATION && $answer_type != UNIQUE_ANSWER)) {
header('Location: question_create.php?' . api_get_cidreq() . '&error=true');
exit;
示例11: setForm
/**
* @param FormValidator $form
* @param string $type
* @param array $data
*/
public function setForm($form, $type = 'add', $data = array())
{
switch ($type) {
case 'add':
$header = get_lang('Add');
break;
case 'edit':
$header = get_lang('Edit');
break;
}
$form->addElement('header', $header);
//Name
$form->addElement('text', 'name', get_lang('Name'), array('maxlength' => 255));
$form->applyFilter('name', 'html_filter');
$form->applyFilter('name', 'trim');
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('name', '', 'maxlength', 255);
// Description
$form->addElement('textarea', 'description', get_lang('Description'), array('cols' => 58));
$form->applyFilter('description', 'html_filter');
$form->applyFilter('description', 'trim');
if ($this->showGroupTypeSetting) {
$form->addElement('checkbox', 'group_type', null, get_lang('SocialGroup'));
}
// url
$form->addElement('text', 'url', get_lang('Url'));
$form->applyFilter('url', 'html_filter');
$form->applyFilter('url', 'trim');
// Picture
$allowed_picture_types = $this->getAllowedPictureExtensions();
$form->addElement('file', 'picture', get_lang('AddPicture'));
$form->addRule('picture', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
if (isset($data['picture']) && strlen($data['picture']) > 0) {
$picture = $this->get_picture_group($data['id'], $data['picture'], 80);
$img = '<img src="' . $picture['file'] . '" />';
$form->addElement('label', null, $img);
$form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
}
$form->addElement('select', 'visibility', get_lang('GroupPermissions'), $this->getGroupStatusList());
$form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>');
// Setting the form elements
if ($type == 'add') {
$form->addButtonCreate($header);
} else {
$form->addButtonUpdate($header);
}
}
示例12: intval
//.........这里部分代码省略.........
// exploding all the selected values (of both select forms)
$selected_values = explode(';', $extra_data['extra_' . $field_details[1]]);
$extra_data['extra_' . $field_details[1]] = array();
// looping through the selected values and assigning the selected values to either the first or second select form
foreach ($selected_values as $key => $selected_value) {
if (array_key_exists($selected_value, $values[0])) {
$extra_data['extra_' . $field_details[1]]['extra_' . $field_details[1]] = $selected_value;
} else {
$extra_data['extra_' . $field_details[1]]['extra_' . $field_details[1] . '*'] = $selected_value;
}
}
}
break;
case ExtraField::FIELD_TYPE_DIVIDER:
$form->addElement('static', $field_details[1], '<br /><strong>' . $field_details[3] . '</strong>');
break;
case ExtraField::FIELD_TYPE_TAG:
//the magic should be here
$user_tags = UserManager::get_user_tags($user_id, $field_details[0]);
$tag_list = '';
if (is_array($user_tags) && count($user_tags) > 0) {
foreach ($user_tags as $tag) {
$tag_list .= '<option value="' . $tag['tag'] . '" class="selected">' . $tag['tag'] . '</option>';
}
}
$multi_select = '<select id="extra_' . $field_details[1] . '" name="extra_' . $field_details[1] . '">
' . $tag_list . '
</select>';
$form->addElement('label', $field_details[3], $multi_select);
$url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php';
$complete_text = get_lang('StartToType');
//if cache is set to true the jquery will be called 1 time
$jquery_ready_content = <<<EOF
\$("#extra_{$field_details['1']}").fcbkcomplete({
json_url: "{$url}?a=search_tags&field_id={$field_details['0']}",
cache: false,
filter_case: true,
filter_hide: true,
complete_text:"{$complete_text}",
firstselected: true,
//onremove: "testme",
//onselect: "testme",
filter_selected: true,
newel: true
});
EOF;
break;
case ExtraField::FIELD_TYPE_TIMEZONE:
$form->addElement('select', 'extra_' . $field_details[1], $field_details[3], api_get_timezones(), '');
if ($field_details[7] == 0) {
$form->freeze('extra_' . $field_details[1]);
}
break;
case ExtraField::FIELD_TYPE_SOCIAL_PROFILE:
// get the social network's favicon
$icon_path = UserManager::get_favicon_from_url($extra_data['extra_' . $field_details[1]], $field_details[4]);
// special hack for hi5
$leftpad = '1.7';
$top = '0.4';
$domain = parse_url($icon_path, PHP_URL_HOST);
if ($domain == 'www.hi5.com' or $domain == 'hi5.com') {
$leftpad = '3';
$top = '0';
}
// print the input field
$form->addElement('text', 'extra_' . $field_details[1], $field_details[3], array('size' => 60, 'style' => 'background-image: url(\'' . $icon_path . '\'); background-repeat: no-repeat; background-position: 0.4em ' . $top . 'em; padding-left: ' . $leftpad . 'em; '));
$form->applyFilter('extra_' . $field_details[1], 'stripslashes');
$form->applyFilter('extra_' . $field_details[1], 'trim');
if ($field_details[7] == 0) {
$form->freeze('extra_' . $field_details[1]);
}
break;
case ExtraField::FIELD_TYPE_FILE:
$extra_field = 'extra_' . $field_details[1];
$form->addElement('file', $extra_field, $field_details[3], null, '');
if ($extra_file_list = UserManager::build_user_extra_file_list($user_id, $field_details[1], '', true)) {
$form->addElement('static', $extra_field . '_list', null, $extra_file_list);
}
if ($field_details[7] == 0) {
$form->freeze($extra_field);
}
break;
case ExtraField::FIELD_TYPE_MOBILE_PHONE_NUMBER:
$form->addElement('text', 'extra_' . $field_details[1], $field_details[3] . " (" . get_lang('CountryDialCode') . ")", array('size' => 40, 'placeholder' => '(xx)xxxxxxxxx'));
$form->applyFilter('extra_' . $field_details[1], 'stripslashes');
$form->applyFilter('extra_' . $field_details[1], 'trim');
$form->applyFilter('extra_' . $field_details[1], 'mobile_phone_number_filter');
$form->addRule('extra_' . $field_details[1], get_lang('MobilePhoneNumberWrong'), 'mobile_phone_number');
if (!$admin_permissions) {
if ($field_details[7] == 0) {
$form->freeze('extra_' . $field_details[1]);
}
}
break;
}
}
$return = array();
$return['jquery_ready_content'] = $jquery_ready_content;
return $return;
}
示例13:
// setting the defaults
$glossary_data = GlossaryManager::get_glossary_information($_GET['glossary_id']);
// Date treatment for timezones
if (!empty($glossary_data['insert_date']) && $glossary_data['insert_date'] != '0000-00-00 00:00:00:') {
$glossary_data['insert_date'] = api_get_local_time($glossary_data['insert_date']);
} else {
$glossary_data['insert_date'] = '';
}
if (!empty($glossary_data['update_date']) && $glossary_data['update_date'] != '0000-00-00 00:00:00:') {
$glossary_data['update_date'] = api_get_local_time($glossary_data['update_date']);
} else {
$glossary_data['update_date'] = '';
}
$form->setDefaults($glossary_data);
// setting the rules
$form->addRule('glossary_title', get_lang('ThisFieldIsRequired'), 'required');
// The validation or display
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
GlossaryManager::update_glossary($values);
}
Security::clear_token();
GlossaryManager::display_glossary();
} else {
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
$form->display();
}
示例14: create
/**
* Create a form validator based on an array of form data:
*
* array(
* 'name' => 'zombie_report_parameters', //optional
* 'method' => 'GET', //optional
* 'items' => array(
* array(
* 'name' => 'ceiling',
* 'label' => 'Ceiling', //optional
* 'type' => 'date',
* 'default' => date() //optional
* ),
* array(
* 'name' => 'active_only',
* 'label' => 'ActiveOnly',
* 'type' => 'checkbox',
* 'default' => true
* ),
* array(
* 'name' => 'submit_button',
* 'type' => 'style_submit_button',
* 'value' => get_lang('Search'),
* 'attributes' => array('class' => 'search')
* )
* )
* );
*
* @param array $form_data
* @deprecated use normal FormValidator construct
*
* @return FormValidator
*/
public static function create($form_data)
{
if (empty($form_data)) {
return null;
}
$form_name = isset($form_data['name']) ? $form_data['name'] : 'form';
$form_method = isset($form_data['method']) ? $form_data['method'] : 'POST';
$form_action = isset($form_data['action']) ? $form_data['action'] : '';
$form_target = isset($form_data['target']) ? $form_data['target'] : '';
$form_attributes = isset($form_data['attributes']) ? $form_data['attributes'] : null;
$form_track_submit = isset($form_data['track_submit']) ? $form_data['track_submit'] : true;
$reset = null;
$result = new FormValidator($form_name, $form_method, $form_action, $form_target, $form_attributes, $form_track_submit);
$defaults = array();
foreach ($form_data['items'] as $item) {
$name = $item['name'];
$type = isset($item['type']) ? $item['type'] : 'text';
$label = isset($item['label']) ? $item['label'] : '';
if ($type == 'wysiwyg') {
$element = $result->addHtmlEditor($name, $label);
} else {
$element = $result->addElement($type, $name, $label);
}
if (isset($item['attributes'])) {
$attributes = $item['attributes'];
$element->setAttributes($attributes);
}
if (isset($item['value'])) {
$value = $item['value'];
$element->setValue($value);
}
if (isset($item['default'])) {
$defaults[$name] = $item['default'];
}
if (isset($item['rules'])) {
$rules = $item['rules'];
foreach ($rules as $rule) {
$message = $rule['message'];
$type = $rule['type'];
$format = isset($rule['format']) ? $rule['format'] : null;
$validation = isset($rule['validation']) ? $rule['validation'] : 'server';
$force = isset($rule['force']) ? $rule['force'] : false;
$result->addRule($name, $message, $type, $format, $validation, $reset, $force);
}
}
}
$result->setDefaults($defaults);
return $result;
}
示例15: display_item_form
/**
* Return the HTML form to display an item (generally a section/module item)
* @param string Item type (module/dokeos_module)
* @param string Title (optional, only when creating)
* @param string Action ('add'/'edit')
* @param integer lp_item ID
* @param mixed Extra info
* @return string HTML form
*/
public function display_item_form($item_type, $title = '', $action = 'add_item', $id = 0, $extra_info = 'new')
{
$course_id = api_get_course_int_id();
$_course = api_get_course_info();
global $charset;
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
if ($id != 0 && is_array($extra_info)) {
$item_title = $extra_info['title'];
$item_description = $extra_info['description'];
$item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
$item_path_fck = '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
} else {
$item_title = '';
$item_description = '';
$item_path_fck = '';
}
if ($id != 0 && is_array($extra_info)) {
$parent = $extra_info['parent_item_id'];
} else {
$parent = 0;
}
$id = intval($id);
$sql = "SELECT * FROM " . $tbl_lp_item . "\n WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id . " AND id != {$id}";
if ($item_type == 'module') {
$sql .= " AND parent_item_id = 0";
}
$result = Database::query($sql);
$arrLP = array();
while ($row = Database::fetch_array($result)) {
$arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite'], 'display_order' => $row['display_order']);
}
$this->tree_array($arrLP);
$arrLP = isset($this->arrMenu) ? $this->arrMenu : null;
unset($this->arrMenu);
$gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : null;
$url = api_get_self() . '?' . api_get_cidreq() . '&gradeboook=' . $gradebook . '&action=' . $action . '&type=' . $item_type . '&lp_id=' . $this->lp_id;
$form = new FormValidator('form', 'POST', $url);
$defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
$defaults['description'] = $item_description;
$form->addElement('header', $title);
//$arrHide = array($id);
$arrHide[0]['value'] = Security::remove_XSS($this->name);
$arrHide[0]['padding'] = 3;
$charset = api_get_system_encoding();
if ($item_type != 'module' && $item_type != 'dokeos_module') {
for ($i = 0; $i < count($arrLP); $i++) {
if ($action != 'add') {
if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
$arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
$arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
if ($parent == $arrLP[$i]['id']) {
$s_selected_parent = $arrHide[$arrLP[$i]['id']];
}
}
} else {
if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
$arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
$arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
if ($parent == $arrLP[$i]['id']) {
$s_selected_parent = $arrHide[$arrLP[$i]['id']];
}
}
}
}
if ($action != 'move') {
$form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
$form->applyFilter('title', 'html_filter');
$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
//$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
} else {
$form->addElement('hidden', 'title');
}
$parent_select = $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
foreach ($arrHide as $key => $value) {
$parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
}
if (!empty($s_selected_parent)) {
$parent_select->setSelected($s_selected_parent);
}
}
if (is_array($arrLP)) {
reset($arrLP);
}
$arrHide = array();
// POSITION
for ($i = 0; $i < count($arrLP); $i++) {
if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
//this is the same!
if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
$s_selected_position = $arrLP[$i]['id'];
} elseif ($action == 'add') {
//.........这里部分代码省略.........