gpt4 book ai didi

php - 使用PHP的动态输入字段的错误消息

转载 作者:行者123 更新时间:2023-12-03 08:47:01 26 4
gpt4 key购买 nike

我创建了动态添加/删除输入字段。我想通过某些验证。如果用户将其保留为空白,则在提交表单后应显示一条消息。我希望显示PHP验证。

<div class="panel panel-default">
<div class="panel-heading"><center><b>Allocation of Funds</b></center></div>
<div class="panel-body">
<div class="row">
<div class="col-md-5"><label>Allocation Items <b style="color:#FF0000;">*</b></label></div>
<div class="col-md-5"><label>Amount <b style="color:#FF0000;">*</b></label></div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-5">
<div class="form-group">
<input type="text" class="form-control" name="allocate_items[]" placeholder=""></div>
</div>
<div class="col-md-5">
<div class="form-group">
<input type="text" class="form-control" name="allocate_amount[]" placeholder=""></div>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-success" id="add-allocation-fields"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add</button>
</div>
</div>
<div id="fund-allocation-fields"></div>

<p class="help-block"><i>Total amount must be equal to the goal amount.</i></p>
</div>
</div>

<script type="text/javascript">
var i = 0;

jQuery(document).ready(function($) {
//fadeout selected item and remove
$(document).on('click', '#remove-allocation-fields', function(event) {
event.preventDefault();
$(this).parent().fadeOut(300, function() {
$(this).parent().empty();
return false;
});
});

var rows = '<div class="fund-fields"><div class="row"><div class="col-md-5"><div class="form-group"><input type="text" class="form-control" name="allocate_items[]" placeholder=""></div></div><div class="col-md-5"><div class="form-group"><input type="text" class="form-control" name="allocate_amount[]" placeholder=""></div></div><div class="col-md-2"><button type="button" class="btn btn-danger" id="remove-allocation-fields"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Remove</button></div></div><div class="clear"></div></div>';

//add input
$('#add-allocation-fields').click(function() {
$(rows).fadeIn("slow").appendTo('#fund-allocation-fields');
i++;
return false;
});
});
</script>

提前致谢!

最佳答案

将一个输入值存储在 session 变量或全局 session 中,并使用条件语句将其与所需输入值进行比较。就这么简单。

喜欢,

if(isset($_SESSION['A']) && empty(trim($_POST['RequiredField']))){
echo 'required field can\'t be empty';
}

关于php - 使用PHP的动态输入字段的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51481370/

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