php - i want to display all checkboxes value which are checked -
i want display checked checkboxes in php.
<script> function requestobject () { var returnvalue = null; try { returnvalue = new activexobject("microsoft.xmlhttp"); } catch (error) { try { returnvalue = new activexobject("msxml2.http"); } catch (error) { try { returnvalue = new xmlhttprequest(); } catch (error) { // failed return null; } } } return returnvalue; } var requestobj = null; function coajax(sender) { requestobj = requestobject(); if (requestobj) { sender.enabled = false; // user cannot change till request finished requestobj.open('get', '<?php echo get_template_directory_uri(); ?>/lunch_dinner.php?lid=' + sender.value, true); requestobj.onreadystatechange = coajax_finish; requestobj.send(null); } } function coajax_finish() { if (requestobj.readystate == 4) { document.getelementbyid('ldb_target').innerhtml = requestobj.responsetext; document.getelementbyid('ldb').enabled = true; } } function getdays(select){ var selectedstring = select.options[select.selectedindex].value; if(selectedstring == "bespoke days"){ document.getelementbyid("days_target").style.display = "block"; } else { document.getelementbyid("days_target").style.display = "none"; } } function validateform() { var x=document.forms["form1"]["contract"].value; if (x==null || x=="" || x=="select contract") { alert("oh, forgot select contract type! :)"); return false; } var x=document.forms["form1"]["days"].selectedindex; if (x<1) { alert("please select days"); return false; } else if(x==4) { // fifth entry var checked = false, chk = document.forms["form1"]["day"]; (var = 0; < chk.length; i++) { if (chk[i].checked) { checked=true; break } } if (!checked) { alert("at least 1 day should checked."); return false; } } var x=document.forms["form1"]["ldb"].value; if (x==null || x=="" || x=="select") { alert("oh, forgot select lunch-dinner! :)"); return false; } var x=document.forms["form1"]["ldb"].value; if(x=="lunch" || x=="both") { var y=document.forms["form1"]["lunch"].value; if(y=="lunch") { alert("oh, forgot select lunch time! :)"); return false; } } var x=document.forms["form1"]["ldb"].value; if(x=="dinner" || x=="both") { var y=document.forms["form1"]["dinner"].value; if(y=="dinner") { alert("oh, forgot select dinner time! :)"); return false; } } var x=document.forms["form1"]["phone"].value; if (x==null || x=="") { alert("oh, forgot enter phone number! :)"); return false; } var x = document.form1.phone.value; if(isnan(x)||x.indexof(" ")!=-1) { alert("please enter numaric value in contact number.") return false; } var x=document.forms["form1"]["meal"].value; if (x==null || x=="" || x=="select meal") { alert("oh, forgot select meal preference! :)"); return false; } var x=document.forms["form1"]["fnm"].value; if (x==null || x=="") { alert("oh, forgot enter full name! :)"); return false; } var x=document.forms["form1"]["pcod"].value; if (x==null || x=="") { alert("oh, forgot enter postal code! :)"); return false; } var x=document.forms["form1"]["email"].value; if (x==null || x=="") { alert("oh, forgot enter email address! :)"); return false; } var x=document.forms["form1"]["email"].value; var atpos=x.indexof("@"); var dotpos=x.lastindexof("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("excuse me! valid email address please!"); return false; } var x=document.forms["form1"]["add"].value; if (x==null || x=="") { alert("oh, forgot enter address! :)"); return false; } var x=document.forms["form1"]["rate"].value; if (x==null || x=="") { alert("oh, forgot enter rate! :)"); return false; } var x=document.forms["form1"]["rate"].value; if(isnan(x)||x.indexof(" ")!=-1) { alert("please enter numaric value in rate.") return false; } var x=document.forms["form1"]["amount"].value; if (x==null || x=="") { alert("oh, forgot enter amount! :)"); return false; } var x=document.forms["form1"]["amount"].value; if(isnan(x)||x.indexof(" ")!=-1) { alert("please enter numaric value in total amount.") return false; } } function calculatetotal(rate) { var rate=(document.forms["form1"]["rate"].value) * 1.03; document.forms["form1"]["amount"].value = rate; } </script>
html:
<form method="post" action="" name="form1" onsubmit="return validateform();"> <table class="order-paypal" width="100%"> <tr> <td><span>choose contract</span></td> <td> <select name="contract"> <option value="select contract" selected>select contract</option> <option value="7 meal veg contract">7 meal veg contract</option> <option value="7 meal nonveg contract">7 meal nonveg contract</option> <option value="7 meal nonveg contract">7 meal nonveg contract</option> <option value="8 meal veg contract">8 meal veg contract</option> <option value="8 meal nonveg contract">8 meal nonveg contract</option> <option value="8 meal mix contract">8 meal mix contract</option> <option value="9 meal veg contract">9 meal veg contract</option> <option value="9 meal nonveg contract ">9 meal nonveg contract </option> <option value="9 meal mix contract ">9 meal mix contract </option> <option value="30 meal veg contract">30 meal veg contract</option> <option value="30 meal nonveg contract">30 meal nonveg contract</option> <option value="30 meal mix contract">30 meal mix contract</option> <option value="book-a-cook service">book-a-cook service</option> <option value="extra roti/rice/dal/vegetable">extra roti/rice/dal/vegetable</option> </select> </td> </tr> <tr> <td><span>please enter days required</span></td> <td> <select name="days" id="days" onchange="getdays(this)"> <option value="select days" selected>select days</option> <option value="mon-fri">mon-fri</option> <option value="mon-sat">mon-sat</option> <option value="mon-sun">mon-sun</option> <option value="bespoke days">bespoke days</option> </select> <ul id="days_target" style="display:none;"> <span>select days</span> <li><input type="checkbox" name="day[]" value="mon"/>monday</li> <li><input type="checkbox" name="day[]" value="tue"/>tueday</li> <li><input type="checkbox" name="day[]" value="wed"/>wednesday</li> <li><input type="checkbox" name="day[]" value="thr"/>thursday</li> <li><input type="checkbox" name="day[]" value="fri"/>friday</li> <li><input type="checkbox" name="day[]" value="sat"/>saturday</li> <li><input type="checkbox" name="day[]" value="sun"/>sunday</li> </ul> </td> </tr> <tr> <td><span>please mention lunch or dinner or both</span></td> <td> <select name="ldb" id="ldb" onchange="coajax(this);" > <option value="select" selected>select</option> <option value="lunch">lunch</option> <option value="dinner">dinner</option> <option value="both">both</option> </select> <span id="ldb_target"></span><br/> </td> </tr> <tr> <td><span>please mention contact number</span></td> <td><input type="text" name="phone" /></td> </tr> <tr> <td><span>please mention meal preference</span></td> <td> <select name="meal" > <option value="select meal" selected>select meal</option> <option value="punjabi">punjabi</option> <option value="gujarati">gujarati</option> </select> </td> </tr> <tr> <td style="vertical-align:top;"><span>please mention dietary requirements</span></td> <td><input type="text" name="req" ></td> </tr> <tr> <td><span>full name</span></td> <td><input type="text" name="fnm" ></td> </tr> <tr> <td><span>address</span></td> <td><textarea name="add" ></textarea></td> </tr> <tr> <td><span>postal code</span></td> <td><input type="text" name="pcod" ></td> </tr> <tr> <td><span>email</span></td> <td><input type="text" name="email" ></td> </tr> <tr> <td><span>enter amount pay</span></td> <td> <input type="text" name="rate" > <br /> (<a target="_blank" href="http://www.infozzle.com/yatin/tifffin_planet/prices-and-offers-2/">check rate of item , zone</a>) <br/> card charge: 3% of total amount </td> </tr> <tr> <td><span>total amount</span></td> <td><input type="text" name="amount" value="click here see total amount" onclick="calculatetotal(this);"></td> </tr> <tr> <td> </td> <td> <table class="submit"> <tr> <td><input type="submit" value="submit" name="submitbtn" class="submit-payment"/></td> <td><input type="reset" value="reset" class="submit-reset"/></td> </tr> </table> </td> </tr> </table> </form>
i want display checked checkboxes of "day" on action page code:
<?php foreach($day $k) { echo $k.","; } ?>
html form , action page in template page of wordpress. doesn't work.how do?i have written code.
this might you:
<form name="search_field" id="search_field" action="formpage.php" method="post" > <ul> <li><input type="checkbox" name="day[]" value="mon"/>monday</li> <li><input type="checkbox" name="day[]" value="tue"/>tueday</li> <li><input type="checkbox" name="day[]" value="wed"/>wednesday</li> <li><input type="checkbox" name="day[]" value="thr"/>thursday</li> <li><input type="checkbox" name="day[]" value="fri"/>friday</li> <li><input type="checkbox" name="day[]" value="sat"/>saturday</li> <li><input type="checkbox" name="day[]" value="sun"/>sunday</li> </ul> <input type="submit" id="submit" name="submit" /> </form>
you can working result (for better understanding):
<form name="search_field" id="search_field" action="formpage.php" method="post" > <?php if(!$_post == ''){ ?> <ul> <li><input type="checkbox" <?php if(in_array("mon", $_post['day'])) {?> checked="checked"<?php } ?> name="day[]" value="mon"/>monday</li> <li><input type="checkbox" <?php if(in_array("tue", $_post['day'])) {?> checked="checked"<?php } ?> name="day[]" value="tue"/>tueday</li> <li><input type="checkbox" <?php if(in_array("wed", $_post['day'])) {?> checked="checked"<?php } ?> name="day[]" value="wed"/>wednesday</li> <li><input type="checkbox" <?php if(in_array("thr", $_post['day'])) {?> checked="checked"<?php } ?> name="day[]" value="thr"/>thursday</li> <li><input type="checkbox" <?php if(in_array("fri", $_post['day'])) {?> checked="checked"<?php } ?> name="day[]" value="fri"/>friday</li> <li><input type="checkbox" <?php if(in_array("sat", $_post['day'])) {?> checked="checked"<?php } ?> name="day[]" value="sat"/>saturday</li> <li><input type="checkbox" <?php if(in_array("sun", $_post['day'])) {?> checked="checked"<?php } ?> name="day[]" value="sun"/>sunday</li> </ul> <input type="submit" id="submit" name="submit" /> </form> <?php print_r($_post); ?> <?php } else { ?> <form name="search_field" id="search_field" action="formpage.php" method="post" > <ul> <li><input type="checkbox" name="day[]" value="mon"/>monday</li> <li><input type="checkbox" name="day[]" value="tue"/>tueday</li> <li><input type="checkbox" name="day[]" value="wed"/>wednesday</li> <li><input type="checkbox" name="day[]" value="thr"/>thursday</li> <li><input type="checkbox" name="day[]" value="fri"/>friday</li> <li><input type="checkbox" name="day[]" value="sat"/>saturday</li> <li><input type="checkbox" name="day[]" value="sun"/>sunday</li> </ul> <input type="submit" id="submit" name="submit" /> </form> <?php } ?>
just create formpage.php file, paste above code , check result.
Comments
Post a Comment