• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Placeholder in element value with javascript

paveo

New Member
Hi,
I have a radiobutton which set the value of a 2nd element depending on the radiobutton value. It works fine but I'm trying to add a placeholder of a 3rd element in the 2nd element value with javascript code but it doesn't work.
My code is :

if(this.getValue() == 'value_of_radiobutton'){
$('table_name___2nd_element_name').value = "message :{table_name___3rd_element_name}"
}
Can you help me?
Thanks
 
Placeholders aren't available in Javascript.

The best approach is to use the main element object structure for the form. Replace X in form_X with your numeric form ID in this:

Code:
if(this.getValue() == 'value_of_radiobutton'){
   var form = Fabrik.getBlock('form_X');
   var el2 = form.formElements.get('table_name___2nd_element_name');
   var el3 = form.formElements.get('table_name___3rd_element_name');
   el2.update("message : " + el3.getValue());
}

-- hugh
 
Thanks Hugh,

It works great. Now I want to add the element id after el3 but it doesn't show. Why?

Code:
if(this.getValue() == 'value_of_radiobutton'){
  var form = Fabrik.getBlock('form_X');
  var el2 = form.formElements.get('table_name___2nd_element_name');
  var el3 = form.formElements.get('table_name___3rd_element_name');
  var el4 = form.formElements.get('table_name___element_id');
  el2.update("message : " + el3.getValue() + el4.getValue());
}
 
What do you mean by "the element id"? You mean the 'id' element for the row, i.e. the primary key value for the table?

Is this a new form, or editing an existing one?

If it's a new form, 'id' won't have a value yet, as the 'id' isn't assigned until the form is submitted.

And if you do literally mean the 'id', then it would probably be called table_name___id, not table_name___element_id?

-- hugh
 
Yes it's table_name___id, sorry.
I want to show the message in the notification e-mail. So, as the table_name___id won't have value until the form is submitted, can I write php code in my php email template which will get and display these element values?
 
Yes.

When running a PHP template, all the form's data is in $emailData, keyed by full element name.

Easiest thing to do is start by doing this:

Code:
var_dump($emailData);exit;

... and run a form submission. This should dump out the $emailData structure and content. Keep that tab, open another one, and work in that, remove the var_dump(), and code your template, referring to the dump of $emailData for what you need. Which might be ...

Code:
if ($emailData['tablename___radiobutton'] == 'yes') {
   echo "message: " . $emailData['tablename___el1']  . $emailData['tablename___el2'] .  $emailData['tablename___id'] . "<br />\n";
}

... or whatever.

-- hugh
 
It's exactly what I needed. Thanks a lot.
I've just added [0] after ['tablename___radiobutton_raw'] because var_dump($emailData);exit; returned ["tablename___radiobutton_raw"]=> array(1) { [0]=> string(3) "yes" }
so my code is :
Code:
if ($emailData['tablename___radiobutton'] [0] == 'yes') {
  echo "message: " . $emailData['tablename___el1']  . $emailData['tablename___el2'] .  $emailData['tablename___id'] . "<br />\n";
}
 
Looks right. Glad it worked for you.

There are better ways to code that sort of thing, using more "defensive" coding, using either PHP functions or J! helper functions to make sure array keys exist, etc. and avoid tossing PHP warnings if the expected data isn't there ... but that'll work as-is.

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

Thank you.

Members online

Back
Top