WordPress.org

Forums

Calculated Fields Form
[resolved] return a Text value from a calculation (6 posts)

  1. metanoia77
    Member
    Posted 1 year ago #

    Hi

    I need to set that to a Text value based on a number

    Pseudo code:

    If field21 > 100 return "Complete";

    If field21 < 50 return "Incomplete";

    now I was thinking of setting up 2 "hidden from user fields"

    field25 initial value complete
    field26 initial value incomplete

    and using the Pseudo code to return fieldnames with default values of complete and incomplete ??

    anyway can I return text ? if so how ty :-)

    https://wordpress.org/plugins/calculated-fields-form/

  2. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    By default the calculated field only accepts numeric values, and texts with date format, but if you want accept texts like "Complete" or "Incomplete", you should modify the validation rules in the module_public.js file, located in "/wp-content/plugins/calculated-fields-form/js/modules/01_mathematical_logical/public/module_public.js"

    1. Open the module_public.js file in the text editor your choice.

    2. Go to the snippet of code:

    return isFinite( v ) || /\d{2}[\/\-\.]\d{2}[\/\-\.]\d{4}/.test( v );

    and modify it like follow:

    return isFinite( v ) || /\d{2}[\/\-\.]\d{2}[\/\-\.]\d{4}/.test( v ) || /complete|incomplete/i.test( v );

    Best regards.

  3. metanoia77
    Member
    Posted 1 year ago #

    Thanks

    btw now i have my form - its working perfectly - but I cannot use <%info%>
    as the contact details are at the bottom - I moved them to the top and also formatting the email as a HTML Table etc ..(looks really pretty :-) LoL)

    so I would like to add the "Include additional information" is there a <%IP addr%> or <%add-info%> ???

    really great plugin !!! so versatile - beats the socks off other forms :-)

    I even found a way to add the company logo :-) so cooooooool !!!

  4. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    To send additional information, that is not collected by the forms, will require customize the plugin's code.

    Specifically the cp_calculatedfieldsf.php file, around the line number 966, above the snippet of code:

    foreach ($to as $item)
    if (trim($item) != '')
    {
    wp_mail(trim($item), $subject, $message,
    "From: \"$from_1\" <".$from_1.">\r\n".
    ($replyto!=''?"Reply-To: \"$replyto\" <".$replyto.">\r\n":'').
    $content_type.
    "X-Mailer: PHP/" . phpversion(), $attachments);
    }

    For example, using the code:

    $message .= '
    IP Address: '.$_SERVER['REMOTE_ADDR'];

    Best regards.

  5. metanoia77
    Member
    Posted 1 year ago #

    Thanks - I will try that :-) Im just amazed how cool you guys are - this is my #1 plugin I wish I could give you 10 stars. I am gonna try to get more of my clients on board :-)

  6. gestaltraeume
    Member
    Posted 8 months ago #

    Hi

    I need to set the follow code to a text value based on a number:

    (function(){
    if(fieldname4=='1') return 'Liter';
    if(fieldname4=='2') return 'm³';
    if(fieldname4=='3') return 'kg';
    if(fieldname4=='4') return 'Ster';
    if(fieldname4=='5') return 'kg';
    });

    How can i get that?

    I read the Text up there and put a javascript into module_public.js:
    return isFinite( v ) || /\d{2}[\/\-\.]\d{2}[\/\-\.]\d{4}/.test( v ) || /Liter|m³|kg|Ster/i.test( v );

    Thank´s for help!

    Best regards.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Calculated Fields Form
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.