How to set field readonly by php condition

sportegioco

New Member
I have a form with the following fields:
surname
firstname
email
The name of table is user.
When I open the form, if email is verified i would like the email field readonly
I evaluate if email is verified through a php code, in particular a query to the database.
It is possible to set the email field to readonly if the email == verified
thanks for any reply
 
I would probably add another element to record the verification status, hidden at least in forms. Could be a yes/no element, or an integer field, or a calc (where you could do the verification as well), set it to e.g. 1 if verified, otherwise 0.
Then use JS with that new element and, if value = 1, add the readonly attribute to the email element.
 
Thanks very much, it works !!!

... I had tried this solution with a display field but it didn't work.
With a field of type field it works perfectly.
I would have preferred a solution without another fields in the table, even if it is a hidden type ...and a better a solution directly from the server.

I had also thought of a solution from the server through the redirect:
Create two forms that refer to the same table, then use a php redirect code like:

If the email == verified go to page X otherwise go to page Y

if ("$fieldX" === "verified")) {
header ("Location: https://www.mysite.com/index.php/it/formXX");
} else {
header ("Location: https://www.mysite.com/index.php/it/formYY");
}

... but I think there must be a more elegant solution directly from the server, but I haven't found it
 
Well, I was trying to think of a simple solution that's easy to be implemented and maintained: single form, single URL, for both adding and editing records, via that extra element which shouldn't cause any headaches.

Thinking along your lines, I can only imagine more complications... multiple forms/URLs, requiring more code/plugins, eventually also outside Fabrik, also depending on how the form(s) should be accessed, etc etc...
 
You're absolutely right, your solution is much better than the two-form solution

... but it is possible that there is no other solution ... for example by adding code directly in the form's php plugin
... a code like this that deactivates the field

echo "<script type = 'text / javascript'> document.form_56.users ___ email.setAttribute ('readOnly', 'readOnly'); document.form_56.users ___ email.addClass ('readonly'); </script>";

...I was not able to find It
 
I tried to put this code in "getTopContent" and "getBottomContent" of the form plugin
...but it does not work. Do you have any suggestions?:
return " <script type='text/javascript'> document.form_56.users___email.setAttribute('readOnly', 'readOnly'); document.form_56.users___email.addClass('readonly'); </script> " ;
 
With "getBottomContent", try this:
Code:
return '<script>document.getElementById("users___email").readOnly = true;</script>';
It works for me.

If it doesn't for you, please check if the <script> tag shows at all in the HTML: with the default bootstrap form template it should be right above <div class="fabrikActions...>, means the form buttons. If it doesn't show there, review your PHP form plugin settings. And if it doesn't work despite showing in the HTML, make sure the element's ID is correct.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top