• Resolved badmax69

    (@badmax69)


    My problem of understanding is this:

    I have several articles with article numbers. If I create a checklist for this, I can only enter a text and the value, but no further information.

    My idea: I create several fields with the article data. I enter the field name in the checklist. When I click on this, the field passes the article information. Is this possible?

    • This topic was modified 6 years, 1 month ago by badmax69.
Viewing 15 replies - 16 through 30 (of 32 total)
  • Thread Starter badmax69

    (@badmax69)

    I’ve found a solution for myself. I could only use the fieldnames with two digits.

    Can you briefly explain the possibility of Recordset DS to me? This is to retrieve all data from the database and make it available in the form. Then every single field accesses this data, right? What is the exact query like?

    SELECT * FROM {wpdb.prefix}cp_calculated_fields_form_posts WHERE formid=10 order by time DESC limit = 1 does not work.

    • This reply was modified 5 years, 12 months ago by badmax69.
    Plugin Author codepeople

    (@codepeople)

    Hello @badmax69,

    The query is correct, but remember the fields are stored in the database as a serialized object, so, after read the data from the database it is required unserialize the information stored in the column paypal_post

    Best regards.

    Thread Starter badmax69

    (@badmax69)

    OK with the Code SELECT paypal_post FROM wp_cp_calculated_fields_form_posts where formid=11 ORDER by id DESC limit 1
    I get the following information from the database:
    Array
    (
    [0] => Array
    (
    [paypal_post] => a:49:{s:6:”formid”;s:2:”11″;s:11:”fieldname16″;s:31:”Safety”;s:11:”fieldname17″;s:18:”Schutzzaun”;s:11:”fieldname18″;s:5:”32704″;s:11:”fieldname19″;s:4:”4056″;s:11:”fieldname20″;s:128:”Safety cell” and so on.

    How can I now access this data with recordset?

    • This reply was modified 5 years, 12 months ago by badmax69.
    Plugin Author codepeople

    (@codepeople)

    Hello @badmax69,

    In the current version of the plugin if you want read the fields values with a recordset field you should extract every field from the serialized object by separated, for example:

    
    SELECT 
    SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',2),':',-1) AS formid,
    SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',4),':',-1) AS field16,
    SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',6),':',-1) AS field17,
    SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',8),':',-1) AS field18,
    SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',10),':',-1) AS field19,
    SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',12),':',-1) AS field20
    FROM <code>{wpdb.prefix}cp_calculated_fields_form_posts</code> WHERE formid=11 ORDER BY id DESC LIMIT 1
    

    Best regards.

    Thread Starter badmax69

    (@badmax69)

    Every day I work with your plugin is a good day :-). The last weeks I have learned a lot and already implemented a lot.

    I have a tiny problem with the above code. Because with the snippet ‘:’, -1), ‘”‘, ” I also remove the colon and the quotation marks in the text itself. Do you know what I mean? How can I solve that?

    Plugin Author codepeople

    (@codepeople)

    Hello @badmax69,

    The structure of query will depend of your data, at least with my forms it is working properly. Could you send me the URL to the webpage where the form is inserted, and indicate the field with the issue, please?

    Best regards.

    Thread Starter badmax69

    (@badmax69)

    Unfortunately this is not possible because it is not online and I have a non-disclosure agreement ??

    However, I can show you an example. In the database under paypal_post is the following area:

    a:13:{s:6:”formid”;s:2:”10″;s:11:”fieldname16″;s:12:”machine”;s:11:”fieldname17″;s:12:”machine2″;s:11:”fieldname18″;s:5:”12345″;s:11:”fieldname19″;s:13:”12.345 €”;s:11:”fieldname20″;s:568:”4 -axis test machine blablabla.

    blabla: blabla

    Configurable options:
    blabla
    blablabla
    blabal

    blabba:
    asdfasdfsfdasfg

    sdasdfasdf

    asdf
    “;s:11:”fieldname21″;s:269:”das ganze auf deutsch”;s:11:”final_price”;s:7:”4……”;s:10:”couponcode”;s:0:””;s:6:”coupon”;s:0:””;s:9:”ipaddress”;s:0:””;s:23:”submissiondate_mmddyyyy”;s:19:”01/10/2019 12:01:34″;s:23:”submissiondate_ddmmyyyy”;s:19:”10/01/2019 12:01:34″;}

    My Code:
    SELECT REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',4),':',-1), '"', '') AS Name_englisch, REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',6),':',-1), '"', '') AS Name_deutsch, REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',8),':',-1), '"', '') AS Artikelnummer, REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',10),':',-1), '"', '') AS Preis, REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',12),':',-1), '"', '') AS Beschreibung_englisch, REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(paypal_post,';',14),':',-1), '"', '') AS Beschreibung_deutsch FROM{wpdb.prefix}cp_calculated_fields_form_postsWHERE formid=10 ORDER BY id DESC LIMIT 1

    What I get:

    asdfasdfsfdasfg

    sdasdfasdf

    asdf

    Because all the text is truncated before the last colon. The same happens with the semicolons.

    Thread Starter badmax69

    (@badmax69)

    Hi @codepeople
    have you seen my example?

    Plugin Author codepeople

    (@codepeople)

    Hello @badmax69,

    My apologies, I’ve not received the notification of your previous ticket.

    As you cannot controlling the texts entered by the users I recommend you an alternative that not requires the use of DS fields.

    1. Go to the settings page of the plugin, tick the checkbox: “CFF – Server Side Equations”, and press the “Activate/Deactivate addons” button.

    The previous action will enable a new section where entering the server side equations.

    2. Ad the end of server side equations enter the following one:

    
    $GLOBALS['SERVER_SIDE_EQUATIONS']['unserialize'] = function($formid){
    	global $wpdb;
    	$field = $wpdb->get_var("SELECT paypal_post FROM {$wpdb->prefix}cp_calculated_fields_form_posts WHERE formid=".intval($formid)." ORDER BY id DESC LIMIT 1");
    	return json_encode(unserialize($field));
    }; 
    

    3. Finally, into the form insert a calculated field with the following equation:

    
    (function () {
    	var result = JSON.parse(SERVER_SIDE('unserialize', 10));
    	for (var i in result) {
    		try {
    			getField(i).setVal(result[i]);
    		} catch (err) {}
    	}
    })()
    

    and that’s all.

    Pay attention, I’m passing the form’s id as the second parameter of the SERVER_SIDE equation in the following line of code (in this example, the form 10) :

    
    var result = JSON.parse(SERVER_SIDE('unserialize', 10));
    

    Best regards.

    Thread Starter badmax69

    (@badmax69)

    Is that the right way to go about it for me? Because nothing happens, the Calculated Field remains empty.

    To explain: My own customer enters values, prices and explanations in his prepared input masks 1 – 10, which the form 11 later uses again and again. Every user of the website receives these values and adds his data. Therefore I decided to use the DS fields. Does this also work with the server side euqations? If yes, how do I get individual values from the individual fields of the input masks 1 – 10?

    Plugin Author codepeople

    (@codepeople)

    Hello @badmax69,

    I’m sorry, but your question is too general.

    With the code I sent you in the previous ticket, I’m reading the values of fields from the database with the server side equation, and populating the values of the fields in the form through the equation associated to the calculated field (that is being used only as auxiliary, so, you can tick the checkbox fo hiding it from the public form).

    However, the potential is unlimited.

    For example, assuming you want sum the fields fieldname1+fieldname6 from the record returned by the server side equation. In this case the equation associated to the calculated field would be:

    
    (function () {
    	var result = JSON.parse(SERVER_SIDE('unserialize', 10));
            return result['fieldname'+1]+result['fieldname'+6];
    })()
    

    Note that I’m referring to the fields names as ‘fieldname’+1 and ‘fieldname’+6, and not as fieldname1 or fieldname6 because the plugin replaces the texts with the format fieldname# in the equation with the values of corresponding fields in the form.

    In a similar way, if you want evaluate the operation in the server side, and simply display the result in the calculated field, the server side equation can be implemented as follows:

    
    $GLOBALS['SERVER_SIDE_EQUATIONS']['unserialize'] = function($formid){
    	global $wpdb;
    	$field = $wpdb->get_var("SELECT paypal_post FROM {$wpdb->prefix}cp_calculated_fields_form_posts WHERE formid=".intval($formid)." ORDER BY id DESC LIMIT 1");
            $record = unserialize($field);
    	return $record['fieldname1']+$record['fieldname6'];
    }; 
    

    and in this case the equation associated to the calculated field would be simply:

    
    SERVER_SIDE('unserialize', 10)
    

    All these previous cases are hypothetical, you should adapt them to your project.

    Best regards.

    Thread Starter badmax69

    (@badmax69)

    You’re my hero, if I haven’t said that yet ??
    And how do I get the result as a placeholder in the normal input field? Currently I use a Text Area DS as input field.

    Plugin Author codepeople

    (@codepeople)

    Hello @badmax69,

    The placeholder are specific attributes on html tags, for example, if you have the input field fieldname1 in the form, and you want assign to it a placeholder, you can use as part of the equation the piece of code:

    
    jQuery('[id*="fieldname'+'1_"]').attr('placeholder', 'Text to display here');
    

    and that’s all.

    Note that a placeholder is not a default value, they don’t affect the equations and are not submitted with the form.

    Best regards.

    Thread Starter badmax69

    (@badmax69)

    Sorry, I didn’t mean as a placeholder. Because here I can’t change the text, but after entering the first letter the text disappears. “Value” … I only must unserialize that.. hmm And the next problem: The Text begins with: “4-axis…” and here I only get “4”. If I change 4 to four I get the whole text

    • This reply was modified 5 years, 10 months ago by badmax69.
    • This reply was modified 5 years, 10 months ago by badmax69.
    • This reply was modified 5 years, 10 months ago by badmax69.
    Plugin Author codepeople

    (@codepeople)

    Hello

    If you want assign a value for example to the fieldname123 field from the equation, the code to use as part of the equation would be:

    
    getField(123).setVal('The value here');
    

    Best regards.

Viewing 15 replies - 16 through 30 (of 32 total)
  • The topic ‘How can I create a checklist from several fields?’ is closed to new replies.