将表单的值发送到隐藏的重力场表单

send value of form to hidden field of gravity form

我制作了一个包含项目复选框的自定义表单。如果用户选中该复选框,则会显示总金额以及姓名、电子邮件、地址和消息的重力表。 如果用户填写自定义表格和重力表格,其中包含用总计检查的项目,并且表格填写重力表格部分,我想收到一封电子邮件。重力形式没问题。我可以收到 gravity form 部分的电子邮件,但我想知道哪些项目被检查以及总金额也在通过 gravity form 发送的同一封电子邮件中

Heres the custom form that i have made

有没有办法将我的自定义表单的值解析为隐藏的重力场表单?如果有的话用重力形式发邮件给我会好很多。 我的所有文件都在我的本地主机中,因此无法 link 访问站点,但有一个 fiddle 您可以查看表单。

我用过的Js是

var inputs = document.getElementsByClassName('immer'),
        total  = document.getElementById('immer-total');

 for (var i=0; i < inputs.length; i++) {
        inputs[i].onchange = function() {
            var add = this.value * (this.checked ? 1 : -1);
            total.innerHTML = parseFloat(total.innerHTML) + add
        }
    }

 var dazuinputs = document.getElementsByClassName('dazu'),
        totalDazu  = document.getElementById('dazu-total');
 for (var i=0; i < dazuinputs.length; i++) {
        dazuinputs[i].onchange = function() {
            var add = this.value * (this.checked ? 1 : -1);
            totalDazu.innerHTML = parseFloat(totalDazu.innerHTML) + add
        }
    }       

我需要得到检查的总项目的价值和总和 Html 隐藏字段是

<input name="input_6" id="input_1_6" type="hidden" class="gform_hidden" aria-invalid="false" value="template-calculator">

如果有一种方法可以在用户单击提交按钮时将 #immer-total 的值获取到隐藏字段名称 input_6

经过一些研究,我得到了一个 js

   var counter = 0;
  $('.gform_button').click(function(event){
   event.preventDefault();
    counter++;

     ...
   $('#immer-total').attr('input_3', counter);
   }

但是没有得到结果。

jQuery 真的可以帮到你。而不是每次有人点击时都计算输入 - 只需在需要时计算它们:

counter = $('input:checkbox:checked').length

然后您可以将该数字设置为隐藏字段的值:

$('#input_1_6').val(counter)

提交表单时最好这样做:

$(function() {
    $('#frm1').submit(function() {
        counter = $('input:checkbox:checked').length;
        alert('Total number of checked checkboxes: '+counter);
        $('#input_1_6').val(counter);
    });
});

Note - the link you provided doesn't have the <form> tag and not the hidden input field.

这是一个基于您的代码的工作示例:

$(function() {
        $('#frm1').submit(function() {
            counter = $('input:checkbox:checked').length;
            alert('Total number of checked checkboxes: '+counter);
            $('#input_1_6').val(counter);
        });
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="frm1" action="" method="post">
  <section id="template-calculator-wrap">
 <div class="calculator-margin">
  <h1>Paket-Konfigurator für Ihren Hotel oder Restaurant Webauftritt</h1>
  <div class="red-bar"></div>
  <h2>We create a unique process for each client to ensure that business objectives are met, success is achieved and users are happy.</h2>

  <div class="calculator-total-wrap">
   <div class="row">
    <div class="col-md-6 col-sm-6 col-xs-6 calc-total1">
     <h1><span>CHF</span> 4’850.-</h1>
     <h3>Erstellung einmalig</h3>
    </div>

    <div class="col-md-6 col-sm-6 col-xs-6 calc-total2">
     <h1><span>CHF</span> 2’975.-</h1>
     <h3>Unterhalt jährlich</h3>
    </div>
   </div>
  </div>

  <div class="row">
   <div class="col-md-6 col-sm-6">
    <div class="price-col-title-wrap">
     <h4>Immer enthalten</h4>
     <h3><span>CHF</span> <span id="immer-total">0</span>.-</h3>
        <input type="checkbox" id="c1" class="immer" value="50" name="cc" onclick="return false" checked="">
          <label for="c1"><span> </span> Installation Wordpress</label> <br>
          
          <input type="checkbox" id="c2" class="immer" value="50" name="cc">
          <label for="c2"><span> </span>  Basis SEO und Dynamic Sitemap</label> <br>

          <input type="checkbox" id="c3" class="immer" value="50" name="cc">
          <label for="c3"><span> </span> Adresse, Öffungszeiten, Telefon mit Call-Funktion für mobil</label> <br>

          <input type="checkbox" id="c4" class="immer" value="50" name="cc">
          <label for="c4"><span> </span> Seite für Datenschutz und Impressum</label> <br>

          <input type="checkbox" id="c5" class="immer" value="50" name="cc">
          <label for="c5"><span> </span> Social Media Follow (FB, G+, Twitter)</label> <br>

          <input type="checkbox" id="c6" class="immer" value="50" name="cc">
          <label for="c6"><span> </span> Kontaktformular + Google Map API</label> <br>
        </div>

        <div class="price-col-title-wrap">
     <h4>Dazu Module für Funktionalität</h4>
     <h3><span>CHF</span> <span id="dazu-total">0</span>.-</h3>
        <input value="50" class="dazu" type="checkbox" id="d1" name="cc">
          <label for="d1"><span> </span> Installation Wordpress</label> <br>
          
          <input value="50" class="dazu" type="checkbox" id="d2" name="cc">
          <label for="d2"><span> </span>  Basis SEO und Dynamic Sitemap</label> <br>

          <input value="50" class="dazu" type="checkbox" id="d3" name="cc">
          <label for="d3"><span> </span> Adresse, Öffungszeiten, Telefon mit Call-Funktion für mobil</label> <br>

          <input value="50" class="dazu" type="checkbox" id="d4" name="cc">
          <label for="d4"><span> </span> Seite für Datenschutz und Impressum</label> <br>

          <input value="50" class="dazu" type="checkbox" id="d5" name="cc">
          <label for="d5"><span> </span> Social Media Follow (FB, G+, Twitter)</label> <br>

          <input class="dazu" type="checkbox" id="c6" name="cc">
          <label for="c6"><span> </span> Kontaktformular + Google Map API</label> <br>

          <input class="dazu" type="checkbox" id="c1" name="cc">
          <label for="c1"><span> </span> Installation Wordpress</label> <br>
          
          <input class="dazu" type="checkbox" id="c2" name="cc">
          <label for="c2"><span> </span>  Basis SEO und Dynamic Sitemap</label> <br>

          <input class="dazu" type="checkbox" id="c3" name="cc">
          <label for="c3"><span> </span> Adresse, Öffungszeiten, Telefon mit Call-Funktion für mobil</label> <br>

          <input class="dazu" type="checkbox" id="c4" name="cc">
          <label for="c4"><span> </span> Seite für Datenschutz und Impressum</label> <br>

          <input class="dazu" type="checkbox" id="c5" name="cc">
          <label for="c5"><span> </span> Social Media Follow (FB, G+, Twitter)</label> <br>

          <input class="dazu" type="checkbox" id="c6" name="cc">
          <label for="c6"><span> </span> Kontaktformular + Google Map API</label> <br>

          <input class="dazu" type="checkbox" id="c1" name="cc">
          <label for="c1"><span> </span> Installation Wordpress</label> <br>
          
          <input class="dazu" type="checkbox" id="c2" name="cc">
          <label for="c2"><span> </span>  Basis SEO und Dynamic Sitemap</label> <br>

          <input class="dazu" type="checkbox" id="c3" name="cc">
          <label for="c3"><span> </span> Adresse, Öffungszeiten, Telefon mit Call-Funktion für mobil</label> <br>

          <input class="dazu" type="checkbox" id="c4" name="cc">
          <label for="c4"><span> </span> Seite für Datenschutz und Impressum</label> <br>


          <input class="dazu" type="checkbox" id="c6" name="cc">
          <label for="c6"><span> </span> Kontaktformular + Google Map API</label> <br>
        </div>

       </div>

       <div class="col-md-6 col-sm-6">
    <div class="price-col-title-wrap">
     <h4>Immer enthalten</h4>
     <h3><span>CHF</span> 1’600.-</h3>
        <input type="checkbox" id="c1" name="cc">
          <label for="c1"><span> </span> Installation Wordpress</label> <br>
          
          <input type="checkbox" id="c2" name="cc">
          <label for="c2"><span> </span>  Basis SEO und Dynamic Sitemap</label> <br>

          <input type="checkbox" id="c3" name="cc">
          <label for="c3"><span> </span> Adresse, Öffungszeiten, Telefon mit Call-Funktion für mobil</label> <br>

          <input type="checkbox" id="c4" name="cc">
          <label for="c4"><span> </span> Seite für Datenschutz und Impressum</label> <br>

          <input type="checkbox" id="c5" name="cc">
          <label for="c5"><span> </span> Social Media Follow (FB, G+, Twitter)</label> <br>

          <input type="checkbox" id="c6" name="radio">
          <label for="c6"><span> </span> Kontaktformular + Google Map API</label> <br>
     
     <label>Design-Anpassungen Paket </label><br>
         <input type="radio" id="R1" name="cc">
         <label for="R1" class="radio-padding-right"><span> </span> 8 Stunden</label> 
     
      <input type="radio" id="R2" name="cc">
         <label for="R2"><span> </span> 12 Stunden</label> <br>
        </div>

        <div class="price-col-title-wrap">
     <h4>Dazu Module für Content</h4>
     <h3><span>CHF</span> 1’600.-</h3>

     <label>Design-Anpassungen Paket </label><br>
            <div class="numbers-row">
             <!-- <label for="name">French Hens</label> <br/> -->
             <div class="dec button">-</div>
             <input type="text" name="french-hens" id="french-hens" value="11">
             <div class="inc button">+</div>
               </div> 
         
      
     <input type="checkbox" id="c5" name="cc">
        <label for="c5"><span> </span> Social Media Follow (FB, G+, Twitter)</label> <br>

         <label>Design-Anpassungen Paket </label><br>
         <input type="radio" id="R4" name="cc">
         <label for="R4" class="radio-padding-right"><span> </span> 8 Stunden</label> 
     
      <input type="radio" id="R5" name="cc">
         <label for="R5" class="radio-padding-right"><span> </span> 12 Stunden</label> 

         <input type="radio" id="R3" name="cc">
         <label for="R3"><span> </span> 12 Stunden</label> <br>

         <label>Design-Anpassungen Paket </label><br>
         <input type="radio" id="R4" name="cc">
         <label for="R4" class="radio-padding-right"><span> </span> 8 Stunden</label> 
     
      <input type="radio" id="R5" name="cc">
         <label for="R5" class="radio-padding-right"><span> </span> 12 Stunden</label> 

         <input type="radio" id="R3" name="cc">
         <label for="R3"><span> </span> 12 Stunden</label> <br>

         <label>Design-Anpassungen Paket </label><br>
         <input type="radio" id="R4" name="cc">
         <label for="R4" class="radio-padding-right"><span> </span> 8 Stunden</label> 
     
      <input type="radio" id="R5" name="cc">
         <label for="R5" class="radio-padding-right"><span> </span> 12 Stunden</label> 

         <input type="radio" id="R3" name="cc">
         <label for="R3"><span> </span> 12 Stunden</label> <br>
        </div>
    
    

       </div>

     </div>

   <!-- gravity form here -->

  </div> <!-- end calculator-margin div -->
 

</section>
<input name="input_6" id="input_1_6" type="hidden" class="gform_hidden" aria-invalid="false" value="template-calculator">
  <input type="submit" name="submit" value="submit" />
</form>

你好,我不知道我是否理解正确的问题......但据我所知,你想计算复选框的选中并通过电子邮件发送......如果这是你的问题,那么解决方案就在这里......

https://gist.github.com/spivurno/a14ef4a18f57d0c67811e1b4d8791781

这是一个简单的功能,您必须编写并制作隐藏文件以进行总检查...之后您可以在确认设置中使用该文件...作为合并标签以根据需要获取电子邮件通知。

配置只需在代码底部根据需要更改值

new GW_Checkbox_Count( array(
    'form_id'            => 123, // the ID of your form
    'count_field_id'     => 2, // any Number field on your form in which the number of checked checkboxes should be dynamically populated; you can configure conditional logic based on the value of this field.
    'checkbox_field_ids' => array( 5, 8 ) // any array of Checkbox field IDs which should be counted
) );

将此添加到您的函数中

<?php
/**
 * Gravity Wiz // Gravity Forms // Checkbox Count
 *
 * Get the total number of checkboxes checked. Useful when wanting to apply conditional logic based on the number of
 * checkboxes checked.
 *
 * @version   2.4
 * @author    David Smith <david@gravitywiz.com>
 * @license   GPL-2.0+
 * @link      http://gravitywiz.com/...
 * @copyright 2018 Gravity Wiz
 */
class GW_Checkbox_Count {

    private static $is_script_output;

    function __construct( $args ) {

        $this->_args = wp_parse_args( $args, array(
            'form_id'            => false,
            'count_field_id'     => false,
            'checkbox_field_id'  => null,
            'checkbox_field_ids' => false
        ) );

        if( isset( $this->_args['checkbox_field_id'] ) ) {
            $this->_args['checkbox_field_ids'] = array( $this->_args['checkbox_field_id'] );
        }

        add_filter( 'gform_pre_render',            array( $this, 'load_form_script' ), 10, 2 );
        add_action( 'gform_register_init_scripts', array( $this, 'add_init_script' ) );
        //add_action( 'gform_pre_validation',        array( $this, 'override_submitted_value') );

    }

    public function load_form_script( $form, $is_ajax_enabled ) {

        if( $this->is_applicable_form( $form ) && ! has_action( 'wp_footer', array( $this, 'output_script' ) ) ) {
            add_action( 'wp_footer', array( $this, 'output_script' ) );
            add_action( 'gform_preview_footer', array( $this, 'output_script' ) );
        }

        return $form;
    }

    function output_script() {
        ?>

        <script type="text/javascript">

            ( function( $ ) {

                window.GWCheckboxCount = function( args ) {

                    var self = this;

                    // copy all args to current object: formId, fieldId
                    for( prop in args ) {
                        if( args.hasOwnProperty( prop ) )
                            self[prop] = args[prop];
                    }

                    self.init = function() {

                        for( var i = 0; i < self.checkboxFieldIds.length; i++ ) {

                            var checkboxFieldId = self.checkboxFieldIds[ i ],
                                checkboxField   = $( '#input_' + self.formId + '_' + checkboxFieldId );

                            checkboxField.find( 'input[type="checkbox"]' ).click( function() {
                                self.updateCheckboxCount( self.formId, self.checkboxFieldIds, self.countFieldId );
                            } );

                        }

                        self.updateCheckboxCount( self.formId, self.checkboxFieldIds, self.countFieldId );

                    };

                    self.updateCheckboxCount = function( formId, checkboxFieldIds, countFieldId ) {

                        var countField    = $( '#input_' + formId + '_' + countFieldId ),
                            count         = 0;

                        for( var i = 0; i < checkboxFieldIds.length; i++ ) {

                            var checkboxField = $( '#input_' + formId + '_' + checkboxFieldIds[ i ] );

                            count += checkboxField.find( 'input[type="checkbox"]' ).filter(':checked').length;

                        }

                        if( parseInt( countField.val() ) != parseInt( count ) ) {
                            countField.val( count ).change();
                        }

                    };

                    self.init();

                }

            } )( jQuery );

        </script>

        <?php
        self::$is_script_output = true;
    }

    function add_init_script( $form ) {

        if( ! $this->is_applicable_form( $form['id'] ) )
            return;

        $args = array(
            'formId'           => $this->_args['form_id'],
            'countFieldId'     => $this->_args['count_field_id'],
            'checkboxFieldIds' => $this->_args['checkbox_field_ids']
        );

        $script = 'new GWCheckboxCount( ' . json_encode( $args ) . ' );';
        $slug = implode( '_', array( 'gw_checkbox_count', $this->_args['form_id'], $this->_args['count_field_id'] ) );

        GFFormDisplay::add_init_script( $this->_args['form_id'], $slug, GFFormDisplay::ON_PAGE_RENDER, $script );

        return;
    }

    function override_submitted_value( $form ) {
        //$_POST["input_{$this->count_field_id}"] = $day_count;
        return $form;
    }

    public function is_applicable_form( $form ) {

        $form_id = isset( $form['id'] ) ? $form['id'] : $form;

        return empty( $this->_args['form_id'] ) || $form_id == $this->_args['form_id'];
    }

    public function is_ajax_submission( $form_id, $is_ajax_enabled ) {
        return isset( GFFormDisplay::$submission[ $form_id ] ) && $is_ajax_enabled;
    }

}

# Configuration

new GW_Checkbox_Count( array(
    'form_id'            => 123, // the ID of your form
    'count_field_id'     => 2, // any Number field on your form in which the number of checked checkboxes should be dynamically populated; you can configure conditional logic based on the value of this field.
    'checkbox_field_ids' => array( 5, 8 ) // any array of Checkbox field IDs which should be counted
) );