本文整理汇总了PHP中FormValidator::setDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP FormValidator::setDefaults方法的具体用法?PHP FormValidator::setDefaults怎么用?PHP FormValidator::setDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormValidator
的用法示例。
在下文中一共展示了FormValidator::setDefaults方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createAnswersForm
/**
* function which redefine Question::createAnswersForm
* @param FormValidator $form
*/
function createAnswersForm($form)
{
$form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1'));
global $text, $class;
// setting the save button here and not in the question class.php
$form->addButtonSave($text, 'submitQuestion');
if (!empty($this->id)) {
$form->setDefaults(array('weighting' => float_format($this->weighting, 1)));
} else {
if ($this->isContent == 1) {
$form->setDefaults(array('weighting' => '10'));
}
}
}
示例2: render
/**
* @param FormValidator $form
* @param array $questionData
* @param array $answers
*/
public function render(FormValidator $form, $questionData = array(), $answers = '')
{
$name = 'question' . $questionData['question_id'];
$form->addSelect($name, null, $questionData['options']);
if (!empty($answers)) {
$form->setDefaults([$name => $answers]);
}
}
示例3: render
/**
* @param FormValidator $form
* @param array $questionData
* @param string $answers
*/
public function render(FormValidator $form, $questionData = array(), $answers = '')
{
if (is_array($answers)) {
$content = implode('', $answers);
} else {
$content = $answers;
}
$name = 'question' . $questionData['question_id'];
$form->addTextarea($name, null);
$form->setDefaults([$name => $answers]);
}
示例4: render
/**
* @param FormValidator $form
* @param array $questionData
* @param array $answers
*/
public function render(FormValidator $form, $questionData = array(), $answers = '')
{
$options = array('--' => '--');
foreach ($questionData['options'] as $key => &$value) {
$options[$key] = $value;
}
$name = 'question' . $questionData['question_id'];
$form->addSelect($name, null, $options);
if (!empty($answers)) {
$form->setDefaults([$name => $answers]);
}
}
示例5: edit_category_form
/**
* @todo move to testcategory.class.php
* @param string $in_action
*/
function edit_category_form($in_action)
{
$in_action = Security::remove_XSS($in_action);
if (isset($_GET['category_id']) && is_numeric($_GET['category_id'])) {
$category_id = Security::remove_XSS($_GET['category_id']);
$objcat = new Testcategory($category_id);
// initiate the object
$form = new FormValidator('note', 'post', api_get_self() . '?action=' . $in_action . '&category_id=' . $category_id);
// settting the form elements
$form->addElement('header', get_lang('EditCategory'));
$form->addElement('hidden', 'category_id');
$form->addElement('text', 'category_name', get_lang('CategoryName'), array('size' => '95'));
$form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
$form->addElement('style_submit_button', 'SubmitNote', get_lang('ModifyCategory'), 'class="add"');
// setting the defaults
$defaults = array();
$defaults["category_id"] = $objcat->id;
$defaults["category_name"] = $objcat->name;
$defaults["category_description"] = $objcat->description;
$form->setDefaults($defaults);
// setting the rules
$form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
// The validation or display
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$v_id = Security::remove_XSS($values['category_id']);
$v_name = Security::remove_XSS($values['category_name'], COURSEMANAGER);
$v_description = Security::remove_XSS($values['category_description'], COURSEMANAGER);
$objcat = new Testcategory($v_id, $v_name, $v_description);
if ($objcat->modifyCategory()) {
Display::display_confirmation_message(get_lang('MofidfyCategoryDone'));
} else {
Display::display_confirmation_message(get_lang('ModifyCategoryError'));
}
}
Security::clear_token();
} else {
display_goback();
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
$form->display();
}
} else {
Display::display_error_message(get_lang('CannotEditCategory'));
}
}
示例6: render
/**
* @param FormValidator $form
* @param array $questionData
* @param array $answers
*/
public function render(FormValidator $form, $questionData = array(), $answers = null)
{
if (is_array($questionData['options'])) {
if ($questionData['display'] == 'vertical') {
$class = 'radio';
} else {
$class = 'radio-inline';
}
$name = 'question' . $questionData['question_id'];
$form->addRadio($name, null, $questionData['options'], ['radio-class' => $class, 'label-class' => $class]);
if (!empty($answers)) {
$form->setDefaults([$name => $answers]);
}
}
}
示例7: render
/**
* @param FormValidator $form
* @param array $questionData
* @param array $answers
*/
public function render(FormValidator $form, $questionData = array(), $answers = array())
{
if ($questionData['display'] == 'vertical') {
$class = 'checkbox';
} else {
$class = 'checkbox-inline';
}
$name = 'question' . $questionData['question_id'];
$form->addCheckBoxGroup($name, null, $questionData['options'], array('checkbox-class' => $class, 'label-class' => $class));
$defaults = [];
if (!empty($answers)) {
foreach ($answers as $answer) {
$defaults[$name . '[' . $answer . ']'] = true;
}
}
$form->setDefaults($defaults);
}
示例8: settingsForm
/**
* Returns a form displaying all options for this tool.
* These are
* - make all files visible / invisible
* - set the default visibility of uploaded files
* @param $defaults
* @return string The HTML form
*/
function settingsForm($defaults)
{
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
if (!$is_allowed_to_edit) {
return;
}
$url = api_get_path(WEB_CODE_PATH) . 'work/work.php?' . api_get_cidreq() . '&action=settings';
$form = new FormValidator('edit_settings', 'post', $url);
$form->addElement('hidden', 'changeProperties', 1);
$form->addElement('header', get_lang('EditToolOptions'));
$group = array($form->createElement('radio', 'show_score', null, get_lang('NewVisible'), 0), $form->createElement('radio', 'show_score', null, get_lang('NewUnvisible'), 1));
$form->addGroup($group, '', get_lang('DefaultUpload'));
$group = array($form->createElement('radio', 'student_delete_own_publication', null, get_lang('Yes'), 1), $form->createElement('radio', 'student_delete_own_publication', null, get_lang('No'), 0));
$form->addGroup($group, '', get_lang('StudentAllowedToDeleteOwnPublication'));
$form->addButtonSave(get_lang('Save'));
$form->setDefaults($defaults);
return $form->returnForm();
}
示例9: render
/**
* @param FormValidator $form
* @param array $questionData
* @param array $answers
*/
public function render(FormValidator $form, $questionData = array(), $answers = array())
{
$defaults = [];
foreach ($questionData['options'] as $key => &$value) {
$options = array();
for ($i = 1; $i <= $questionData['maximum_score']; $i++) {
$options[$i] = $i;
}
$name = 'question' . $questionData['question_id'] . '[' . $key . ']';
$form->addSelect($name, $value, $options);
if (!empty($answers)) {
if (in_array($key, array_keys($answers))) {
$defaults[$name] = $answers[$key];
}
}
}
if (!empty($defaults)) {
$form->setDefaults($defaults);
}
}
示例10: 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;
}
示例11: intval
}
$form->addElement('select', 'exercise_id', get_lang('Exercise'), $exercise_list);
}
//$form->addElement('submit','submit',get_lang('Filter'));
$form->addElement('style_submit_button', 'submit', get_lang('Filter'), 'class="search"');
if (!empty($_REQUEST['score'])) {
$filter_score = intval($_REQUEST['score']);
} else {
$filter_score = 70;
}
if (!empty($_REQUEST['exercise_id'])) {
$exercise_id = intval($_REQUEST['exercise_id']);
} else {
$exercise_id = 0;
}
$form->setDefaults(array('score' => $filter_score));
if (!$export_to_xls) {
Display::display_header(get_lang('Reporting'));
echo '<div class="actions">';
if ($global) {
echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'auth/my_progress.php">' . Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM);
echo '</a>';
echo '<span style="float:right">';
echo '<a href="' . api_get_self() . '?export=1&score=' . $filter_score . '&exercise_id=' . $exercise_id . '">' . Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '<a href="javascript: void(0);" onclick="javascript: window.print()">' . Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '</span>';
$menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), 32), api_get_path(WEB_CODE_PATH) . 'mySpace/?view=teacher');
if (api_is_platform_admin()) {
$menu_items[] = Display::url(Display::return_icon('star.png', get_lang('AdminInterface'), array(), 32), api_get_path(WEB_CODE_PATH) . 'mySpace/?view=admin');
} else {
$menu_items[] = Display::url(Display::return_icon('star.png', get_lang('CoachInterface'), array(), 32), api_get_path(WEB_CODE_PATH) . 'mySpace/?view=coach');
示例12: createAnswersForm
//.........这里部分代码省略.........
tabInputSize[idnum] = thewidth;
}
});
}
function changeInputSize(inCoef, inIdNum)
{
var currentWidth = $("#samplesize\\\\["+inIdNum+"\\\\]").width();
var newWidth = currentWidth + inCoef * 20;
newWidth = Math.max(20, newWidth);
newWidth = Math.min(newWidth, 600);
$("#samplesize\\\\["+inIdNum+"\\\\]").width(newWidth);
$("#sizeofinput\\\\["+inIdNum+"\\\\]").attr("value", newWidth);
}
function removeForbiddenChars(inTxt) {
outTxt = inTxt;
outTxt = outTxt.replace(/"/g, ""); // remove the char
outTxt = outTxt.replace(/\\x22/g, ""); // remove the char
outTxt = outTxt.replace(/"/g, ""); // remove the char
outTxt = outTxt.replace(/\\\\/g, ""); // remove the \\ char
outTxt = outTxt.replace(/ /g, " ");
outTxt = outTxt.replace(/^ +/, "");
outTxt = outTxt.replace(/ +$/, "");
return outTxt;
}
function changeBlankSeparator()
{
var separatorNumber = $("#select_separator").val();
var tabSeparator = getSeparatorFromNumber(separatorNumber);
blankSeparatortStart = tabSeparator[0];
blankSeparatortEnd = tabSeparator[1];
blankSeparatortStartRegexp = getBlankSeparatorRegexp(blankSeparatortStart);
blankSeparatortEndRegexp = getBlankSeparatorRegexp(blankSeparatortEnd);
updateBlanks();
}
// this function is the same than the PHP one
// if modify it modify the php one escapeForRegexp
function getBlankSeparatorRegexp(inTxt)
{
var tabSpecialChar = new Array(".", "+", "*", "?", "[", "^", "]", "$", "(", ")",
"{", "}", "=", "!", "<", ">", "|", ":", "-", ")");
for (var i=0; i < tabSpecialChar.length; i++) {
if (inTxt == tabSpecialChar[i]) {
return "\\\\"+inTxt;
}
}
return inTxt;
}
// this function is the same than the PHP one
// if modify it modify the php one getAllowedSeparator
function getSeparatorFromNumber(innumber)
{
tabSeparator = new Array();
tabSeparator[0] = new Array("[", "]");
tabSeparator[1] = new Array("{", "}");
tabSeparator[2] = new Array("(", ")");
tabSeparator[3] = new Array("*", "*");
tabSeparator[4] = new Array("#", "#");
tabSeparator[5] = new Array("%", "%");
tabSeparator[6] = new Array("$", "$");
return tabSeparator[innumber];
}
function trimBlanksBetweenSeparator(inTxt, inSeparatorStart, inSeparatorEnd)
{
// blankSeparatortStartRegexp
// blankSeparatortEndRegexp
var result = inTxt
result = result.replace(inSeparatorStart, "");
result = result.replace(inSeparatorEnd, "");
result = result.trim();
return inSeparatorStart+result+inSeparatorEnd;
}
</script>';
// answer
$form->addElement('label', null, '<br /><br />' . get_lang('TypeTextBelow') . ', ' . get_lang('And') . ' ' . get_lang('UseTagForBlank'));
$form->addHtmlEditor('answer', Display::return_icon('fill_field.png'), ['id' => 'answer', 'onkeyup' => "javascript: updateBlanks(this);"], array('ToolbarSet' => 'TestQuestionDescription'));
$form->addRule('answer', get_lang('GiveText'), 'required');
//added multiple answers
$form->addElement('checkbox', 'multiple_answer', '', get_lang('FillInBlankSwitchable'));
$form->addElement('select', 'select_separator', get_lang("SelectFillTheBlankSeparator"), self::getAllowedSeparatorForSelect(), ' id="select_separator" style="width:150px" onchange="changeBlankSeparator()" ');
$form->addElement('label', null, '<input type="button" onclick="updateBlanks()" value="' . get_lang('RefreshBlanks') . '" class="btn btn-default" />');
$form->addElement('html', '<div id="blanks_weighting"></div>');
global $text;
// setting the save button here and not in the question class.php
$form->addElement('html', '<div id="defineoneblank" style="color:#D04A66; margin-left:160px">' . get_lang('DefineBlanks') . '</div>');
$form->addButtonSave($text, 'submitQuestion');
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
}
示例13: createAnswersForm
//.........这里部分代码省略.........
<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
}
$renderer->setElementTemplate('{element} ', 'lessAnswers');
$renderer->setElementTemplate('{element} ', 'submitQuestion');
$renderer->setElementTemplate('{element}', 'moreAnswers');
$form->addElement('html', '</div></div>');
$defaults['correct'] = $correct;
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
示例14: isset
}
$values['group'] = isset($values['group']) ? $values['group'] : '0';
$form->addElement('checkbox', 'send_mail', null, get_lang('SendMail'));
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') {
$form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
$text = get_lang('AddNews');
$class = 'add';
$form->addElement('hidden', 'action', 'add');
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
$text = get_lang('EditNews');
$class = 'save';
$form->addElement('hidden', 'action', 'edit');
}
$form->addElement('checkbox', 'send_email_test', null, get_lang('SendOnlyAnEmailToMySelfToTest'));
$form->addButtonSend($text, 'submit');
$form->setDefaults($values);
if ($form->validate()) {
$values = $form->exportValues();
if (!isset($values['visible_teacher'])) {
$values['visible_teacher'] = false;
}
if (!isset($values['visible_student'])) {
$values['visible_student'] = false;
}
if (!isset($values['visible_guest'])) {
$values['visible_guest'] = false;
}
if ($values['lang'] == 'all') {
$values['lang'] = null;
}
$sendMail = isset($values['send_mail']) ? $values['send_mail'] : null;
示例15: getCategoryForm
/**
* @param int $id
* @param string $action
*
* @return FormValidator
*/
public static function getCategoryForm($id, $action)
{
$form = new FormValidator('category', 'post', api_get_self() . '?action=' . $action . '&' . api_get_cidreq());
$defaults = [];
if ($action == 'addcategory') {
$form->addHeader(get_lang('CategoryAdd'));
$my_cat_title = get_lang('CategoryAdd');
} else {
$form->addHeader(get_lang('CategoryMod'));
$my_cat_title = get_lang('CategoryMod');
$defaults = self::getCategory($id);
}
$form->addHidden('id', $id);
$form->addText('category_title', get_lang('CategoryName'));
$form->addTextarea('description', get_lang('Description'));
$form->addButtonSave($my_cat_title, 'submitCategory');
$form->setDefaults($defaults);
return $form;
}