How to call a function that receive parameters and return result

joezart

New Member
I have a very long call function that it's not practical to place in a php box (plugin) as I need to call it from different forms.

What I need to do is to "call it" from the php box plugin

QUESTIONS:
1. Where to store it
2. How to call it
3. How to send it parameters
 
you don't say which plugin but most of the php ones allow you to define a script which is called instead of the inline php. The form php plugin wiki page tells you where to place the script depending on your version.

http://fabrikar.com/wiki/index.php/Form_plugin_php

I'm presuming this is for a form plugin.
As you need to call it from several places I'd make a file in
plugins/fabrik_element/form/scripts/library.php

with code:
Code:
function doMyThing() {
  .....
  return true;
}

then another script for each form 'form1.php':

Code:
require_once('library.php');
return doMyThing();

I've not tested that so you may need to specify the full path to library.php in the require_once statement
 
Sorry Rob

Im using joomla 2.5
and fabrik 3.0.6.3

I was talking about the FORM PLUGIN PHP
specifically PHP CODE

Like I said I do not know how to

1. Where to store it
2. How to call it
3. How to send it parameters

I think the first question it's anwered
 
He actually (kinda) answered all three.

However, I've just made a slight tweak to the PHP form plugin that will make this easier. So, grab the latest github, and ...

Put your functions in a file, and store them in the PHP plugin scripts dir which is at ./plugins/fabrik_form/php/scripts. (NOT the path Rob gave you).

Select that file in the PHP plugin's PHP File.

Call the function from the PHP Code box, passing in any args you need.

Simple example I tested with:

File is called my_funcs.php, which is:

PHP:
<?php
function saySomething($msg, $formModel) {
	$example_element_value = $formModel->getElementData('fab_calc_test___calc_test_2', false, 'default value');
	$app = JFactory::getApplication();
	$app->enqueueMessage($msg . ": " . $example_element_value);
	return true;
}
?>

Then in the PHP Code box, I have:

PHP:
saySomething("Value is", $formModel);

Net result is, after submitting the form, J! shows a standard status message at the top of the page, saying:

Value is: cheesegrits

Note that I pass in $formModel, which is usually the main Fabrik "thing" you'll be wanting to operate on, and is in scope when we eval your code .. but not within any functions in your file, unless you 'global' it, which is a frowned upon these days, so you'll need to pass it in as an arg. And as per the tooltips, you'd then be able to use $formModel->updateFormData() to modify form data.

Final note, you could do this without updating form github, by just not selecting a PHP File, and doing (more or less) what Rob said to do:

PHP:
require_once JPATH_ROOT . '/plugins/fabrik_form/php/scripts/my_funcs.php';
saySomething("Value is", $formModel);

The only difference with the tweak I just did in github is to make it easier to include that file, i.e. we do the require_once for you.

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

Thank you.

Members online

Back
Top