Tuesday, 15 February 2011

javascript - Unable to input data in to mysql from cloned forms? -



javascript - Unable to input data in to mysql from cloned forms? -

i using cloned form reference http://tristandenyer.com/using-jquery-to-duplicate-a-section-of-a-form-maintaining-accessibility/ . trying come in cloned forms in mysql. sorry newbie. pasting code below. kind of sure error in accessing multidimensional array php. in php code right trying print info screen. gives ample error messages. html code:

<form action="<?php $_server['php_self']?>" method="post" id="sign-up_area" role="form"> <label class="label_ttl control-label" for="title">title:</label> <div class="form-group"> <select class="select_ttl form-control" name="form[0][0]" id="title"> <option value="" selected="selected" disabled="disabled">select title</option> <option value="dr.">dr.</option> <option value="mr.">mr.</option> <option value="mrs.">mrs.</option> <option value="ms.">ms.</option> <option value="sir">sir</option> </select> </div> <!-- text input--> <div class="form-group"> <label class="label_fn control-label" for="first_name">first name:</label> <input id="first_name" name="form[0][1]" type="text" placeholder="" class="input_fn form-control" required> <p class="help-block">this field required.</p> </div> <!-- text input--> <div class="form-group"> <label class="label_ln control-label" for="last_name">last name:</label> <input id="last_name" name="form[0][2]" type="text" placeholder="" class="input_ln form-control"> </div> <div class="form-group"> <label class="label_email control-label" for="email_address">email:</label> <input id="email_address" name="form[0][3]" type="text" placeholder="example@example.com" class="input_email form-control"> </div> <!-- prepended text--> <label class="label_twt control-label" for="institution">enter establishment / organization:</label> <div class="input-group form-group"> <input id="twitter_handle" name="form[0][4]" class="input_twt form-control" placeholder="" type="text"> </div> <!-- text input--> </div><!-- end #entry1 --> <!-- button (double) --> <p> <button type="button" id="btnadd" name="btnadd" class="btn btn-info">add section</button> <button type="button" id="btndel" name="btndel" class="btn btn-danger">remove section above</button> </p> <!-- button --> <p> <button id="submit_button" name="submit_button" class="btn btn-primary">submit</button> </p> </fieldset> </form>

this php code:

if(isset($_post['form'])){ echo "reaching else"; $food=$_post['form']; for($i=0; $i<4; $i++){ for($j=0; $j<3; $j++){ $car=array($food[$i][$j]=>array($food[$i][$j])); //echo $car; } }

this javascript code:

$(function () { $('#btnadd').click(function () { var num = $('.clonedinput').length, // checks see how many "duplicatable" input fields have newnum = new number(num + 1), // numeric id of new input field beingness added, increasing 1 each time newelem = $('#entry' + num).clone().attr('id', 'entry' + newnum).fadein('slow'); // create new element via clone(), , manipulate it's id using newnum value /* manipulate name/id values of input within new, cloned element below examples of forms elements can clone, not ones. there 2 basic structures below: 1 h2, , 1 form elements. create more, can re-create 1 form elements , update classes label , input. maintain in mind .val() method clears element when gets cloned. radio , checkboxes need .val([]) instead of .val(''). */ // h2 - section newelem.find('.heading-reference').attr('id', 'id' + newnum + '_reference').attr('name', 'id' + newnum + '_reference').html('co-pi #' + newnum); // title - select newelem.find('.label_ttl').attr('for', 'id' + newnum); newelem.find('.select_ttl').attr('id', 'id' + newnum).attr('name', 'id' + newnum).val(''); // first name - text newelem.find('.label_fn').attr('for', 'id' + newnum); newelem.find('.input_fn').attr('id', 'id' + newnum).attr('name', 'id' + newnum).val(''); // lastly name - text newelem.find('.label_ln').attr('for', 'id' + newnum); newelem.find('.input_ln').attr('id', 'id' + newnum).attr('name', 'id' + newnum).val(''); // skate - radio , upload file // newelem.find('.label_vitae').attr('for', 'id' + newnum + '_uploadfile'); // newelem.find('.btn-primary').attr('id', 'id' + newnum + '_uploadfile').attr('name', 'id' + newnum + '_uploadfile').val([]); // email - text newelem.find('.label_email').attr('for', 'id' + newnum); newelem.find('.input_email').attr('id', 'id' + newnum).attr('name', 'id' + newnum).val(''); // twitter handle (for bootstrap demo) - append , text newelem.find('.label_twt').attr('for', 'id' + newnum); newelem.find('.input_twt').attr('id', 'id' + newnum).attr('name', 'id' + newnum).val(''); // insert new element after lastly "duplicatable" input field $('#entry' + num).after(newelem); $('#id' + newnum + '_title').focus(); // enable "remove" button. shows 1 time have duplicated section. $('#btndel').attr('disabled', false); // right can add together 4 sections, total of 5. alter '5' below max number of sections want allow. if (newnum == 5) $('#btnadd').attr('disabled', true).prop('value', "you've reached limit"); // value here updates text in 'add' button when limit reached }); $('#btndel').click(function () { // confirmation dialog box. works on desktop browsers , iphone. if (confirm("are sure wish remove section? cannot undone.")) { var num = $('.clonedinput').length; // how many "duplicatable" input fields have $('#entry' + num).slideup('slow', function () {$(this).remove(); // if 1 element remains, disable "remove" button if (num -1 === 1) $('#btndel').attr('disabled', true); // enable "add" button $('#btnadd').attr('disabled', false).prop('value', "add section");}); } homecoming false; // removes lastly section added }); // enable "add" button $('#btnadd').attr('disabled', false); // disable "remove" button $('#btndel').attr('disabled', true); });

i'm not on computer right now, looking on code ever start form?

<form action="<?php echo $_server['php_self']; ?>" method="post">

if not, may causing problem.

javascript php jquery mysql

No comments:

Post a Comment