Forums

enable field based on value in database

smurf007 24 Mar, 2014
Hi,

Is it possible to create a form like:

1) Field1 - Load state: Parent hidden

2) Script (or something else) which check the follwoing sql-query

IF
SELECT Column1 FROM Table1 WHERE Column2 = 'value' = 1
Then 'Show parent' Field1
Else
End

This makes my form much more 'dynamic', because I can create a control panel to enable/disable fields without creating many forms.

Should be possible, but I need some help🙂
GreyHead 24 Mar, 2014
Hi smurf007,

I don't know if it will work in CFv5 but in CFv4 I have used Custom containers to do this. You can add code in the Custom Start and end code boxes so that the container contents are either shown or hidden depending on some PHP. Here's a simple example. Start:
<?php
$display = 'none';
if ( $form->data['some_input'] == 'some_value' ) {
  $display = 'block';
}
echo "<div style='display:{$display};' >";
?>

End:
</div>

Bob
smurf007 24 Mar, 2014
Hi,

Thanks for your answer. I got this error:

Parse error: syntax error, unexpected ';' in /public/sites/...(125) : eval()'d code on line 3

Any suggestions?
GreyHead 25 Mar, 2014
HI smurf007,

Sorry, typo in my code, fixed now I hope.

Bob
This topic is locked and no more replies can be posted.