Reputation: 66
I'm trying to add a 'help text' to the questions added by the Form block. Something like this but on the front-end part of the form.
For some reason its not saving the value or getting the value into the edit form. Even when I add it manually to the row it is not in the frontend output.
I made a custom form block / template with the additional changes to:
An extra table column 'helptext' in the db.xml. And updated the block.
<table name="btFormQuestions">
...
<field name="helptext" type="text">
<default value=""/>
</field>
...
</table>
An extra field on the editing form (normal and edit):
<div class="form-group">
<?php echo $form->label('helptext', t('Help Text'))?>
<?php echo $form->text('helptext', array('maxlength' => '255'))?>
</div>
Output it In the view.php
use \Application\Block\Form\MiniSurvey;
...
<?php echo $question['helptext']; ?>
Added the extra code to auto.js,
addQuestion:
postStr += '&helptext=' + encodeURIComponent($('#helptext' + mode).val());
...
reloadQuestion:
$('#helptextEdit').val(jsonObj.helptext);
...
resetQuestion:
$('#helptext').val('');
mini-survey.php,
$dataValues = array(
intval($values['qsID']),
trim($values['question']),
trim($values['helptext']),
$values['inputType'],
$values['options'],
intval($values['position']),
$width,
$height,
intval($values['required']),
$values['defaultDate'],
intval($values['msqID']),
);
$sql = 'UPDATE btFormQuestions SET questionSetId=?, question=?, helptext=?, inputType=?, options=?, position=?, width=?, height=?, required=?, defaultDate=? WHERE msqID=? AND bID=0';
} else {
if (!isset($values['position'])) {
$values['position'] = 1000;
}
if (!intval($values['msqID'])) {
$values['msqID'] = intval($this->db->fetchColumn("SELECT MAX(msqID) FROM btFormQuestions") + 1);
}
$dataValues = array(
$values['msqID'],
intval($values['qsID']),
trim($values['question']),
trim($values['helptext']),
$values['inputType'],
$values['options'],
intval($values['position']),
intval($values['width']),
intval($values['height']),
intval($values['required']),
$values['defaultDate'],
);
$sql = 'INSERT INTO btFormQuestions (msqID,questionSetId,question,helptext,inputType,options,position,width,height,required,defaultDate) VALUES (?,?,?,?,?,?,?,?,?,?,?)';
}
$result = $this->db->executeQuery($sql, $dataValues);
Cleared cache and updated the block.
Forum Post on Concrete5 with the changes
Solved: Got this working on a clean install of C5.
Small changes:
Added the original files form the concrete/blocks/form to the application folder (and changed the namespace)
db.xml (longtext was unnecessary)
<field name="helptext" type="text" size="65535"></field>
auto.js (Semicolon ; missing in the original concrete/block/form/auto.js (and thus the copy in application))
reloadQuestion:
$('#editQuestionForm').css('display', 'block');
Upvotes: 1
Views: 377