I have been using Fabrik for more than a year, but this is the first time I am trying to make use of the feature to run PHP script at the end of the Form submission. I have searched the Forum for some examples to update the 'users table' field, but could not find similar example. May be someone can help me find the way...
I have a new field added to the joomla users table that keeps track of a 'credit unit' the user has. While submitting the Form I have a form field to amend this value. On submission of the form I want to amend the value in the 'jos_users.credit' field with the new value submitted in the form.
Assuming:
Field Name to update = jos_users.credit
Form Field name for credit unit adjustment = credit_adjust
I have done the following steps:
a) Display the name of the elements in $aData
<pre><?php print_r($this?_data); ?><pre>
b) The name of the elements i want to use are:
[form_id] => 4
[jos_users___id] => 66
[jos_transactions___credits] => 10 ... Field name = 'Credit Adjustment'
jos_transactions is a new Fabrik table I have created to keep track of transactions of the users
and the credit value to be adjusted as credit/debit.
For credit I will use the value as -10 and debit will be just 10
On Form submission, I want to sum up (add with the sign) the existing value in jos_users.credit field
with the value entered in the Form 'jos_transactions_credits' and update the value in the jos_users.credit
field.
For example, if the existing value in jos_users.credit field = 100
If I enter in the Form Field 'Credit Adjustment' = 30
After the form is submitted, the value in jos_user.credit field = 70 ...(100-30)
If I enter in the Form Field 'Credit Adjustment' = -30
After the form is submitted, the value in jos_user.credit field = 130 ...(100-(-30))
c) sample code:
Selected the option form dropdown = As soon as form submitted (simple eval)
Following examples I found in several postings, I created the following code to be entered into the
'PHP code to execute on Form submission':
$credit = mosGetParam($_POST, 'jos_transactions___credits');
$uid = mosGetParam($_POST, 'jos_users___id');
"UPDATE jos_users SET credit = credit - $credit WHERE id=$uid";
On submission of the form, i do not see any errors, but the jos_user.credit field is NOT getting updated!
I guess I am making some mistakes in my code.
Would appreciate some advise on this..
Festus
P.S. I have installed Fabrik_v1.0.4 SVN_520
I have a new field added to the joomla users table that keeps track of a 'credit unit' the user has. While submitting the Form I have a form field to amend this value. On submission of the form I want to amend the value in the 'jos_users.credit' field with the new value submitted in the form.
Assuming:
Field Name to update = jos_users.credit
Form Field name for credit unit adjustment = credit_adjust
I have done the following steps:
a) Display the name of the elements in $aData
<pre><?php print_r($this?_data); ?><pre>
b) The name of the elements i want to use are:
[form_id] => 4
[jos_users___id] => 66
[jos_transactions___credits] => 10 ... Field name = 'Credit Adjustment'
jos_transactions is a new Fabrik table I have created to keep track of transactions of the users
and the credit value to be adjusted as credit/debit.
For credit I will use the value as -10 and debit will be just 10
On Form submission, I want to sum up (add with the sign) the existing value in jos_users.credit field
with the value entered in the Form 'jos_transactions_credits' and update the value in the jos_users.credit
field.
For example, if the existing value in jos_users.credit field = 100
If I enter in the Form Field 'Credit Adjustment' = 30
After the form is submitted, the value in jos_user.credit field = 70 ...(100-30)
If I enter in the Form Field 'Credit Adjustment' = -30
After the form is submitted, the value in jos_user.credit field = 130 ...(100-(-30))
c) sample code:
Selected the option form dropdown = As soon as form submitted (simple eval)
Following examples I found in several postings, I created the following code to be entered into the
'PHP code to execute on Form submission':
$credit = mosGetParam($_POST, 'jos_transactions___credits');
$uid = mosGetParam($_POST, 'jos_users___id');
"UPDATE jos_users SET credit = credit - $credit WHERE id=$uid";
On submission of the form, i do not see any errors, but the jos_user.credit field is NOT getting updated!
I guess I am making some mistakes in my code.
Would appreciate some advise on this..
Festus
P.S. I have installed Fabrik_v1.0.4 SVN_520