表单如果然后否则/ ifElse提交HTML [英] Form if then Else/ifElse HTML on submit
问题描述
我有一个表格,我需要以特定的方式行事。例如:用户带回设备:我不希望那样出现在我的表单中。用户拿出设备:我想让它生成我的表单,他们输入一些信息,表单发送信息到数据库。用户取出设备:它也生成所述表单,他不输入任何信息,表单在20秒后提交信息,信息在数据库中。
我正在做一个简单的页面刷新,以便将信息转化为我的表格,但是那一天是将所有带入仓库的设备都拿走了。所以我评论说,然后我会卡在我的ajax页面上。
然后,我尝试创建一个新的页面,其中有一个301页面刷新,并努力使页面回到我的索引页面,但是,我的表单不工作正确,所以我评论了自动提交,现在我的表单工作很好......除非我不能满足这个最后的要求,如果用户忘记将他的设备信息放入,页面将提交数据。我正在寻找做if / then / else类型的页面提交。但是,我无法弄清楚如何在php或html中纯粹做一个。这是我到目前为止所了解到的,但它不起作用,我知道我在某个地方离开了。
< ;!DOCTYPE html>
< html>
< body>
<! - 这是当前在我的代码中注释掉的那个
< script type =text / javascript>
window.setTimeout(function(){
window.location ='index.php'},1000 * 2);
< / script>
< / body>
< / html> - >
//这是我的梦想
<?php
if(isset($ _ POST ['action'])){
switch($ _POST [ 'action']){
case'DONE':
document.getElement('formSubmit')。submit();
休息;
}
} else {
< script type =text / javascript>
window.setTimeout(function(){
document.getElement('formSubmit')。submit();
},1000 * 30);
< / script>
}
?>
我对jQuery的了解不多,除了经历一个codecademy之外,我知道的更少JavaScript的。我是一个数据库人员,通过连接来构建高级表单/网页。所以我正在学习PHP,CSS,jQuery和HTML。
Index.php:
<!DOCTYPE html>
< html>
< head>
< meta name =Warehouse 3962content =width = device-width,initial-scale = 1.0>
< link href =style.csstype =text / css =stylesheet>
< script type =text / javascript>
<! - window.setTimeout(function(){
document.getElement('formSubmit')。submit();
},1000 * 30); - >
< / script>
< / head>
< body>
< section class =w>
< div class =row>
< div class =小列>
< img src =logo.png/>
< h3 class =green>使用者< / h3>
< / div>
< h6>仓库3962< / h6>
< / div>
< div class =row>
< div class =小列>
< form action =ajax.phpmethod =postid =formSubmit>
< table id =equipment-table>
< thead>
< tr>
< th>设备< / th>
< th>金额< / th>
th Val1< th>
th Val2< th>
< / tr>
< / thead>
< tbody>
<?php foreach
($ results ['tags'] as $ equipment){
if($ equipment ['category'] ==Part){?>
< tr>
< td><?= $ equipment ['Amount']; ?>< / TD>
< td class =text-center><?= $ equipment ['quantity']; ?>< / TD>
< td>< input type =textname =val1/>< / td>
< td>< input type =textname =val2/>< / td>
< / tr>
<?php} // end if
} // end foreach?>
< tr>
< td colspan =4style =text-align:right;>< input type =submitclass =buttonname =DONEvalue =DONE/> < / TD>
< / tr>
< / tbody>
< / table>
< / form>
< / div>
< / div>
< / section>
< / body>
< / html>
请尝试这个新解决方案。这会每隔30秒发送一个帖子,其中只包含包含文本的输入框。
<!DOCTYPE html>
< html>
< head>
< meta name =Warehouse 3962content =width = device-width,initial-scale = 1.0>
< link href =style.csstype =text / css =stylesheet>
< / head>
< body>
< section class =w>
< div class =row>
< div class =小列>
< img src =logo.png/>
< h3 class =green>使用者< / h3>
< / div>
< h6>仓库3962< / h6>
< / div>
< div class =row>
< div class =小列>
< form action =ajax.phpmethod =postid =formSubmit>
< table id =equipment-table>
< thead>
< tr>
< th>设备< / th>
< th>金额< / th>
th Val1< th>
th Val2< th>
< / tr>
< / thead>
< tbody>
<?php
foreach($ results ['tags'] as $ equipment):
if($ equipment ['category'] ===Part):
>
< tr>
< td>
<?php echo $ equipment ['Amount']; ?>
< / td>
< td class =text-center>
<?php echo $ equipment ['quantity']; ?>
< / td>
< td>
< input id =<?php echo $ equipment ['number'];?> -val1type =textname =<?php echo $ equipment ['number']; ?> -val1\" />
< / td>
< td>
< input id =<?php echo $ equipment ['number'];?> -val2type =textname =<?php echo $ equipment ['number']; ?> -val2\" />
< / td>
< / tr>
<?php
endif;
endforeach;
?>
< tr>
< td colspan =4style =text-align:right;>
< input type =submitclass =buttonname =DONEvalue =DONE/>
< / td>
< / tr>
< / tbody>
< / table>
< / form>
< / div>
< / div>
< / section>
< script type =text / javascript>
函数sendData(){
var inputs = document.getElementById('equipment-table')。getElementsByTagName('input'),
data = [],
name,val1 ,val2;
for(var i = 0; i< inputs.length; i ++){
if(inputs [i] .type ==='submit'){
continue ;
}
if(inputs [i] .value){
name = inputs [i] .name.split(' - val');
val1 = inputs [i] .name.split('val1'); (val1.length> 1){
data.push({name:name [0],val1:inputs [i] .value});
}
else {
data.push({name:name [0],val2:inputs [i] .value});
$ b window.setTimeout(function(){
sendData();
},30000);
}
sendData();
< / script>
< / body>
< / html>
I have a form that I need to act in specific ways. Example: User brings equipment back: I don't want that to show up in my form. User takes equipment out: I want it to generate to my form, they enters some information, form sends information to database. User takes equipment out: it too generates said form, he doesn't enter any information, form submits information after 20 sec, information is in database.
I was doing a simple page refresh to get the information into my form but that was pulling all the equipment that had been brought into the warehouse that day. So I commented that out and then I would get stuck on my ajax page.
I then tried creating a new php page that had a 301 page refresh and that worked to get the page back to my index page, however, my form wasn't working properly and so I commented out the auto submit and now my form works great... except I can't fulfill this last requirement where the page will submit the data if the user forgets to put his equipment information in.
I'm looking to do an if/then/else type of page submission. However, I can't figure out how to do one purely in either php or html. This is what I have figured out so far but it doesn't work and I know I'm way off somewhere.
<!DOCTYPE html>
<html>
<body>
<!--This is the one that is currently commented out in my code
<script type="text/javascript">
window.setTimeout(function() {
window.location = 'index.php'},1000*2);
</script>
</body>
</html> -->
//This is my pipe dream
<?php
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case ‘DONE’:
document.getElement('formSubmit').submit();
break;
}
} else {
<script type="text/javascript">
window.setTimeout(function(){
document.getElement('formSubmit').submit();
},1000*30);
</script>
}
?>
I don't know that much about jQuery other than going through a codecademy, and I know even less javascript. I'm a database person that got "conned" into building an advanced form/webpage. So I'm learning PHP, CSS, jQuery and HTML as I code.
Index.php:
<!DOCTYPE html>
<html>
<head>
<meta name="Warehouse 3962" content="width=device-width, initial-scale=1.0">
<link href="style.css" type="text/css" rel="stylesheet">
<script type="text/javascript">
<!—window.setTimeout(function(){
document.getElement(‘formSubmit').submit();
},1000*30); —>
</script>
</head>
<body>
<section class="w">
<div class="row">
<div class="small columns">
<img src="logo.png" />
<h3 class="green">Users</h3>
</div>
<h6>Warehouse 3962</h6>
</div>
<div class="row">
<div class="small columns">
<form action="ajax.php" method="post" id="formSubmit">
<table id="equipment-table">
<thead>
<tr>
<th>Equipment</th>
<th>Amount</th>
<th>Val1</th>
<th>Val2</th>
</tr>
</thead>
<tbody>
<?php foreach
($results['tags'] as $equipment) {
if ($equipment['category'] == "Part") { ?>
<tr>
<td><?= $equipment['Amount']; ?></td>
<td class="text-center"><?= $equipment[‘quantity']; ?></td>
<td><input type="text" name="val1" /></td>
<td><input type="text" name="val2" /></td>
</tr>
<?php } // end if
} // end foreach ?>
<tr>
<td colspan="4" style="text-align: right;"><input type="submit" class="button" name="DONE" value="DONE" /></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</section>
</body>
</html>
Please try this new solution. This will send a post every 30 seconds containing only the input boxes containing text on them.
<!DOCTYPE html>
<html>
<head>
<meta name="Warehouse 3962" content="width=device-width, initial-scale=1.0">
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<section class="w">
<div class="row">
<div class="small columns">
<img src="logo.png" />
<h3 class="green">Users</h3>
</div>
<h6>Warehouse 3962</h6>
</div>
<div class="row">
<div class="small columns">
<form action="ajax.php" method="post" id="formSubmit">
<table id="equipment-table">
<thead>
<tr>
<th>Equipment</th>
<th>Amount</th>
<th>Val1</th>
<th>Val2</th>
</tr>
</thead>
<tbody>
<?php
foreach ($results['tags'] as $equipment) :
if ($equipment['category'] === "Part") :
?>
<tr>
<td>
<?php echo $equipment['Amount']; ?>
</td>
<td class="text-center">
<?php echo $equipment['quantity']; ?>
</td>
<td>
<input id="<?php echo $equipment['number'];?>-val1" type="text" name="<?php echo $equipment['number'];?>-val1"/>
</td>
<td>
<input id="<?php echo $equipment['number'];?>-val2" type="text" name="<?php echo $equipment['number'];?>-val2"/>
</td>
</tr>
<?php
endif;
endforeach;
?>
<tr>
<td colspan="4" style="text-align: right;">
<input type="submit" class="button" name="DONE" value="DONE" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</section>
<script type="text/javascript">
function sendData() {
var inputs = document.getElementById('equipment-table').getElementsByTagName('input'),
data = [],
name, val1, val2;
for (var i = 0; i < inputs.length; i++) {
if ( inputs[i].type === 'submit') {
continue;
}
if ( inputs[i].value ) {
name = inputs[i].name.split('-val');
val1 = inputs[i].name.split('val1');
if (val1.length > 1) {
data.push({name: name[0], val1: inputs[i].value});
}
else {
data.push({name: name[0], val2: inputs[i].value});
}
}
}
window.setTimeout(function() {
sendData();
},30000);
}
sendData();
</script>
</body>
</html>
这篇关于表单如果然后否则/ ifElse提交HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!