将形式的值发送到隐藏的重力形式

时间:2016-07-08 07:47:52

标签: php jquery wordpress gravity

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

Heres the custom form that i have made

无论如何都要将我的自定义表单的值解析为隐藏的重力场形式?如果有的话,将重力形式的邮件发送给我会好得多。 我的所有文件都在我的本地主机中,因此无法链接到网站,但是您可以查看表单。

我用过的Js是

MainActivity

我需要获取被检查的总项目的值和总和 隐藏字段的Html是

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
        }
    }       

当用户点击提交按钮时,如果能够获得<input name="input_6" id="input_1_6" type="hidden" class="gform_hidden" aria-invalid="false" value="template-calculator"> 隐藏字段名称#immer-total的价值。

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

input_6

但没有得到结果。

2 个答案:

答案 0 :(得分:3)

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);
    });
});
  

注意 - 您提供的链接具有<form>标记,而不是隐藏的输入字段。

以下是基于您的代码的工作示例:

$(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>

答案 1 :(得分:1)

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

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
) );