javascript - Dynamically added form elements are posted to PHP but cannot access them -
i'm posting dynamically added form elements php via ajax.
i can see serialised form data posted php, when try access data within it, of fields come null i.e. var_dump in php below shows null.
this jquery adds dynamic elements:
$(function(){ var count=0; $('#more_edu').click(function(){ count ++; $('#education_add').append('<br><br><label>university/institution: </label><input type="text" class="searchbox" id="edu_inst'+count+'" name="edu_inst[]" maxlength="200" value="">); event.preventdefault(); }); }); and jquery posting php:
function profilesub(){ var myform; event.preventdefault(); myform = $('form').serialize(); $.ajax({ type: 'post', url: 'tutorprofileinput.php', data: {"form": myform}, success:function(data, response, xhr){ console.log(response); console.log(data); console.log(xhr); }, error:function(){ // failed request; give feedback user $('#ajax-panel').html('<p class="error"><strong>oops!</strong> try again in few moments.</p>'); } }); } this original form:
<form id="tutor_profile_input" onsubmit="return false;"> <label>university/institution: </label> <input type="text" class="searchbox" id="edu_inst" name="edu_inst[]" maxlength="200" value=""> </br></br> <label>subject:</label> <input type="text" class="searchbox" id="edu_subj" name="edu_subject[]" maxlength="200" value=""></br></br> <label> level </label> <select id="edu_level" name="edu_level[]"> and php itself:
<?php if (isset($_post['form'])){ $form = $_post['form']; var_dump($_post["edu_inst"]);?> this var dump of whole $_post:
location=&price=&tutorname=&edu_inst%5b%5d=uni1&edu_subject%5b%5d=subje1&edu_level%5b%5d=ba&edu_inst%5b%5d=uni2&edu_subject%5b%5d=subj2&edu_level%5b%5d=ba&bio=%09&exper
the form you've posted has id of #tutor_profile_input, 1 you're appending in jquery function #education_add - unless i've misunderstood?
otherwise i'd @ specifying more specific target in ajax request - you're targetting $('form') @ moment form on page..
Comments
Post a Comment