Jump to content

Checkbox Value Data


biwerw

Recommended Posts

I have a form setup with 9 check boxes. When the form is submitted I would like the values that have been checked to be displayed on the next page. I am running into the problem that when a check box isn't selected I receive an error on the next page.

 

Any help would be awesome. Thanks.

 

Here is the code for the form.

<form method="post" action="submit.php">	
  		<table width="432" border="0" cellspacing="0" cellpadding="0">
            <tr><td colspan="4"><img src="header-lol.jpg" alt="LAND O' LAKES Premium Deli Cheese | America's Favorite - Sliced Fresh" /></td></tr>
            <tr>
            	<td width="313" align="left"><p class="left"><label><input name="lol-wt-am" type="checkbox" value="LAND O LAKES® White American Cheese" />LAND O LAKES® White American Cheese</label></p></td>
            	<td colspan="3"><p class="right"><input name="v1" type="text" size="8" />per Lb.</p></td>
            </tr>
            <tr>
            	<td><p class="left"><label><input name="lol-ye-am" type="checkbox" value="LAND O LAKES® Yellow American Cheese" />LAND O LAKES® Yellow American Cheese</label></p></td>
           	  	<td colspan="3"><p class="right"><input name="v2" type="text" size="8" />per Lb.</p></td>
            </tr>
            <tr>
            	<td><p class="left"><label><input name="lol-2w-am" type="checkbox" value="LAND O LAKES® 2% Milk White American Cheese" />LAND O LAKES® 2% Milk White American Cheese</label></p></td>
           	  	<td colspan="3"><p class="right"><input name="v3" type="text" size="8" />per Lb.</p></td>
            </tr>
            <tr>
            	<td><p class="left"><label><input name="lol-2y-am" type="checkbox" value="LAND O LAKES® 2% Milk Yellow American Cheese" />LAND O LAKES® 2% Milk Yellow American Cheese</label></p></td>
           	  	<td colspan="3"><p class="right"><input name="v4" type="text" size="8" />per Lb.</p></td>
    		</tr>
            <tr>
            	<td><p class="left"><label><input name="lol-cmc" type="checkbox" value="LAND O LAKES® Creamy Muenster Cheese" />LAND O LAKES® Creamy Muenster Cheese</label></p></td>
           	  	<td colspan="3"><p class="right"><input name="v5" type="text" size="8" />per Lb.</p></td>
    		</tr>
            <tr>
            	<td colspan="4" align="right"><img src="header-al.jpg" alt="Alpine Lace: Better For You - Sliced Fresh" /></td>
       	  	</tr>
            <tr>
              <td colspan="3"><p class="left"><label><input name="al-rfsc" type="checkbox" value="Alpine Lace® Reduced Fat Swiss Cheese" />Alpine Lace® Reduced Fat Swiss Cheese</label></p></td>
              <td width="109"><p class="right"><input name="v6" type="text" size="8" />per Lb.</p></td>
            </tr>
            <tr>
              <td colspan="3"><p class="left"><label><input name="al-mc" type="checkbox" value="Alpine Lace® Muenster Cheese" />Alpine Lace® Muenster Cheese</label></p></td>
              <td><p class="right"><input name="v7" type="text" size="8" />per Lb.</p></td>
            </tr>
            <tr>
              <td colspan="3"><p class="left"><label><input name="al-ac" type="checkbox" value="Alpine Lace® American Cheese" />Alpine Lace® American Cheese</label></p></td>
              <td><p class="right"><input name="v8" type="text" size="8" />per Lb.</p></td>
            </tr>
            <tr>
              <td colspan="3"><p class="left"><label><input name="al-pc" type="checkbox" value="Alpine Lace® Provolone Cheese" />Alpine Lace® Provolone Cheese</label></p></td>
              <td><p class="right"><input name="v9" type="text" size="8" />per Lb.</p></td>
            </tr>
            <tr>
              <td colspan="4" align="center"><p><input type="submit" class="submit_button" value="Submit" tabindex="" /></p></td>
            </tr>
	</table>
</form>

 

And the code for the page it is pulled and displayed on:

<table width="432" border="0" cellspacing="0" cellpadding="0">
            <tr><td colspan="4"><img src="header-lol.jpg" alt="LAND O' LAKES Premium Deli Cheese | America's Favorite - Sliced Fresh" /></td></tr>
            <tr>
            	<td width="313" align="left"><p class="left"><?php echo $lolwtam ?></p></td>
            	<td colspan="3"><p class="right"><?php echo $price1 ?> per Lb.</p></td>
            </tr>
            <tr>
            	<td><p class="left"><?php echo $lolyeam ?></p></td>
           	  	<td colspan="3"><p class="right"><?php echo $price2 ?> per Lb.</p></td>
            </tr>
            <tr>
            	<td><p class="left"><?php echo $lol2wam ?></p></td>
           	  	<td colspan="3"><p class="right"><?php echo $price3 ?> per Lb.</p></td>
            </tr>
            <tr>
            	<td><p class="left"><?php echo $lol2yam ?></p></td>
           	  	<td colspan="3"><p class="right"><?php echo $price4 ?> per Lb.</p></td>
    		</tr>
            <tr>
            	<td><p class="left"><?php echo $lolcmc ?></p></td>
           	  	<td colspan="3"><p class="right"><?php echo $price5 ?> per Lb.</p></td>
    		</tr>
            <tr>
            	<td colspan="4" align="right"><img src="header-al.jpg" alt="Alpine Lace: Better For You - Sliced Fresh" /></td>
       	  	</tr>
            <tr>
              <td colspan="3"><p class="left"><?php echo $alrfsc ?></p></td>
              <td width="109"><p class="right"><?php echo $price6 ?> per Lb.</p></td>
            </tr>
            <tr>
              <td colspan="3"><p class="left"><?php echo $almc ?></p></td>
              <td><p class="right"><?php echo $price7 ?> per Lb.</p></td>
            </tr>
            <tr>
              <td colspan="3"><p class="left"><?php echo $alac ?></p></td>
              <td><p class="right"><?php echo $price8 ?> per Lb.</p></td>
            </tr>
            <tr>
              <td colspan="3"><p class="left"><?php echo $alpc ?></p></td>
              <td><p class="right"><?php echo $price9 ?> per Lb.</p></td>
            </tr>
	</table>

 

 

Link to comment
https://forums.phpfreaks.com/topic/189032-checkbox-value-data/
Share on other sites

Please tell me you are not relying on register_globals.  Anyway, a checkbox will only exist in $_POST if it was checked, and if it does, its value will be whatever was in the HTML value="" attribute.

 

You need to check and see if it exists before displaying it.. Example,

echo isset($_POST['myCheckbox']) ? htmlentities($_POST['myCheckbox'], ENT_COMPAT, 'UTF-8') : 'NULL';

Link to comment
https://forums.phpfreaks.com/topic/189032-checkbox-value-data/#findComment-998075
Share on other sites

Sorry, i declared the variables at the top of the 2nd page.

 

The error is: Notice: Undefined index: al-pc in E:\www\mymarketinglab.com\clients\landolakes\printform\submit.php on line 10

 

<?php
  $lolwtam = $_REQUEST['lol-wt-am'] ;
  $lolyeam = $_REQUEST['lol-ye-am'] ;
  $lol2wam = $_REQUEST['lol-2w-am'] ;
  $lol2yam = $_REQUEST['lol-2y-am'] ;
  $lolcmc = $_REQUEST['lol-cmc'] ;
  $alrfsc = $_REQUEST['al-rfsc'] ;
  $almc = $_REQUEST['al-mc'] ;
  $alac = $_REQUEST['al-ac'] ;
  $alpc = $_REQUEST['al-pc'] ;
  $price1 = $_REQUEST['v1'] ;
  $price2 = $_REQUEST['v2'] ;
  $price3 = $_REQUEST['v3'] ;
  $price4 = $_REQUEST['v4'] ;
  $price5 = $_REQUEST['v5'] ;
  $price6 = $_REQUEST['v6'] ;
  $price7 = $_REQUEST['v7'] ;
  $price8 = $_REQUEST['v8'] ;
  $price9 = $_REQUEST['v9'] ;
?>

 

Link to comment
https://forums.phpfreaks.com/topic/189032-checkbox-value-data/#findComment-998077
Share on other sites

replace them with this..

$lolwtam = (isset($_REQUEST['lol-wt-am']) ? $_REQUEST['lol-wt-am'] : '');

 

Awesome, that did the trick.

 

I had one other simple question. I have the prices being input in text fields and diplayed on the next page. Right now the "per Lb." is displayed after each price. How can I adjust this to only show up if they have entered a price?

Currently:

<p class="right"><?php echo $price4 ?> per Lb.</p>

 

What I would like (obviously not working...):

<p class="right"><?php echo $price4 "per Lb." ?> </p>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/189032-checkbox-value-data/#findComment-998086
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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