Form - add help text to form question [Solved]

Permalink
C5.7.5.9 - Something like this but on the front-end part of the form:
http://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):
<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,
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 (?,?,?,?,?,?,?,?,?,?,?,?)";

c5dragon
 
mnakalay replied on at Permalink Reply
mnakalay
unless you updated, chances are your new field didn't get added to the database so nothing will save.

Just a guess though
c5dragon replied on at Permalink Reply
c5dragon
Did update the block. First thing I did when I added it to the db.xml. Database shows the column, with a NULL value.

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.)
c5dragon replied on at Permalink Reply
c5dragon
print_r($question);
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.
mnakalay replied on at Permalink Reply
mnakalay
in minisurvey.php are you sure you put your
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?
c5dragon replied on at Permalink Reply
c5dragon
Tried to match it with the way questions are added to the db/json. (With matching '?')

$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 {
mnakalay replied on at Permalink Reply
mnakalay
Yes that seems correct.

I'll keep looking in case I notice something weird
c5dragon replied on at Permalink Reply
c5dragon
Saving it to the db with add/edit form still not working. It resets to Null.

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.
mnakalay replied on at Permalink Reply
mnakalay
ok I finally got time to do what you did. I am on 5.7.5.9, I follow your steps exactly and it worked for me without a glitch.

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?
c5dragon replied on at Permalink Best Answer Reply
c5dragon
Don't have access to the 'real' project code and can't compare but I got this working on a clean install of C5. (03:34 AM local time)

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.