Empty databasejoin message field

winetrade

New Member
Hi,
on a project i have a form with a field that is a databasejoin.
The form get the client code from a furniture table and put in the field the client code.

I have a problem on submit because if i have the code (the databasejoin return a number) all works well.
But if the client is not in the furniture i get an sql error when submit.

I'd like to know if i can do one of this two things:

1) If the databasejoin is empty use somenting like "not already a client" option
2) Prevent the form appearing if you are not a client: YOU ARE A CLIENT -> form | YOU ARE NOT -> a message

Thanks you
 
I don't understand what you mean by "The form get the client code from a furniture table and put in the field the client code."
How is this done?

If I'm guessing this correctly, it sounds like all you need to do is set a default value of zero for the databasejoin element.
In the 'Default' tab of the databasejoin element configuration enter 0.
In the 'Please select' tab of the databasejoin element configuration...
Show please select: Yes
Value of 'Please select' option: 0
Label of 'Please select' option: Not a client

Another option (or depending on how that 'client code' gets added) would be to create a new Joomla usergroup and access level named 'Client' - and when the user first gets a client code, include some php to add them to the 'Client' usergroup also. Then any elements or menu items in your project that you want to restrict to only 'Client' users could all be controlled by the ACL 'Access' level for those elements or menu items.
 
Hi, yes you understand right, sorry for my bad english, i'll try with the default value for the join dropdow. is the fastest, if dosen't work i'll try the other.
Thank you
 
I check de problem and now i understand what happens. When i submit the form the databasejoin works and works with the solution you give me.
The problem is the UPSET plugin. When i submit i need also to update another table with the clientcode that in the query is empty in this case.

So i need a solution to use for example "0" for that field if the query in the upset is empty.
Thank you
 
Plugins have a (enable) 'On' condition (New and/or Edit). And the Upsert plugin has a box for entering php code for the 'Condition' you need met.
 
Hi,
i've done a test.
I try to explain:
in the drop down field with the database join i added a default field with "0".
In this field (drop down database join) the system extract a query trying to match user client code with another table.
If he find it then add values on the drop down else in the drop down i have only "0" checked.

Then i add a custom code in the UPSERT conditions like this:

$variable_check = $formModel->formData['database-join-field-name'];
if ($variable_check > 0) {
return true;
}
else
{
return false;
}

I Expect that if the dropdown is empty (only the default value checked) the system do not execute the UPSERT, in other case users will select their code and the system will execute the upsert.
The code dosen't work, what i'm doing wrong ?
Thanks
 
Replace 'database-join-field-name' with the actual full name of the database join element. Also try converting the result to an integer for comparing against zero.
e.g.
PHP:
$variable_check = (int) $formModel->formData['tablename___dbj_elementname'];
return ($variable_check > 0);
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top