Php form plugin

peterpetrov

New Member
Hello,

This is my scenario:

table1___access_level - drop-down with 3 entries
1, access1
2, access2
3, access3

table1___another - field where it has to be populated on form submission.

i am using php form plugin for that with onBeforeStore. The code is as follows:

--------------
$access - $formModel->getElementData('table1___access_level', true);

if ($access === '1'){
$formModel->updateFormData('table1___another', '5', true);
}

elseif ($access === '2'){
$formModel->updateFormData('table1___another', '9', true);
}
elseif ($access === '3'){
$formModel->updateFormData('table1___another', '11', true);
}
---------------

I am unable to make any of the 'if's to happen even if it is just single one.
 
The first line of your code is
Code:
$access - $formModel->getElementData('table1___access_level', true);

Perhaps it should have an = instead of -

Code:
$access = $formModel->getElementData('table1___access_level', true)[0];
 
Hello mamies, it is equals, not a dash. I wasn't copying it but rather wrote it here. I haven't got that '[0]' part and not sure if it should be at the end in order to work.
 
Being a drop down the output with the [0] will display a more information then just the value that will be entered into the database
Array
(
[0] => 2
)

To only output the number from the Array you will need to specify which one you want. In the case of a single entry drop down [0] is it.
To test enter the below just after the $access variable to see what value is returned
Code:
echo "<pre>";print_r($access);exit;
 
Hey Matt,

that all make sense. However i would like to have that $access var to be stored in similar way as the cascade dropdown. I will think about using cascade instead of that method.
 
Use a calc element to store the 'other' value - and tell the calc element to use Ajax and watch for any changes to the 'access_level' drop-down selection. Then in the calculation code, work with the {table1___access_level_raw} placeholder value to write the code needed so that the 'other' value is formatted however you need it to be. No php form plugin is really needed.

The reason your if statements aren't working is because you are not comparing the raw values - you are comparing the label to the actual value.
e.g. (using placeholders instead) If the first option was selected...
'{table1___access_level}' would return 'access1'
while
'{table1___access_level_raw}' would return '1'
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top