• Resolved saralovesyellow

    (@saralovesyellow)


    Hi there.

    First, great plugin! Thanks for all of your hard work!

    Next, I am having a bit of difficulty saving a calculated field to the wp_usermeta table of my database. I’ll try to keep my explanation basic and clear.

    Calculated field: this is calculating and displaying correctly on the front end. It is a combo of a sub string of two fields (first three letters of last name, last 4 digits of phone) as well as the purchase date (date field on form). Ex: 07242017abc1234

    However when I try to assign this value as user meta I am only getting the date portion, ex: ‘07242017’

    Upon further investigation I found that if I used another calculate field to try to display the value from the first calculated field that second field would only display the date portion as well.

    I have tried every possible thing I can think of, hoping someone here can shed some light on what I am doing wrong and how I can properly save the full value of the calculate field to the database.

    Thanks in advance for your help!
    Sara

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @saralovesyellow,

    The plugin always tries to get the digits in the fields’ values for using they in the mathematical equations (the main objective of the calculated fields), however, if you want to use the field’s value without processing, please, follow the instructions below:

    I’ll try to explain the process with an example.

    Assuming the field to use is the fiedname1, and your equation will be concatenate the text ‘suffix’ at the end of the fieldname1’s value. The equation in this case would be:

    (function(){
    var tmp = fieldname1;
    return jQuery('[id*="fieldname'+'1_"]').val()+'suffix';
    })()

    Pay attention, the “tmp” variable was defined, and receive the fieldname1 (var tmp = fieldname1;), however, it is not used in the rest of the equation, because the field’s value is obtained directly with jQuery. The line of code:

    var tmp = fieldname1;

    indicates to the plugin that the equation depends of the fieldname1 field, and if its value varies, the equation should be reevaluated.

    Best regards.

    Thread Starter saralovesyellow

    (@saralovesyellow)

    Hello, thank you so much for your quick reply! Unfortunately this fix is not working when it comes to saving the value in the database. I am still only getting the same results in the database as previously (I am able to display a calculated field value in another calculated field using this method but that was never my intent – only something is discovered in troubleshooting the issue regarding saving the full variable to the database).

    Is there something special I need to do with the variable in the query in order to save the full value?

    Thank you again for your help,
    Sara

    Plugin Author codepeople

    (@codepeople)

    Hello Sara,

    If you are talking about the database of the plugin, all submitted data are stored in the plugin’s table, without any modification, just like it was submitted, but if you are storing the submitted data into your own database (a database that is not part of the plugin) it will depend of the structure of the column in your database.

    Best regards.

    Thread Starter saralovesyellow

    (@saralovesyellow)

    I am trying to save the value to the wp_usermeta table in the wordpress database using the Form Controls with Datasource connection and a custom query. Only the first portion of the value saves in the database (the date portion as described in original post).

    Plugin Author codepeople

    (@codepeople)

    Hello Sara,

    The datasource controls were thought for reading the data from the database and filling the fields in the form and not for storing the data in the database.

    For storing the data collected by the form into a different table or database, you should edit the “cp_calculatedfieldsf_insert_in_database.php” file to define the database connection’s data, and the insertion queries.

    More information in the following link:

    https://cff.dwbooster.com/documentation#third-party-database

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Calculate Field Not Saving Correctly to DB’ is closed to new replies.