我正在使用此引用中的克隆形式 http://tristandenyer.com/using-jquery-to-duplicate-a-section-of-a-form-maintaining-accessibility/。 我试图从克隆的表格进入mysql。对不起,我是新手。我在下面粘贴我的代码。我确信我的错误是从php访问多维数组。在我的PHP代码中,我现在只是想将数据打印到屏幕上。它给出了我充足的错误消息。 这是我的HTML代码:
<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 your 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 is 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 Institution / 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>
这是我的PHP代码:
if(isset($_POST['form'])){
echo "reaching the 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;
}
}
这是我的javascript代码:
$(function () {
$('#btnAdd').click(function () {
var num = $('.clonedInput').length, // Checks to see how many "duplicatable" input fields we currently have
newNum = new Number(num + 1), // The numeric ID of the new input field being added, increasing by 1 each time
newElem = $('#entry' + num).clone().attr('id', 'entry' + newNum).fadeIn('slow'); // create the new element via clone(), and manipulate it's ID using newNum value
/* This is where we manipulate the name/id values of the input inside the new, cloned element
Below are examples of what forms elements you can clone, but not the only ones.
There are 2 basic structures below: one for an H2, and one for form elements.
To make more, you can copy the one for form elements and simply update the classes for its label and input.
Keep in mind that the .val() method is what clears the element when it gets cloned. Radio and 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('');
// Last 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 and 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 and text
newElem.find('.label_twt').attr('for', 'ID' + newNum);
newElem.find('.input_twt').attr('id', 'ID' + newNum).attr('name', 'ID' + newNum).val('');
// Insert the new element after the last "duplicatable" input field
$('#entry' + num).after(newElem);
$('#ID' + newNum + '_title').focus();
// Enable the "remove" button. This only shows once you have a duplicated section.
$('#btnDel').attr('disabled', false);
// Right now you can only add 4 sections, for a total of 5. Change '5' below to the max number of sections you want to allow.
if (newNum == 5)
$('#btnAdd').attr('disabled', true).prop('value', "You've reached the limit"); // value here updates the text in the 'add' button when the limit is reached
});
$('#btnDel').click(function () {
// Confirmation dialog box. Works on all desktop browsers and iPhone.
if (confirm("Are you sure you wish to remove this section? This cannot be undone."))
{
var num = $('.clonedInput').length;
// how many "duplicatable" input fields we currently have
$('#entry' + num).slideUp('slow', function () {$(this).remove();
// if only one element remains, disable the "remove" button
if (num -1 === 1)
$('#btnDel').attr('disabled', true);
// enable the "add" button
$('#btnAdd').attr('disabled', false).prop('value', "add section");});
}
return false; // Removes the last section you added
});
// Enable the "add" button
$('#btnAdd').attr('disabled', false);
// Disable the "remove" button
$('#btnDel').attr('disabled', true);
});
答案 0 :(得分:0)
我现在不在我的电脑上,但是通过查看你的代码你真的开始表单吗?
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
如果没有,那么这可能是造成问题的原因。