本文整理汇总了PHP中FormValidator::addButtonCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP FormValidator::addButtonCreate方法的具体用法?PHP FormValidator::addButtonCreate怎么用?PHP FormValidator::addButtonCreate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormValidator
的用法示例。
在下文中一共展示了FormValidator::addButtonCreate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: createAnswersForm
/**
* Function which redefines Question::createAnswersForm
* @param FormValidator $form
*/
public function createAnswersForm($form)
{
$defaults = array();
$nb_matches = $nb_options = 2;
$matches = array();
$answer = null;
if ($form->isSubmitted()) {
$nb_matches = $form->getSubmitValue('nb_matches');
$nb_options = $form->getSubmitValue('nb_options');
if (isset($_POST['lessMatches'])) {
$nb_matches--;
}
if (isset($_POST['moreMatches'])) {
$nb_matches++;
}
if (isset($_POST['lessOptions'])) {
$nb_options--;
}
if (isset($_POST['moreOptions'])) {
$nb_options++;
}
} else {
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0) {
$nb_matches = $nb_options = 0;
for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
if ($answer->isCorrect($i)) {
$nb_matches++;
$defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
$defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1);
$answerInfo = $answer->getAnswerByAutoId($answer->correct[$i]);
$defaults['matches[' . $nb_matches . ']'] = isset($answerInfo['answer']) ? $answerInfo['answer'] : '';
} else {
$nb_options++;
$defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
}
}
}
} else {
$defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
$defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
$defaults['matches[2]'] = '2';
$defaults['option[1]'] = get_lang('DefaultMatchingOptA');
$defaults['option[2]'] = get_lang('DefaultMatchingOptB');
}
}
for ($i = 1; $i <= $nb_matches; ++$i) {
$matches[$i] = $i;
}
$form->addElement('hidden', 'nb_matches', $nb_matches);
$form->addElement('hidden', 'nb_options', $nb_options);
// DISPLAY MATCHES
$html = '<table class="table table-striped table-hover">
<thead>
<tr>
<th width="85%">' . get_lang('Answer') . '</th>
<th width="15%">' . get_lang('MatchesTo') . '</th>
<th width="10">' . get_lang('Weighting') . '</th>
</tr>
</thead>
<tbody>';
$form->addHeader(get_lang('MakeCorrespond'));
$form->addHtml($html);
if ($nb_matches < 1) {
$nb_matches = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_matches; ++$i) {
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]");
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]");
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]");
$form->addHtml('<tr>');
$form->addText("answer[{$i}]", null);
$form->addSelect("matches[{$i}]", null, $matches);
$form->addText("weighting[{$i}]", null, true, ['value' => 10, 'style' => 'width: 60px;']);
$form->addHtml('</tr>');
}
$form->addHtml('</tbody></table>');
$renderer->setElementTemplate('<div class="form-group"><div class="col-sm-offset-2">{element}', 'lessMatches');
$renderer->setElementTemplate('{element}</div></div>', 'moreMatches');
global $text;
$group = [$form->addButtonDelete(get_lang('DelElem'), 'lessMatches', true), $form->addButtonCreate(get_lang('AddElem'), 'moreMatches', true), $form->addButtonSave($text, 'submitQuestion', true)];
$form->addGroup($group);
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
$form->setConstants(['nb_matches' => $nb_matches, 'nb_options' => $nb_options]);
}
示例3: array
//Group Parentship
$groups = array();
$groups[0] = get_lang('NoParentship');
$groups = $groups + GroupPortalManager::get_groups_list($group_id);
$group_data['parent_group'] = GroupPortalManager::get_parent_group($group_id);
$form->addElement('select', 'parent_group', get_lang('GroupParentship'), $groups, array());
// Status
$status = array();
$status[GROUP_PERMISSION_OPEN] = get_lang('Open');
$status[GROUP_PERMISSION_CLOSED] = get_lang('Closed');
$form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status);
// Set default values
$defaults['status'] = GROUP_PERMISSION_OPEN;
$form->setDefaults($defaults);
// Submit button
$form->addButtonCreate(get_lang('Add'));
// Validate form
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$picture_element = $form->getElement('picture');
$picture = $picture_element->getValue();
$picture_uri = '';
$name = $values['name'];
$description = $values['description'];
$url = $values['url'];
$status = intval($values['visibility']);
$picture = $_FILES['picture'];
$parent_group_id = intval($values['parent_group']);
$group_id = GroupPortalManager::add($name, $description, $url, $status);
示例4: 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
//.........这里部分代码省略.........
示例5: array
$form->addElement('text', 'code', get_lang("CategoryCode"));
$form->addElement('text', 'name', get_lang("CategoryName"));
$form->addRule('name', get_lang('PleaseEnterCategoryInfo'), 'required');
$form->addRule('code', get_lang('PleaseEnterCategoryInfo'), 'required');
$group = array($form->createElement('radio', 'auth_course_child', get_lang("AllowCoursesInCategory"), get_lang('Yes'), 'TRUE'), $form->createElement('radio', 'auth_course_child', null, get_lang('No'), 'FALSE'));
$form->addGroup($group, null, get_lang("AllowCoursesInCategory"));
if (!empty($categoryInfo)) {
$class = "save";
$text = get_lang('Save');
$form->setDefaults($categoryInfo);
$form->addButtonSave($text);
} else {
$class = "add";
$text = get_lang('AddCategory');
$form->setDefaults(array('auth_course_child' => 'TRUE'));
$form->addButtonCreate($text);
}
$form->display();
} elseif (api_get_multiple_access_url() && api_get_current_access_url_id() != 1) {
// If multiple URLs and not main URL, prevent edition and inform user
Display::display_warning_message(get_lang('CourseCategoriesAreGlobal'));
}
} else {
// If multiple URLs and not main URL, prevent deletion and inform user
if ($action == 'delete' && api_get_multiple_access_url() && api_get_current_access_url_id() != 1) {
Display::display_warning_message(get_lang('CourseCategoriesAreGlobal'));
}
echo '<div class="actions">';
$link = null;
if (!empty($parentInfo)) {
$parentCode = $parentInfo['parent_id'];
示例6: 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;
}
示例7: return_form
/**
* @param string $url
* @param string $action
* @return FormValidator
*/
public function return_form($url, $action)
{
$form = new FormValidator($this->type . '_field', 'post', $url);
$form->addElement('hidden', 'type', $this->type);
$id = isset($_GET['id']) ? intval($_GET['id']) : null;
$form->addElement('hidden', 'id', $id);
// Setting the form elements
$header = get_lang('Add');
$defaults = array();
if ($action == 'edit') {
$header = get_lang('Modify');
// Setting the defaults
$defaults = $this->get($id);
}
$form->addElement('header', $header);
$form->addElement('text', 'display_text', get_lang('Name'), array('class' => 'span5'));
// Field type
$types = self::get_field_types();
$form->addElement('select', 'field_type', get_lang('FieldType'), $types, array('id' => 'field_type'));
$form->addElement('label', get_lang('Example'), '<div id="example">-</div>');
$form->addElement('text', 'variable', get_lang('FieldLabel'), array('class' => 'span5'));
$form->addElement('text', 'field_options', get_lang('FieldPossibleValues'), array('id' => 'field_options', 'class' => 'span6'));
$fieldWithOptions = array(ExtraField::FIELD_TYPE_RADIO, ExtraField::FIELD_TYPE_SELECT_MULTIPLE, ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_TAG, ExtraField::FIELD_TYPE_DOUBLE_SELECT);
if ($action == 'edit') {
if (in_array($defaults['field_type'], $fieldWithOptions)) {
$url = Display::url(get_lang('EditExtraFieldOptions'), 'extra_field_options.php?type=' . $this->type . '&field_id=' . $id);
$form->addElement('label', null, $url);
if ($defaults['field_type'] == ExtraField::FIELD_TYPE_SELECT) {
$urlWorkFlow = Display::url(get_lang('EditExtraFieldWorkFlow'), 'extra_field_workflow.php?type=' . $this->type . '&field_id=' . $id);
$form->addElement('label', null, $urlWorkFlow);
}
$form->freeze('field_options');
}
}
$form->addElement('text', 'default_value', get_lang('FieldDefaultValue'), array('id' => 'default_value'));
$group = array();
$group[] = $form->createElement('radio', 'visible', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'visible', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('Visible'), '', false);
$group = array();
$group[] = $form->createElement('radio', 'changeable', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'changeable', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('FieldChangeability'), '', false);
$group = array();
$group[] = $form->createElement('radio', 'filter', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'filter', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('FieldFilter'), '', false);
/* Enable this when field_loggeable is introduced as a table field (2.0)
$group = array();
$group[] = $form->createElement('radio', 'field_loggeable', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'field_loggeable', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('FieldLoggeable'), '', false);
*/
$form->addElement('text', 'field_order', get_lang('FieldOrder'), array('class' => 'span1'));
if ($action == 'edit') {
$option = new ExtraFieldOption($this->type);
if ($defaults['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
$form->freeze('field_options');
}
$defaults['field_options'] = $option->get_field_options_by_field_to_string($id);
$form->addButtonUpdate(get_lang('Modify'));
} else {
$defaults['visible'] = 0;
$defaults['changeable'] = 0;
$defaults['filter'] = 0;
$form->addButtonCreate(get_lang('Add'));
}
/*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('display_text', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('field_type', get_lang('ThisFieldIsRequired'), 'required');
return $form;
}
示例8: return_form
/**
* Returns a Form validator Obj
* @todo the form should be auto generated
* @param string $url
* @param string $action add, edit
*
* @return FormValidator form validator obj
*/
public function return_form($url, $action)
{
$form = new FormValidator('grades', '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'));
$form->addElement('label', get_lang('Components'));
// Get components
$nr_items = 2;
$max = 10;
// Setting the defaults
$defaults = $this->get($id);
$components = $this->get_components($defaults['id']);
if ($action == 'edit') {
if (!empty($components)) {
$nr_items = count($components) - 1;
}
}
$form->addElement('hidden', 'maxvalue', '100');
$form->addElement('hidden', 'minvalue', '0');
$renderer =& $form->defaultRenderer();
$component_array = array();
for ($i = 0; $i <= $max; $i++) {
$counter = $i;
$form->addElement('text', 'components[' . $i . '][percentage]', null);
$form->addElement('text', 'components[' . $i . '][acronym]', null);
$form->addElement('text', 'components[' . $i . '][title]', null);
$form->addElement('hidden', 'components[' . $i . '][id]', null);
$template_percentage = '<div id=' . $i . ' style="display: ' . ($i <= $nr_items ? 'inline' : 'none') . ';" class="control-group">
<p>
<label class="control-label">{label}</label>
<div class="controls">
<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
{element} <!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --> % = ';
$template_acronym = '
<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
{element} {label} <!-- BEGIN error --><span class="form_error">{error}</span> <!-- END error -->';
$template_title = ' {element} <!-- BEGIN error --> <span class="form_error">{error}</span><!-- END error -->
<a href="javascript:plusItem(' . ($counter + 1) . ')">
<img style="display: ' . ($counter >= $nr_items ? 'inline' : 'none') . ';" id="plus-' . ($counter + 1) . '" src="../img/icons/22/add.png" alt="' . get_lang('Add') . '" title="' . get_lang('Add') . '"></img>
</a>
<a href="javascript:minItem(' . $counter . ')">
<img style="display: ' . ($counter >= $nr_items ? 'inline' : 'none') . ';" id="min-' . $counter . '" src="../img/delete.png" alt="' . get_lang('Delete') . '" title="' . get_lang('Delete') . '"></img>
</a>
</div></p></div>';
$renderer->setElementTemplate($template_title, 'components[' . $i . '][title]');
$renderer->setElementTemplate($template_percentage, 'components[' . $i . '][percentage]');
$renderer->setElementTemplate($template_acronym, 'components[' . $i . '][acronym]');
if ($i == 0) {
$form->addRule('components[' . $i . '][percentage]', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('components[' . $i . '][title]', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('components[' . $i . '][acronym]', get_lang('ThisFieldIsRequired'), 'required');
}
$form->addRule('components[' . $i . '][percentage]', get_lang('OnlyNumbers'), 'numeric');
$form->addRule(array('components[' . $i . '][percentage]', 'maxvalue'), get_lang('Over100'), 'compare', '<=');
$form->addRule(array('components[' . $i . '][percentage]', 'minvalue'), get_lang('UnderMin'), 'compare', '>=');
$component_array[] = 'components[' . $i . '][percentage]';
}
//New rule added in the formvalidator compare_fields that filters a group of fields in order to compare with the wanted value
$form->addRule($component_array, get_lang('AllMustWeight100'), 'compare_fields', '==@100');
$form->addElement('label', '', get_lang('AllMustWeight100'));
if ($action == 'edit') {
$form->addButtonUpdate(get_lang('Modify'));
} else {
$form->addButtonCreate(get_lang('Add'));
}
if (!empty($components)) {
$counter = 0;
foreach ($components as $component) {
foreach ($component as $key => $value) {
$defaults['components[' . $counter . '][' . $key . ']'] = $value;
}
$counter++;
}
}
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
return $form;
}
示例9: createAnswersForm
//.........这里部分代码省略.........
$defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1);
$defaults['matches[' . $nb_matches . ']'] = $answer->correct[$i];
} else {
$nb_options++;
$defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
}
}
}
} else {
$defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
$defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
$defaults['matches[2]'] = '2';
$defaults['option[1]'] = get_lang('DefaultMatchingOptA');
$defaults['option[2]'] = get_lang('DefaultMatchingOptB');
}
}
if (empty($matches)) {
for ($i = 1; $i <= $nb_options; ++$i) {
// fill the array with A, B, C.....
$matches[$i] = chr(64 + $i);
}
} else {
for ($i = $counter; $i <= $nb_options; ++$i) {
// fill the array with A, B, C.....
$matches[$i] = chr(64 + $i);
}
}
$form->addElement('hidden', 'nb_matches', $nb_matches);
$form->addElement('hidden', 'nb_options', $nb_options);
// DISPLAY MATCHES
$html = '<table class="table table-striped table-hover">
<thead>
<tr>
<th width="5%">' . get_lang('Number') . '</th>
<th width="70%">' . get_lang('Answer') . '</th>
<th width="15%">' . get_lang('MatchesTo') . '</th>
<th width="10%">' . get_lang('Weighting') . '</th>
</tr>
</thead>
<tbody>';
$form->addHeader(get_lang('MakeCorrespond'));
$form->addHtml($html);
if ($nb_matches < 1) {
$nb_matches = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_matches; ++$i) {
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]");
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]");
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]");
$form->addHtml('<tr>');
$form->addHtml("<td>{$i}</td>");
$form->addText("answer[{$i}]", null);
$form->addSelect("matches[{$i}]", null, $matches);
$form->addText("weighting[{$i}]", null, true, ['value' => 10]);
$form->addHtml('</tr>');
}
$form->addHtml('</tbody></table>');
$group = array();
$form->addGroup($group);
// DISPLAY OPTIONS
$html = '<table class="table table-striped table-hover">
<thead>
<tr>
<th width="15%">' . get_lang('Number') . '</th>
<th width="85%">' . get_lang('Answer') . '</th>
</tr>
</thead>
<tbody>';
$form->addHtml($html);
if ($nb_options < 1) {
$nb_options = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_options; ++$i) {
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "option[{$i}]");
$form->addHtml('<tr>');
$form->addHtml('<td>' . chr(64 + $i) . '</td>');
$form->addText("option[{$i}]", null);
$form->addHtml('</tr>');
}
$form->addHtml('</table>');
$group = array();
global $text;
// setting the save button here and not in the question class.php
$group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessOptions', true);
$group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreOptions', true);
$group[] = $form->addButtonSave($text, 'submitQuestion', true);
$form->addGroup($group);
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
$form->setConstants(array('nb_matches' => $nb_matches, 'nb_options' => $nb_options));
}
示例10: switch
$viewFromSession = Session::read('glossary_view');
if (!isset($viewFromSession)) {
// Default option
Session::write('glossary_view', 'table');
}
}
if (api_is_allowed_to_edit(null, true)) {
switch ($action) {
case 'addglossary':
$form = new FormValidator('glossary', 'post', api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&' . api_get_cidreq());
// Setting the form elements
$form->addElement('header', '', get_lang('TermAddNew'));
$form->addElement('text', 'glossary_title', get_lang('TermName'), array('size' => '80', 'id' => 'glossary_title'));
//$form->applyFilter('glossary_title', 'html_filter');
$form->addHtmlEditor('glossary_comment', get_lang('TermDefinition'), false, false, array('ToolbarSet' => 'Glossary', 'Height' => '300'));
$form->addButtonCreate(get_lang('TermAddButton'), 'SubmitGlossary');
// 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::save_glossary($values);
}
Security::clear_token();
GlossaryManager::display_glossary();
} else {
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
示例11: array
// Form title
$form->addElement('header', get_lang('AddLpToStart'));
// Title
$form->addElement('text', 'lp_name', api_ucfirst(get_lang('LPName')), array('autofocus' => 'autofocus'));
$form->applyFilter('lp_name', 'html_filter');
$form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'post_time', time());
$form->addElement('hidden', 'action', 'add_lp');
$form->addButtonAdvancedSettings('advanced_params');
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
$items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), true);
$form->addElement('select', 'category_id', get_lang('Category'), $items);
// Start date
$form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
$form->addElement('html', '<div id="start_date_div" style="display:block;">');
$form->addElement('DatePicker', 'publicated_on', get_lang('PublicationDate'));
$form->addElement('html', '</div>');
//End date
$form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
$form->addElement('html', '<div id="end_date_div" style="display:none;">');
$form->addElement('DatePicker', 'expired_on', get_lang('ExpirationDate'));
$form->addElement('html', '</div>');
$form->addElement('html', '</div>');
$defaults['activate_start_date_check'] = 1;
$defaults['publicated_on'] = date('Y-m-d 08:00:00');
$defaults['expired_on'] = date('Y-m-d 08:00:00', time() + 86400);
$form->setDefaults($defaults);
$form->addButtonCreate(get_lang('CreateLearningPath'));
$form->display();
// Footer
Display::display_footer();
示例12: show_skill_form
/**
* Returns a Form validator Obj
* @todo the form should be auto generated
* @param string url
* @param string action add, edit
* @return obj form validator obj
*/
public function show_skill_form($gradebook_id, $url, $header = null)
{
$form = new FormValidator('gradebook_add_skill', 'POST', $url);
// Setting the form elements
if (!isset($header)) {
$header = get_lang('Add');
}
$form->addElement('header', '', $header);
$id = isset($_GET['id']) ? intval($_GET['id']) : '';
$form->addElement('hidden', 'id', $id);
$skill = new Skill();
$skills = $skill->get_all();
$clean_skill_list = array();
foreach ($skills as $skill) {
$clean_skill_list[$skill['id']] = $skill['name'];
}
$form->addElement('select', 'skill', get_lang('Skills'), $clean_skill_list, array('multiple' => 'multiple'));
$selected_skills = self::get_skills_by_gradebook($gradebook_id);
$clean_selected_skills = array();
if (!empty($selected_skills)) {
foreach ($selected_skills as $skill) {
$clean_selected_skills[] = $skill['id'];
}
}
$form->addButtonCreate(get_lang('Add'), 'submit');
$form->setDefaults(array('skill' => $clean_selected_skills));
return $form;
}
示例13:
}
}
}
}
$form->addElement('html', '</div>');
}
}
$form->addElement('html', '</div><br />');
if (isset($_GET['survey_id']) && $_GET['action'] == 'edit') {
$class = 'save';
$text = get_lang('ModifySurvey');
$form->addButtonUpdate(get_lang('ModifySurvey'), 'submit_survey');
} else {
$class = 'add';
$text = get_lang('CreateSurvey');
$form->addButtonCreate(get_lang('CreateSurvey'), 'submit_survey');
}
// Setting the rules
if ($_GET['action'] == 'add') {
$form->addRule('survey_code', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('survey_code', '', 'maxlength', 20);
}
$form->addRule('survey_title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('start_date', get_lang('InvalidDate'), 'date');
$form->addRule('end_date', get_lang('InvalidDate'), 'date');
$form->addRule(array('start_date', 'end_date'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
// Setting the default values
$form->setDefaults($defaults);
// The validation or display
if ($form->validate()) {
// Exporting the values
示例14: elseif
$prev = '000';
} elseif ($group_id < 100) {
$prev = '00';
} elseif ($group_id < 1000) {
$prev = '0';
} else {
$prev = '';
}
}
$defaults['group_' . $group_number . '_name'] = get_lang('GroupSingle') . ' ' . $prev . $group_id++;
$form->addGroup($group_el, 'group_' . $group_number, null, '</td><td>', false);
}
$defaults['action'] = 'create_groups';
$defaults['number_of_groups'] = intval($_POST['number_of_groups']);
$form->setDefaults($defaults);
$form->addButtonCreate(get_lang('CreateGroup'), 'submit');
$form->display();
}
} else {
/*
* Show form to generate new groups
*/
$create_groups_form = new FormValidator('create_groups', 'post', api_get_self() . '?' . api_get_cidreq());
$create_groups_form->addElement('header', $nameTools);
/* $group_el = array ();
$group_el[] = $create_groups_form->createElement('text', 'number_of_groups', array(get_lang('Create'), '1'));
$group_el[] = $create_groups_form->addButtonCreate(get_lang('ProceedToCreateGroup'), 'submit', true);
$create_groups_form->addGroup($group_el, 'create_groups', get_lang('NumberOfGroupsToCreate'), ' ', false);
*/
$create_groups_form->addText('number_of_groups', get_lang('NumberOfGroupsToCreate'), null, array('value' => '1'));
$create_groups_form->addButton('submit', get_lang('ProceedToCreateGroup'), 'plus', 'primary');
示例15: FormValidator
$form->addRule('english_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('text', 'isocode', get_lang('ISOCode'), 'class="input_titles"');
$form->addRule('isocode', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('static', null, ' ', '<i>en, es, fr</i>');
$form->addElement('checkbox', 'sub_language_is_visible', '', get_lang('Visibility'));
$form->addButtonCreate(get_lang('CreateSubLanguage'), 'SubmitAddNewLanguage');
//$values['original_name'] = $language_details['original_name'].'...'; -> cannot be used because of quickform filtering (freeze)
$values['english_name'] = $language_details['english_name'] . '2';
$values['isocode'] = $language_details['isocode'];
$form->setDefaults($values);
$form->display();
} else {
if (isset($_GET['action']) && $_GET['action'] == 'deletesublanguage') {
$text = $language_name;
$form = new FormValidator('deletesublanguage', 'post', 'sub_language_add.php?id=' . Security::remove_XSS($_GET['id']) . '&sub_language_id=' . Security::remove_XSS($_GET['sub_language_id']));
$class = 'minus';
$form->addElement('header', '', $text);
$form->addElement('static', '', get_lang('OriginalName'), $original_name);
$form->addElement('static', '', get_lang('EnglishName'), $english_name);
$form->addElement('static', '', get_lang('PlatformCharsetTitle'), $isocode);
$form->addButtonCreate(get_lang('DeleteSubLanguage'), 'SubmitAddDeleteLanguage');
$form->display();
}
if (isset($_GET['action']) && $_GET['action'] == 'definenewsublanguage') {
Display::display_normal_message(get_lang('TheSubLanguageForThisLanguageHasBeenAdded'));
}
}
/**
* Footer
*/
Display::display_footer();