UPSERT condition

hello,

I use a UPSERT plugin ... which works very well for me, to modify a value of a table called "X"

It would be possible to add an “IF” in the “condition” section of the plugin… so that it modifies the value, only when a field in the “Y” table that I am editing is equal to the “cancel” value


I have reviewed several "upsert topics" of the forum and and I do not quite understand it ...


I hope I explained ...

Thanks in advance…


http://fabrikar.com/forums/index.php?wiki/php-form-plugin/

· Conditionally updating a form's value on Save(top)

Lets say we want to update the field 'sport's value to 'badminton' when the field name's value is 'rob'. To do this the php would be:

PHP:


$name = $formModel->formData['tablename___name'];

if ($name === 'rob')
{
$formModel->updateFormData('tablename___sport', 'badminton', true);
}
 
good again ...
I have tried testing with the php code ... and it doesn't quite work for me.
tomorrow I will continue investigating. I appreciate any suggestions or ideas ...
thank you and good night!
 

Attachments

  • upsert conditionphpfabrik.jpg
    upsert conditionphpfabrik.jpg
    72.4 KB · Views: 71
The condition in the upsert plugin - as in other plugins - determines if the plugin is run at all.
upload_2021-2-2_0-38-52.png
So
if ($name !== 'rob') return false;

The form php plugin is special, it doesn't have a condition, you have to do t in your code. But your title says UPSERT condition.
 
The condition in the upsert plugin - as in other plugins - determines if the plugin is run at all.
View attachment 19060
So
if ($name !== 'rob') return false;

The form php plugin is special, it doesn't have a condition, you have to do t in your code. But your title says UPSERT condition.

Good Morning…
The condition did not just work for me ... surely I am doing something wrong ... sorry!
I am going to detail the steps ... to see you detect the error on my part ...
I think I'm close to solving it ...
I understand that it works like this ...

If in the form that I am modifying ...
the value gpexpedient___gp_exp_actiu === ’actiu’ return false (so it does not perform modification…) is it like this…?

If the value gpexpedient___gp_exp_actiu of the table "X" that I am modifying! == ‘actiu’
Then YES it should do the upsert, changing the value of "immovable status" of table "Y" to "available"

Would this condition be correct ...? Or there is some syntax error that I cannot detect ...

$ name = $ formModel-> formData ['gpexpedient ___ gp_exp_actiu'];
if ($ name === 'actiu') return false;


I appreciate the attention and speed in which you answer my questions.!
 

Attachments

  • upsert conditionphpfabrik2.png
    upsert conditionphpfabrik2.png
    30 KB · Views: 71
Not sure if $formModel... will do, the tooltip says $data.

Check with var_dump(...);exit; or with the jDump plugin what you get.
 
good
I'm going to try the jdump plugin
https://github.com/mathiasverraes/jdump/downloads
Let's see if I can clarify ...
Thanks again

Very good

In the end I have leaned towards this instruction that you told me ...

echo "<pre>"; print_r ($ data); go out;

and I have verified that it correctly picks up the value ... this way.

$ value = $ data ['gpexpedient ___ gp_exp_actiu']; perfect !! ;)

Now $ value = actiu checked ...

But I have no way that the condition will do me right

if ($ value! == "actiu") returns false;

I have also tried with:
=
==
! =
! ==​

And I can't get the upsert to write the value "available" in the table "gphabitatge"
If I leave "NO" Evaluate the value as PHP the UPSERT works correctly.

I'm starting to get a little low in morale… since I don't quite understand… what a mistake I'm making.
Let's see if you can help me ... and I can continue testing the upsert condition ...

PS .: by the way ... the php version is 7.3 I understand that it is correct

Thanks again
 

Attachments

  • upsert conditionphpfabrik3.jpg
    upsert conditionphpfabrik3.jpg
    41.6 KB · Views: 77
Don't mix up the condition and the upsert settings.

Condition: only determins if the plugin is run at all. This has nothing to do with eval in the "Values" popup

If you set "eval"=Yes in the upsert "Values" popup the value must be php code, i.e. something like
if ('{some_element}' == 'foo') $myvalue = 'bar'; return $myvalue;
 
Don't mix up the condition and the upsert settings.

Condition: only determins if the plugin is run at all. This has nothing to do with eval in the "Values" popup

If you set "eval"=Yes in the upsert "Values" popup the value must be php code, i.e. something like
if ('{some_element}' == 'foo') $myvalue = 'bar'; return $myvalue;
Well, apparently I have mixed concepts ... my minimal notions are in sight ... I'm sorry ...
I'm going to explain myself again ...
I have a list / form called "exp" and an element called exp_actiu
Within this list / form, the exp_actiu element can have a “cancelat” or “actiu” value.

When editing / modifying the list / form "exp" ... I change the value of the exp_actiu element to a value "cancelat"
I want it to modify in the upsert an element from another table ...

That is ... and summarizing:
to execute the UPSERT as long as the value exp_actiu = ”cancelat”
I am aware of my limitations, with the code ... and I am somewhat thick with this doubt.
However ... I really appreciate the patience and attention you give me at the moment.
Thank you.
 
Ok. You say the update is working in principle. So you upsert settings seem to be correct.

If I got you right you'll need:

Eval=no in the popup (you don't want to evaluate the value, it's fix "disponible")

And you need the correct condition to PREVENT the upsert from running, so

$value = $data['gpexpedient ___ gp_exp_actiu']; //you said this is returning the expected value (= a string). But I would check with var_dump, this will show you the exact variable type etc.; make sure $value is not an array

if ($value !== 'cancelat') return false; //i.e. if ($value === 'cancelat') run the upsert
 
Ok. You say the update is working in principle. So you upsert settings seem to be correct.

If I got you right you'll need:

Eval=no in the popup (you don't want to evaluate the value, it's fix "disponible")

And you need the correct condition to PREVENT the upsert from running, so

$value = $data['gpexpedient ___ gp_exp_actiu']; //you said this is returning the expected value (= a string). But I would check with var_dump, this will show you the exact variable type etc.; make sure $value is not an array

if ($value !== 'cancelat') return false; //i.e. if ($value === 'cancelat') run the upsert

Good…
I've never tried var_dump… It's my first time… Thank you.
This is the result…
string (9) "MY_VAR:" string (5) "Actiu"
I observe that the database saves "actiu" (in lowercase)
and the value with the DUMPVAR ... I picked it up with a capital letter "Actiu"
which is the one I have as a description ...
thanks to VAR_DUMP ... I observe that the value I collect is the one shown on the screen (first letter in capital letters)
I was doing the comparison in lowercase ...
Wonderful, wonderful !!!…. Now you have managed to make the upsert work ...
I have learned ... several things thanks to your collaboration ...!
thanks for the patience ... and attention that you have given me !!
Thank you very much…;);););)
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top