Crocoblock / jetformbuilder

72 stars 15 forks source link

[Question] Is there a way to hide a calculated field formula server side? #328

Open eclipses opened 11 months ago

eclipses commented 11 months ago

I doubt this is possible but maybe you can find this question interesting. I would like to hide a formula of a calculated field to the end user. Is there any way how this could be possible in JetFormBuilder?

ihslimn commented 11 months ago

You may use this https://github.com/ihslimn/jet-form-builder-update-field to update field value with a value that comes from a custom PHP callback. Yet in this case you have to have some knowledge in PHP

eclipses commented 1 week ago

Unfortunately this is not an applicable solution as "Works for Select, Radio, Checkboxes fields" Let us say that I have a Calculate field with a Formula depending on other fields and I multiply by a constant, e.g. %Field1%%Field2%0.5 and I would like to hide this formula so that the users cannot know I'm multiplying by 0.5 I hope this make sense to you, of course my formula is more complex than this, but it is just an example on what I would like to achieve.

ihslimn commented 1 week ago

@eclipses it works for text/hidden fields as well, you will just need a little knowledge of PHP to make a function that performs a calculation

like

function form_sum_and_mult( $field_name, $form_id, $fields ) {
    $num1 = ! empty( $fields['num1'] ) ? ( float ) $fields['num1'] : 0;
    $num2 = ! empty( $fields['num2'] ) ? ( float ) $fields['num2'] : 0;

    return ( $num1 + $num2 ) * 0.5;
}

image