javascript - Capture Array Values from Dynamic input Fields using PHP and email them -


i have large form, in form there multiple dynamic form fields can added user. need capture these using php , email, there no mysqli connection necessary. use javascript handle dynamic form fields appearing , disappearing.

one of html dynamic form fields looks this--

<div class="col-sm-1">                 <select id="about_you_dep-gender[]" name="about_you_dep-   gender[]" class="form-control">                     <option value="male">male</option>                     <option value="female">female</option>                 </select><div class="help">gender</div>             </div> 

the php looks - if submit form content of field says:array

    <?php if(!isset($_post['submit'])) {     echo "error; need submit form!";     $about_you_dep_gender = $_post['about_you_dep-gender'];     $email_subject = "new form submission";    $email_body = "you have received new filled out form client      $about_you_name.\n\n".  "dependant gender: $about_you_dep_gender \n".   } 

the javascript below , part of form seems working fine.

<script> $(document).ready(function() { // maximum number of options var max_options = 3;  $('#custom')     .formvalidation({         framework: 'bootstrap',         icon: {             valid: 'glyphicon glyphicon-ok',             invalid: 'glyphicon glyphicon-remove',             validating: 'glyphicon glyphicon-refresh'         }         })      // add button click handler     .on('click', '.addbutton', function() {         var $template = $('#deptemplate'),             $clone    = $template                             .clone()                             .removeclass('hide')                             .removeattr('id')                             .insertbefore($template),             $dep_name   = $clone.find('[name="about_you_dep-name[]"]')             $dep_gender   = $clone.find('[name="about_you_dep-gender[]"]')             $dep_dob   = $clone.find('[name="about_you_dep-dob[]"]')             $dep_fin   = $clone.find('[name="about_you_dep-fin[]"]')             $dep_until   = $clone.find('[name="about_you_dep-until[]"]');          // add new field         $('#custom')             .formvalidation('addfield', $dep_name)              .formvalidation('addfield', $dep_gender)              .formvalidation('addfield', $dep_dob)             .formvalidation('addfield', $dep_fin)             .formvalidation('addfield', $dep_until);     })      // remove button click handler     .on('click', '.removebutton', function() {         var $row    = $(this).parents('.form-group'),             $dep_name = $row.find('[name="about_you_dep-name[]"]')             $dep_gender = $row.find('[name="about_you_dep-gender[]"]')             $dep_dob = $row.find('[name="about_you_dep-dob[]"]')             $dep_fin = $row.find('[name="about_you_dep-fin[]"]')             $dep_until = $row.find('[name="about_you_dep-until[]"]');          // remove element containing option         $row.remove();          // remove field         $('#custom')             .formvalidation('removefield', $dep_name)              .formvalidation('removefield',  $dep_gender)              .formvalidation('removefield', $dep_dob)             .formvalidation('removefield', $dep_fin)             .formvalidation('removefield', $dep_until);     })      // called after adding new field     .on('added.field.fv', function(e, data) {         // data.field   --> field name         // data.element --> new field element         // data.options --> new field options          if (data.field === 'about_you_dep-name[]') {             if ($('#custom').find(':visible[name="about_you_dep-name[]"]').length >= max_options) {                 $('#custom').find('.addbutton').attr('disabled', 'disabled');             }         }     })      // called after removing field     .on('removed.field.fv', function(e, data) {        if (data.field === 'about_you_dep-name[]') {             if ($('#custom').find(':visible[name="about_you_dep-name[]"]').length < max_options) {                 $('#custom').find('.addbutton').removeattr('disabled');             }         }     }); 

});

currently when process form returns answer:array, instead of actual input form field. appreciated. thank in advance :)

you have loop through array

<?php if(!isset($_post['submit'])) {     $dependents = array();      foreach ($_post['about_you_dep-gender'] $key => $value) {          $dependents[] = array(              'name'   => $_post['about_you_dep-name'][$key],              'gender' => $_post['about_you_dep-gender'][$key],              'dob' => $_post['about_you_dep-dob'][$key],          );    }     $email_subject = "new form submission";    $email_body = "you have received new filled out form client.\n\n";    $email_body .= "name: " . $aboutyouname . "\n";     foreach ($dependents $dependent) {        $email_body .= "dependent name: " . $dependent['name'] . "\n";        $email_body .= "dependent gender: " . $dependent['gender'] . "\n";        $email_body .= "dependent dob: " . $dependent['dob'] . "\n";    }     // send email } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -