Forums

CF5: Set the value of a hidden field according to the value of a dropdown field

sanma 11 Dec, 2018
Good morning,
I would like to understand if and how to set the event of the dropdown to set a certain value of a hidden field.
Is there an example somewhere?
thanks
GreyHead 11 Dec, 2018
Hi sanma,

Please explain what you need in more detail as I am not clear.

You can set a default value for any input element by adding it to the form data in the form Load event before the HTML (render form) action.

Bob
sanma 11 Dec, 2018
shortly. I have to change the value of hidden1 based on the value of dropdown1

if dropdown1 = 0 hidden1 = 'hello'
if dropdown1 = 1 hidden1 = 'bye'
sanma 12 Dec, 2018
because the value of hidden1 will be passed to the tcpdf
healyhatman 12 Dec, 2018
.... Just use the value of the dropdown though, and do it in your TCPDF action?
Don't know how you get values in PHP in CFv5, but pseudocode should look like
if(data['dropdown1'] == 0)
echo 'hello';
else
echo 'bye';
sanma 12 Dec, 2018
Dropdown commands other events in the form and also an event switcher in which there are various tcpdfs. I can not pass it directly to the tcpdf
GreyHead 12 Dec, 2018
Hi sanma,

Could you just change the values in the drop-down to get the same result ?

Otherwise you can use a PHP action after the form submits to set the value.

Or, and most complicated, you could use JavaScript to set the value in the browser.

Bob
sanma 12 Dec, 2018
With php the problem is solvable but I have very little knowledge of php.
I would like the field to be enhanced without direct interaction from the user but automatically according to other fields of the form and then pass the value of that field to the tcpdf
GreyHead 13 Dec, 2018
Hi Could you just change the values in the drop-down to get the same result ?,

Could you just change the values in the drop-down to get the same result ?

Bob
sanma 13 Dec, 2018
No, because the value of dropdown1 should not be passed to tcpdf but must be passed hidden1.
For now I have solved with the following php code in a custom code of on submit

<?php
switch ($form->data['dropdown1']) {
case '1':
$form->data['hidden1'] = 'one';
break;
case '2':
$form->data['hidden1'] = 'two';
default:
$form->data['hidden2'] = 'zero';
break;
}?>

But I would like to get the same result without php maybe using chronoform events
healyhatman 13 Dec, 2018
But WHY can't you just use the dropdown I legitimately don't understand.
sanma 13 Dec, 2018
Because I send to the tcpdf 8 variables using no more than 2 dropdowns. The value of these variables is never equal to one of the dropdown choices. I have to automate to avoid errors of choice by users. I can with php but I would like to try with the chronoform events.
This topic is locked and no more replies can be posted.