gpt4 book ai didi

javascript - 无法从克隆表单将数据输入到 mysql?

转载 作者:行者123 更新时间:2023-11-30 00:07:44 24 4
gpt4 key购买 nike

我正在使用此引用中的克隆表单 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);
});

最佳答案

我现在不在计算机上,但是通过查看您的代码,您是否真正启动表单?

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

如果不是,则这可能是导致问题的原因。

关于javascript - 无法从克隆表单将数据输入到 mysql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24373632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com