searls03 Posted April 16, 2011 Share Posted April 16, 2011 so I have this code: <input type='checkbox' name='title8' value='$title8' /></td><td><strong>$title8</strong> <br /> $date8 <br />$ $price8<input type='hidden' name='price8' value='$price8'> how do I make is so that the hidden field is only going to submit if the checkbox is checked........ Quote Link to comment https://forums.phpfreaks.com/topic/233909-associate-hidden-field-with-check-box/ Share on other sites More sharing options...
Skewled Posted April 16, 2011 Share Posted April 16, 2011 so I have this code: <input type='checkbox' name='title8' value='$title8' /></td><td><strong>$title8</strong> <br /> $date8 <br />$ $price8<input type='hidden' name='price8' value='$price8'> how do I make is so that the hidden field is only going to submit if the checkbox is checked........ <?php if (isset($_POST['title8'])) { $price = $_POST['price8']; } else { $price = ""; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233909-associate-hidden-field-with-check-box/#findComment-1202359 Share on other sites More sharing options...
searls03 Posted April 16, 2011 Author Share Posted April 16, 2011 so should I put that with this code or in the processing piece of the code? and if it is with this, can you help get me started? if (isset($_POST['eventid'])){ $name = ereg_replace("[^A-Z a-z0-9]", "", $_POST['name']); // filter everything but numbers and letters $event = ereg_replace("[^A-Z a-z0-9]", "", $_POST['event']); // filter everything but spaces, numbers, and letters $eventid = ereg_replace("[^A-Z a-z0-9]", "", $_POST['eventid']); // filter everything but spaces, numbers, and letters $userid = ereg_replace("[^A-Z a-z0-9]", "", $_POST['userid']); $title1 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['title1']); // filter everything but spaces, numbers, and letters $title2 = ereg_replace("[^A-Za-z0-9]", "", $_POST['title2']); // filter everything but lowercase letters $title3 = ereg_replace("[^A-Za-z0-9]", "", $_POST['title3']); // filter everything but lowercase letters $title4 = ereg_replace("[^A-Za-z0-9]", "", $_POST['title4']); // filter everything but lowercase letters $title5 = ereg_replace("[^A-Za-z0-9]", "", $_POST['title5']); // filter everything but lowercase letters $title6 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['title6']); // filter everything but $title7 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['title7']); // filter everything but $title8 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['title8']); // filter everything but $email = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['email']); // filter everything but $price1 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price1']); // filter everything but $price2 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price2']); // filter everything but $price3 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price3']); // filter everything but $price4 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price4']); // filter everything but $price5 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price5']); // filter everything but $price6 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price6']); // filter everything but $price7 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price7']); // filter everything but $price8 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price8']); // filter everything but $id = ereg_replace("[^A-Z a-z0-9.@,]", "", $_POST['id']); // filter everything but $sql = "REPLACE INTO Events (name, event, eventid, userid, title1, title2, title3, title4, title5, title6, title7, title8, email, id, price1, price2, price3, price4, price5, price6, price7, price8) VALUES('$name','$event','$eventid','$userid','$title1','$title2','$title3','$title4','$title5','$title6','$title7','$title8','$email','$id','$price1', '$price2', '$price3','$price4','$price5','$price6','$price7','$price8')"; $rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/233909-associate-hidden-field-with-check-box/#findComment-1202361 Share on other sites More sharing options...
Skewled Posted April 16, 2011 Share Posted April 16, 2011 That would be used in the processing code that deals with the associated form, it seems like the code you posted deals with the form submission so yes it would go in that code. <?php if (isset($_POST['eventid'])){ if (isset($_POST['title8'])) { $price8 = ereg_replace("[^A-Z a-z0-9.@]", "", $_POST['price8']); // filter everything but } else { $price8 = ""; // What value do you want it to hold if the box is unchecked? As it stands it holds nothing. } // All your other post data here except $price8 } ?> You could place this after your first if statement, drop the $price8 variable from your orig code. Quote Link to comment https://forums.phpfreaks.com/topic/233909-associate-hidden-field-with-check-box/#findComment-1202366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.