from element value to element label

enzo2016

Member
Hi,

is possible to change the content of a field to a label of an element?
E.g.: a field element is filled with the word "colour". Could the word "colour" become label of an element?

Thanks

Enzo
 
I answered a similar question yesterday ...

http://fabrikar.com/forums/index.ph...lement-and-input-type-text.45683/#post-235638

... which uses a form PHP plugin running onLoad. If you look at the code in that thread ...

Code:
$formModel->groups[28]->elements[157]->element->label = "MODIFIED LABEL";
$formModel->data['date_test___name'] = "modified value";
$formModel->data['date_test___name_raw'] = "modified value";

... I think you could change it to ...

Code:
$formModel->groups[28]->elements[157]->element->label = $formModel->data['date_test___name_raw'];

Modify the group ID, element ID and element name accordingly.

-- hugh
 
Thank you very much Hugh.
I replaced the code in the following way (where the origin form is the form including the element with the value filled by the user; the destination form is the form including the element whith the changing label):

$formModel->groups[id group numer of origin form]->elements[id element number of origin form]->element->label = $formModel->data['destinationtablename___destionationelementname'];


Are my changes correct?
The settings I have used (group ID, element ID and placeholder) could be wrong because I got an error. In destination form after loading it, the following message appears:

Notice: Undefined index: nuova_zona_geografica___firstquestion in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\prova 3.6.2\plugins\fabrik_form\php\php.php(453) : eval()'d code on line 1
Warning: Creating default object from empty value in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\prova 3.6.2\plugins\fabrik_form\php\php.php(453) : eval()'d code on line 1
Fatal error: Call to undefined method stdClass::getParams() in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\prova 3.6.2\components\com_fabrik\models\form.php on line 3760
 
The example I gave was assuming you meant using the value to see the label of the same element. You seem to be trying to use a value from a different table / form entirely?

Sent from my HTC 10 using Tapatalk
 
Yes, the element where the value is added is in a different table from the element where the label is displayed.
For example, the placeholder of the element where the value is added is "table_a__value_to_copy_in_label" and the placeholder of the element where the label is displayed is: "table_b___label_pasted_from_the_value". Table b is a related data of table a.

Thanks

Enzo
 
Hi,
how could I do if using a value from a different table entirely (an example is on my site for tables: questions and comments)?

Please...

Enzo
 
You'd need to look up the value you need from the other table.

Table b is a related data of table a.

How are the tables related? So which table has the foreign key pointing to the related row in the other table?

The more details you give me, with actual table and element names, the more I can help you.

-- hugh
 
I am sorry because I couldn't replicate exactly the tables relations on my server, but please immagine the following situation. There are two tables: country (id, country_name, question_value) and region (id, region_name, country_id, question_label). The content written in question_value by the user should become label of the element question_label. So for example if the user is adding France as country and wine as question_value, then the user adding France regions will see the field with label: wine.

Thanks

-- Enzo
 
So when you are adding a new "region' form, is the country_id preset when the form loads?

Assuming that is the case ...

Code:
$countryId = $formModel->data['region___country_id_raw'];
$myDb = FabrikWorker::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select('question_value')->from('country')->where('id = ' . $myDb->quote($countryId));
$myDb->setQuery($myQuery);
$questionValue = $myDb->loadResult();
$formModel->groups[28]->elements[157]->element->label = $questionValue;

-- hugh
 
I used that code into the php plugin of 'region' form (onBeforeLoad), but it returned the following error:

Warning: Creating default object from empty value in /web/htdocs/www.mywebsite.net/home/plugins/fabrik_form/php/php.php(453) : eval()'d code on line 7

Fatal error: Call to undefined method stdClass::getPublishedElements() in /web/htdocs/www.mywesite.net/home/components/com_fabrik/models/pluginmanager.php on line 597



I replaced the last code row
Code:
$formModel->groups[28]->elements[157]->element->label = $questionValue;
,
in the following way:
Groups [countrygroup idnumber] elements[question_value idnumber]



Thanks,
Enzo
 
You were using the wrong group and element ids in that last line. You were using the numbers for the country, where the question is coming from. But then needed to be the numbers of the region group / element that you are setting the label value for.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top