Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
USing PHP to refer to Form fields in BS AS BB BE fields
USing PHP to refer to Form fields in BS AS BB BE fields
How do I reference field names on a PHP form using the form properties PHP code blocks for AS BS BB BE?
If I have a php based form that I created on a website and I submit that form to my PHP processor, I would grab the form data by this: $_GET['FldName']; OR =$_POST['FldName']; where FldName is the name of the field on the form. OR another way when pulling record field data from a query would be myrow["FldName"] or simply by a variable name $FldName.
For example in the BS (Before Save) code block, I want modify the data in a field, IE: the phone number field to remove the "-"s from that field as it appears on the form before I save it to the table. If the Fieldname on the form was Phone1 how would I refer to that field in the PHP code in this DB system on the BS code block? In reverse of this, I assume I'd use the BB or BE code blocks to put the field masks back on the data to display them on the forms, right?
Something Else I want to do is encrypt a field name, ie: an SSN field, BEFORE saving it to the database. I found an OLD post where Kev1n provided some code to use an encrypt_data table and do this, but the details of how to actually encrypt the field and use that table were not included and no-one has responded to that post yet. Any ideas on how to use that code in the BS code block would be helpful too. I have my own PHP code that I use outside of nuBuilder, but not sure how to "include" that code in nuB.
If I have a php based form that I created on a website and I submit that form to my PHP processor, I would grab the form data by this: $_GET['FldName']; OR =$_POST['FldName']; where FldName is the name of the field on the form. OR another way when pulling record field data from a query would be myrow["FldName"] or simply by a variable name $FldName.
For example in the BS (Before Save) code block, I want modify the data in a field, IE: the phone number field to remove the "-"s from that field as it appears on the form before I save it to the table. If the Fieldname on the form was Phone1 how would I refer to that field in the PHP code in this DB system on the BS code block? In reverse of this, I assume I'd use the BB or BE code blocks to put the field masks back on the data to display them on the forms, right?
Something Else I want to do is encrypt a field name, ie: an SSN field, BEFORE saving it to the database. I found an OLD post where Kev1n provided some code to use an encrypt_data table and do this, but the details of how to actually encrypt the field and use that table were not included and no-one has responded to that post yet. Any ideas on how to use that code in the BS code block would be helpful too. I have my own PHP code that I use outside of nuBuilder, but not sure how to "include" that code in nuB.
-
- nuBuilder Team
- Posts: 4210
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 67 times
- Been thanked: 414 times
- Contact:
Re: USing PHP to refer to Form fields in BS AS BB BE fields
Hash Cookies: https://wiki.nubuilder.cloud/ ... sh_Cookiesicoso wrote:How do I reference field names on a PHP form using the form properties PHP code blocks for AS BS BB BE?
Re: USing PHP to refer to Form fields in BS AS BB BE fields
Thanks for the guidance. I see that it says:
"There are 5 Hash Cookies always available.
USER_ID
USER_GROUP_ID
HOME_ID
GLOBAL_ACCESS
ACCESS_LEVEL_CODE
To find what other Hash Cookies are available for use, you can run nuHash() inside your code. "
Im assuming that these other "hash cookies" would be references to the field variables on the forms, right? Is that where I find the variable names of the fields on the forms? Because Im assuming (because it seems logically intuitive) that in the BS code block is where I would put some PHP code to strip the masking from the fields that I previously masked so that Im not saving an SSN like: 123-44-5555 in the database. OR I would run some type of encryption routine to encrypt the SSN before I save it in the database, right?
I put nuHash(); by itself in my BS Php code block, saved it, went out, back in opened my form, changed some data and clicked SAVE. And nothing happened...
What does putting nuhash(); in my PHP block supposed to do? Is it supposed to pop something up, print something, display something? Does it display all the object variables available? It says in the wiki "inside your code." so I assume that means in the BS or AS or BB or BE code blocks, right? or is there some place else Im supposed to run nuhash(); to find out what the VARIABLE names are on the forms so I can run some PHP code against them Before Saving? Or am I just not following the manual properly?
Question: Where or How do I find the variables names that are associated to the fields on a form so that I can references them in some PHP code in the AS BS BB BE code blocks? IS there some secret formula to accessing those fields data at those times? Can you provide some type of example that allows me to follow so that I can find this information?
"There are 5 Hash Cookies always available.
USER_ID
USER_GROUP_ID
HOME_ID
GLOBAL_ACCESS
ACCESS_LEVEL_CODE
To find what other Hash Cookies are available for use, you can run nuHash() inside your code. "
Im assuming that these other "hash cookies" would be references to the field variables on the forms, right? Is that where I find the variable names of the fields on the forms? Because Im assuming (because it seems logically intuitive) that in the BS code block is where I would put some PHP code to strip the masking from the fields that I previously masked so that Im not saving an SSN like: 123-44-5555 in the database. OR I would run some type of encryption routine to encrypt the SSN before I save it in the database, right?
I put nuHash(); by itself in my BS Php code block, saved it, went out, back in opened my form, changed some data and clicked SAVE. And nothing happened...
What does putting nuhash(); in my PHP block supposed to do? Is it supposed to pop something up, print something, display something? Does it display all the object variables available? It says in the wiki "inside your code." so I assume that means in the BS or AS or BB or BE code blocks, right? or is there some place else Im supposed to run nuhash(); to find out what the VARIABLE names are on the forms so I can run some PHP code against them Before Saving? Or am I just not following the manual properly?
Question: Where or How do I find the variables names that are associated to the fields on a form so that I can references them in some PHP code in the AS BS BB BE code blocks? IS there some secret formula to accessing those fields data at those times? Can you provide some type of example that allows me to follow so that I can find this information?
-
- nuBuilder Team
- Posts: 4210
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 67 times
- Been thanked: 414 times
- Contact:
Re: USing PHP to refer to Form fields in BS AS BB BE fields
nuHash() returns list of Hash Cookies. https://wiki.nubuilder.cloud/ ... PHP#nuHashI put nuHash(); by itself in my BS Php code block, saved it, went out, back in opened my form, changed some data and clicked SAVE. And nothing happened...
YesIm assuming that these other "hash cookies" would be references to the field variables on the forms, right? Is that where I find the variable names of the fields on the forms
You need to use the AS event to modify data in the db. Unfortunately, it's not possible in BS.I would put some PHP code to strip the masking from the fields that I previously masked so that Im not saving an SSN like: 123-44-5555 in the database. OR I would run some type of encryption routine to encrypt the SSN before I save it in the database, right?
You do not have the required permissions to view the files attached to this post.
Re: USing PHP to refer to Form fields in BS AS BB BE fields
Im talking about changing the fields BEFORE saving it. So wouldn't I use the BS codeblock? In this case I want the SSN field that is showing on the form with the dashes (IE: 111-22-3333) Assign it to a variable, then dosomefunction() on that variable , then save it back in the field array itself BEFORE that data is saved to the database. In my PHP code How exactly do I reference the field data directly? Would I do something like this:
$frmData = nuHash();
$ssn=$frmData['cus_ssn'];
$ssn=(dosomefunction($ssn));
$frmData['cus_ssn'] = $ssn;
What's the proper way of accessing that field data directly in my PHP code?
$frmData = nuHash();
$ssn=$frmData['cus_ssn'];
$ssn=(dosomefunction($ssn));
$frmData['cus_ssn'] = $ssn;
What's the proper way of accessing that field data directly in my PHP code?
-
- nuBuilder Team
- Posts: 4210
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 67 times
- Been thanked: 414 times
- Contact:
Re: USing PHP to refer to Form fields in BS AS BB BE fields
No, currenly you cannot modify the fields in BS, before saving a form.
I would like that possibility too and will see if I can make that possible somehow.
You can access the fields as you have shown or reference them like
I would like that possibility too and will see if I can make that possible somehow.
You can access the fields as you have shown or reference them like
Code: Select all
$ssn ="#cus_ssn#";
Re: USing PHP to refer to Form fields in BS AS BB BE fields
When the save button is clicked, what's the purpose of the PHP code in BS then? Typically, with a PHP form that is submitted to be saved to the database, all the fields of that form would be accessible via some $_POST['fldName'] array in the PHP code that's called in the form submit. I can then assign a variable that field data, and then use that variable instead of the $_POST['fldName'] in my SQL to insert or update the database.
At some point in your save or update you have to be executing an SQL statement to save or insert that data right?
Does it currently use the Forms posted array $_POST[] for all fields when running the SQL to insert or update? Can it use those hash variables instead? Both the end user (developer-me) have access to change those and your system should have access to them too.
Or if I can't change the value of the hash variables (allowing so could be dangerous). Then create some phpfunction that would, ie: nuUpdateHash(MyVariable, #HashVariable#);
Or how exactly are the fields data saved to the database?
At some point in your save or update you have to be executing an SQL statement to save or insert that data right?
Does it currently use the Forms posted array $_POST[] for all fields when running the SQL to insert or update? Can it use those hash variables instead? Both the end user (developer-me) have access to change those and your system should have access to them too.
Or if I can't change the value of the hash variables (allowing so could be dangerous). Then create some phpfunction that would, ie: nuUpdateHash(MyVariable, #HashVariable#);
Or how exactly are the fields data saved to the database?
-
- nuBuilder Team
- Posts: 4210
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 67 times
- Been thanked: 414 times
- Contact:
Re: USing PHP to refer to Form fields in BS AS BB BE fields
The purpose of BS is to validate date with the possibility to abort saving.
nuUpdateDatabase() saves/updates data in nudata.php.
The object $nudata contains all the form data. If we modified that (somehow), the altered data would be saved in the database
nuUpdateDatabase() saves/updates data in nudata.php.
The object $nudata contains all the form data. If we modified that (somehow), the altered data would be saved in the database
-
- nuBuilder Team
- Posts: 4210
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 67 times
- Been thanked: 414 times
- Contact:
Re: USing PHP to refer to Form fields in BS AS BB BE fields
I'm testing a way to change data before saving (it already works but it's experimental)
-
- nuBuilder Team
- Posts: 4210
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 67 times
- Been thanked: 414 times
- Contact:
Re: USing PHP to refer to Form fields in BS AS BB BE fields
The updated files in attachment allow you to modify an object's value in BS:
Example:
Please let me know if it works for you,
Example:
Code: Select all
$nuMainTable = nuHash()['nuFORMdata'][0]->table;
// Get the value of the object "not_title"
$title = nuGetNuDataValue($nudata, $nuMainTable, 'not_title');
// Replace the value of the object "not_title" by adding a -test postfix:
nuSetNuDataValue($nudata, $nuMainTable, 'not_title', $title . "-test");