我需要在php中的表单之外发布值,如何做到
这是我的示例代码
<input type="hidden" id="test" name="test" />
<input type="hidden" id="testvalue" name="testvalue"/>
<?Php for($i=0;$i<5;$i++) { ?>
<form action='some_url'>
<input type="text" value="dynamic_value" name='testname'>
<select name="testselect">
<option value="<?php echo $dynamicvalue[$i]?>"><?php echo $dynamicvalue[$i]?></option>
</select>
<button class="btn btn-primary book_now" type="submit">BookNow</button>
</form>
<?php } ?>
我还需要在表单上方发布所有输入值,因为我不能在循环中使用该输入字段,我希望id是唯一的,所以我不能在里面使用
可用于发布所有数据的任何其他选项
答案 0 :(得分:0)
使用jQuery:
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
$(document).ready(function(){
$('form').submit(function(){
var test = $('#test').val();
var testvalue = $('#testvalue').val();
$(this).append('<input type="hidden" name="test" value="'+test+'">');
$(this).append('<input type="hidden" name="testvalue" value="'+testvalue+'">');
return true
});
});
</script>
答案 1 :(得分:0)
您可以将输入字段添加到for-loop
<?php for($i=0;$i<5;$i++) { ?>
<form action='some_url'>
<input type="text" value="dynamic_value" name='testname'>
<select name="testselect">
<option value="<?php echo $dynamicvalue[$i]?>"><?php echo $dynamicvalue[$i]?></option>
</select>
<button class="btn btn-primary book_now" type="submit">BookNow</button>
<input type="hidden" name="test" />
<input type="hidden" name="testvalue"/>
</form>
<?php } ?>