最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Gravity Forms non-empty Total field values not submitted

programmeradmin0浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I have created a gravity form and used several Total fields. Although I do not have any Product fields in my form, which the Total field is usually used to display the total of product prices, I used the Total field because I like the way it automatically formats prices and I am setting the values of the Total fields in my form via my own jQuery code. My code updates both the text in the Total field span element and the associated hidden input element.

However, despite these values displaying in the Total fields on the form, when the form is submitted the Total fields' values are not displaying in the form entries or email notifications.

I know my use of the Total field is not strictly in keeping with the intended usage, but I do not know why the field values are missing from the submission entries. Any ideas why and if there is a way to get around the problem?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I have created a gravity form and used several Total fields. Although I do not have any Product fields in my form, which the Total field is usually used to display the total of product prices, I used the Total field because I like the way it automatically formats prices and I am setting the values of the Total fields in my form via my own jQuery code. My code updates both the text in the Total field span element and the associated hidden input element.

However, despite these values displaying in the Total fields on the form, when the form is submitted the Total fields' values are not displaying in the form entries or email notifications.

I know my use of the Total field is not strictly in keeping with the intended usage, but I do not know why the field values are missing from the submission entries. Any ideas why and if there is a way to get around the problem?

Share Improve this question asked Dec 16, 2020 at 16:57 authentictechauthentictech 1258 bronze badges 4
  • 1 Recommend contacting the support folks at Rocket that author the Gravity Forms plugin: gravityforms/support – jdm2112 Commented Dec 16, 2020 at 20:17
  • 1 For security the total field value from the submission is not used. The plugin re-calculates the total during submission using the saved values of the other pricing fields on the form. Have you considered using a Number field with the calculation feature enabled and the format set to the currency option? – richardW8k Commented Dec 17, 2020 at 17:07
  • @richardW8k Ah I understand. I could use a Number field but I don't want the totals to be modified by the user. So if I want to submit the totals with the form I must use a calculated Number field. I suppose I must use Javascript to make the fields read only? – authentictech Commented Dec 17, 2020 at 17:54
  • You need to contact Gravity Forms support, 3rd party plugin dev support is off topic here, you cannot ask for help using 3rd party plugins here – Tom J Nowell Commented Dec 18, 2020 at 13:49
Add a comment  | 

1 Answer 1

Reset to default 1

As @richardW8k pointed out, Total field values are recalculated on submission and will override anything submitted from the frontend.

If your custom jQuery code can be replaced by a formula in the Number field, that'd definitely the way to go. If your jQuery code is doing some more complex logic a calculated Number field will have the same issue as the total field. The submitted value will be overridden by the calculated value on submission.

Here's a solution that allows you to use your custom jQuery code to update the value of a read-only Number field styled to look like the Total field.

  1. Add a Number field to your form.

  2. Mark the field as read-only. There are two ways to do this.

    The Easy Way
    GF Read Only provides the ability to mark fields as readonly right from the field settings.

    The Hard Way
    This snippet from Gravity Forms can do the job.

    // update '1' to the ID of your form
    add_filter( 'gform_pre_render_1', 'add_readonly_script' );
    function add_readonly_script( $form ) {
        ?>
    
        <script type="text/javascript">
            jQuery(document).ready(function(){
                /* apply only to a input with a class of gf_readonly */
                jQuery("li.gf_readonly input").attr("readonly","readonly");
            });
        </script>
    
        <?php
        return $form;
    }
    
    
  3. Target this Number field with your jQuery code to update the price.

  4. Use our styles to style your Number field like a total field by adding a "gf_total" class to the field's CSS Class Name setting.

    /**
     * Gravity Wiz // Gravity Forms // Style Number Fields like Total Field
     *
     * Use "gf_price" and "gf_total" CSS classes via the "CSS Class Name" setting to style your Number fields like a product
     * price (red) or total (green).
     */
    .gform_wrapper .gf_price input[type=text],
    .gform_wrapper .gf_price input[type=number] {
        border: 0;
        font-size: 1.2em;
        color: #060;
        text-indent: 0;
        padding: 0;
    }
    .gform_wrapper .gf_total input[type=text],
    .gform_wrapper .gf_total input[type=number] {
        color: #060;
    }
    
发布评论

评论列表(0)

  1. 暂无评论