• Resolved Nokaa

    (@nokaa)


    Hi,

    I got an issue with that : in order to validate a form, I created a script which call the names of all input which has the type ‘checkbox’, remove the occurences, and verify if at least one checkbox of a group is checked.

    At this moment my script returned an error that let me show that the CF7 checkboxes automatically add tags [] after their name. I didn’t find why…

    Here’s an example of my input :

    [checkbox* sample "Red" "Blue" "Yellow"]

    That’s what we got :

    <span class="wpcf7-form-control-wrap sample">
    	<span class="wpcf7-form-control wpcf7-checkbox wpcf7-validates-as-required">
    		<span class="wpcf7-list-item first">
    			<input name="sample[]" value="Red" type="checkbox"><span class="wpcf7-list-item-label">Red</span>
    		</span>
    		<span class="wpcf7-list-item">
    			<input name="sample[]" value="Blue" type="checkbox"><span class="wpcf7-list-item-label">Blue</span>
    		</span>
    		<span class="wpcf7-list-item">
    			<input name="sample[]" value="Yellow" type="checkbox"><span class="wpcf7-list-item-label">Yellow</span>
    		</span>
    	</span>
    </span>

    The name of my checkboxes became “sample[]” instead of “sample” as we wrote it.

    In the future, it will also be difficult to manage for me because I need to create huge forms and pass them trough a third party system, which will collect the data to relay them in another back-office. So, I need to be able to use the exact terms…

    Can you help me on this way ?

    Thank you in advance

    • This topic was modified 6 years, 11 months ago by Nokaa.
    • This topic was modified 6 years, 11 months ago by Nokaa.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Nokaa

    (@nokaa)

    For now and if someone asks for a solution, I rectified that behaviour with a little function :

    // Rectify checkboxes "name" generated from Contact Form 7
    function rectifyCheckboxInput(){
      var checkbox = $('.wpcf7-form').find('input[type=checkbox]');
      $.each(checkbox, function(i, el){
          current_name = $(el).attr('name');
          $(el).attr('name', current_name.replace('[]',''));
      });
    }
    rectifyCheckboxInput(); 

    But I still think that thoses additionnal tags are undesired … Maybe an error in the plugin ? Or is there another reason ?

    • This reply was modified 6 years, 11 months ago by Nokaa.
    Plugin Author Takayuki Miyoshi

    (@takayukister)

    This FAQ answer explains when you use [] in HTML form.

    http://php.net/manual/en/faq.html.php#faq.html.arrays

    Thread Starter Nokaa

    (@nokaa)

    Didn’t know that…
    So I presume I need to use them whatever happen if I want to send multiple values for my checkbox groups.

    Thank you for your fast answer

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Checkbox automatically add tags ‘[]’ after its name’ is closed to new replies.