• I have put a javascript number spinner in my CF7-form and I’m trying to make a custom form tag for it so that input names would generate automatic like mvr1, mvr2, mvr3… because I have multiple number inputs/spinners in the same form. I just cant get the number to appear in the inputs name. It just shows <input type=”text” name=”mvr[]” class=”in-num czr-focusable” value=”1″ readonly=””> in every field. What am I doing wrong?

    
    add_action( 'wpcf7_init', 'custom_add_form_tag_spin' );
    
    function custom_add_form_tag_spin() {
    	wpcf7_add_form_tag( 'spin', 'custom_spin_form_tag_handler', array( 'name-attr' => true ));
    }
    
    function custom_spin_form_tag_handler( $tag ){
    	return'<div class="num-block skin-7">
    	<div class="num-in">
    	<span class="minus dis">-</span>
    	<input type="text" name="mvr[]" class="in-num" value="1" readonly=""
    	<span class="plus">+</span>
    	</div>
    	</div>';
    	{
    		$name = $_POST['mvr'];
    		foreach( $name as $key => $n ) {
    			print $n;
    		}
    	}
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi, bhasic, I’m another CF7 user.

    What was your intent with the code block:

    {
    		$name = $_POST['mvr'];
    		foreach( $name as $key => $n ) {
    			print $n;
    		}
    	}

    ?

    Since you return the string prior to that, this code doesn’t run.

    Thread Starter bhasic

    (@bhasic)

    That code block is supposed to generate numbers for mvr[] field names. I can’t get it to work no matter where I put the block. Does not work even when it’s run before return.

    Hi, bhasic, if you want to increment the name attribute, work along the lines of this idea – increment the name attribute via PHP:

    <input type="text" name="mvr<?php $name = $_POST['mvr'];
    		foreach( $name as $key => $n ) {
    			print $n;
    		} ?>" class="in-num" value="1" readonly=""

    Currently your code will output the same name attribute to each field because you are not manipulating it using PHP.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom form tag generate input names’ is closed to new replies.