php - Form if then Else/ifElse HTML on submit -
i have form need act in specific ways. example: user brings equipment back: don't want show in form. user takes equipment out: want generate form, enters information, form sends information database. user takes equipment out: generates said form, doesn't enter information, form submits information after 20 sec, information in database.
i doing simple page refresh information form pulling equipment had been brought warehouse day. commented out , stuck on ajax page.
i tried creating new php page had 301 page refresh , worked page index page, however, form wasn't working , commented out auto submit , form works great... except can't fulfill last requirement page submit data if user forgets put equipment information in.
i'm looking if/then/else type of page submission. however, can't figure out how 1 purely in either php or html. have figured out far doesn't work , know i'm way off somewhere.
<!doctype html> <html> <body> <!--this 1 commented out in code <script type="text/javascript"> window.settimeout(function() { window.location = 'index.php'},1000*2); </script> </body> </html> --> //this 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 jquery other going through codecademy, , know less javascript. i'm database person got "conned" building advanced form/webpage. i'm learning php, css, jquery , html 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'] $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 new solution. send post every 30 seconds containing 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'] $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; (var = 0; < 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>
Comments
Post a Comment