Form - add help text to form question [Solved]
Permalinkhttp://documentation.concrete5.org/developers/working-with-blocks/c...
For some reason its not saving the value or getting the value into the edit form.
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):
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,
namespace Application\Block\Form; ... trim($values['helptext']), ... $sql = 'UPDATE btFormQuestions SET questionSetId=?, question=?, helptext=?, inputType=?, options=?, position=?, width=?, height=?, required=?, defaultDate=? WHERE msqID=? AND bID=0'; ... trim($values['helptext']), ... $sql = 'INSERT INTO btFormQuestions (msqID,questionSetId,question,helptext,inputType,options,position,width,height,required,defaultDate) VALUES (?,?,?,?,?,?,?,?,?,?,?)';
controller.php
namespace Application\Block\Form; ... public function duplicate: $v = array($newQuestionSetId,intval($row['msqID']), intval($newBID), $row['question'],$row['helptext'],$row['inputType'],$row['options'],$row['position'],$row['width'],$row['height'],$row['required'],$row['defaultDate']); ... $sql = "INSERT INTO {$this->btQuestionsTablename} (questionSetId,msqID,bID,question,helptext,inputType,options,position,width,height,required,defaultDate) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
When I save the question and want to edit it afterwards there's no value filled in. (That's before saving the form to the database.)
Array ( [qID] => 295 [msqID] => 18 [bID] => 139 [questionSetId] => 1480941675 [question] => --Question-- [inputType] => checkboxlist [options] => --Options-- [position] => 0 [width] => 0 [height] => 0 [defaultDate] => [required] => 1 [helptext] => [input] => --Content-- [type] => checkboxlist [labelFor] => for="Question18" )
I added the helptext manually to the database but no value comes out.
trim($values['helptext']),
at the right position in the array to match your query?
For the update query it should be third in the array and for the insert query it should be fourth in the array. Is it what you have?
$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 {
I'll keep looking in case I notice something weird
When I add it manually to the right version of the Question (Forget about that) in the database the value is shown on the frontend and add/edit form.
Maybe you should go back to your modifications and make sure it is exactly as you have it here.
For instance are you sure you didn't forget a ? in one of the sql queries?
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');
@mnakalay Tnx for testing and feedback.
Just a guess though