Jump to content

associate hidden field with check box


searls03

Recommended Posts

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........

Link to comment
Share on other sites

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 = "";
}
?>

 

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.