0

So I have a form (dynamically built from selections by the user) and I ran into an "issue" I didnt really think of. I can get the data easy enough with jquery like:

        var myForm = document.getElementById('form');

        var formData = new FormData(myForm),
        data = {};

        for (var entry of formData.entries()) {
            data[entry[0]] = entry[1];
        }
        data = JSON.stringify(data)
        console.log(data);

        $('#json').text(data)

In the console, this produces:

{"form_fullname":"first name last name","form_email":"test@email.com","form_phone":"8885551234","comments":"Justo Lorem Euismod"}

I need to pass this data via an ajax request to a php file that would loop through the data and send it out using phpmailer. I have sucessfully sent form data via ajax before to phpmailer (or just to a php file) many times, but I guess due to the fields being dynamic I am a bit unsure of how to split the data and submit it as something like:

Full Name: $fullName
Email: $fullname
etc etc
  • I guess you will always need basic detail from your form for your PHPmailer to work `email, name` the rest of the dynamic fields you can check you have in total to check on the php side using `isset()` to see if the field is being passed from ajax to php or not. – Always Helping Jul 03 '20 at 18:55

0 Answers0