0

enter image description here

I have there an example part of my form, (my form has 4 different fields/div like that) and i cannot think of how i can send the values of those created input fields on php via ajax. Sorry if i can't explain it well. I have searched for this but i can't get the exact answer i'm looking for.

<input type = "text" class = "form-control" placeholder="Knowledgeable/Proficient in.." name = "skills[]" >

I want to use a function which uses some kind of name="skills[]" (or array type) instead of something like name="skills1". tyia!

2
  • I googled "send form data using ajax" and found: stackoverflow.com/questions/21662836/send-form-data-using-ajax Commented Jul 5, 2018 at 14:47
  • @KIKOSoftware i checked it, but my problem is i have 4 divs that have multiple created input fields, i'm having problem on how to send it on ajax and fetch it on php. Thanks for answering!! :)) Commented Jul 5, 2018 at 14:51

1 Answer 1

0

If you give the skill inputs a class like so

<input type="text" class="form-control skill-input" placeholder="Knowledgeable/Proficient in..">

You can then create an object from your form in javascript (example using jquery)

var skills = [];
$(".skill-input").each(function() {
    skills.push($(this).val());
});
console.log(skills); //final array of skills

var resume = JSON.stringify({
    firstName: $('[name=firstName]').val(),
    lastname: $('[name=lastName]').val(),
    skills: skills
});

$.ajax({
    dataType: 'json',
    url: './submit.php',
    type: 'POST',
    data: {resume:resume}
});

then on your submit.php you can have

$form = json_decode($_POST['resume'], true);
echo $form['skills'];
Sign up to request clarification or add additional context in comments.

5 Comments

how will i send those values with the other values from my form to my php page via ajax? thasnk you sir :))
updated my post. Just got to my computer, so I will test the code.
@Prozky im sorry for the late reply, on $form = json_decode($_POST['resume']); how can i get the value seperately? was it still like $_POST['firstName']; ? and how to get the value of the array skills? thank you so much!! this helps a lot :))
Hi @jes, I edited the bottom of my answer. See if that works for you.
thank you so much! will tell you if it worked! sorry for i am busy with finishing this project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.