flashpipe Posted May 31, 2007 Share Posted May 31, 2007 I'm new to php and I need to wrap an if statement around a group of php/html and don't know how to go about it...if anyone could help, that would be great... I need to make the following chunk of code display based on the if statement below: <form action="<?php echo($cartweaver->thisPageName . "?cartid=" . $_SESSION["CartId"]);?>" method="post" name="addToCart"> <?php cw3ProductOptions($productId, $taxRate);?> <input name="prodId" type="hidden" value="<?php //echo($productId);?>"> <input name="submit" type="submit" class="formButton" value="Add to Cart"> </form> and this is the if statement I need to wrap around it... if(isset($_SESSION["customerID"]) && $_SESSION["customerID"] != "0") { } Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/53727-solved-wrapping-if-statement-around-htmlphp/ Share on other sites More sharing options...
taith Posted May 31, 2007 Share Posted May 31, 2007 <?php if(isset($_SESSION["customerID"]) && $_SESSION["customerID"] != "0") { ?> <form action="<?php echo($cartweaver->thisPageName . "?cartid=" . $_SESSION["CartId"]);?>" method="post" name="addToCart"> <?php cw3ProductOptions($productId, $taxRate);?> <input name="prodId" type="hidden" value="<?php //echo($productId);?>"> <input name="submit" type="submit" class="formButton" value="Add to Cart"> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53727-solved-wrapping-if-statement-around-htmlphp/#findComment-265503 Share on other sites More sharing options...
flashpipe Posted May 31, 2007 Author Share Posted May 31, 2007 SWEET!! So, wrap the if inside a tag and then the following tags are dependent on that if...interesting... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/53727-solved-wrapping-if-statement-around-htmlphp/#findComment-265568 Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 That is a shady way to do it, the proper way is to have the data you want printed in a string and print it out at the end of the script to avoid any issues that might come from modifying headers etc. This is the way i would go about doing it: <?php $form=false; if(isset($_SESSION["customerID"]) && $_SESSION["customerID"] != "0") { $form = '<form action="' . $cartweaver->thisPageName . '?cartid=' . $_SESSION["CartId"] . '" method="post" name="addToCart"> '. cw3ProductOptions($productId, $taxRate) .' <input name="prodId" type="hidden" value="'.$productId.'"> <input name="submit" type="submit" class="formButton" value="Add to Cart"> </form>'; } if (!$form) { echo $form; } This way you have full control and do not have to worry about conflicting items such as session_start or headers or even setcookie. Just another option to do it. Quote Link to comment https://forums.phpfreaks.com/topic/53727-solved-wrapping-if-statement-around-htmlphp/#findComment-265571 Share on other sites More sharing options...
flashpipe Posted May 31, 2007 Author Share Posted May 31, 2007 Very cool...thanks! The syntax is pretty similar to actionscript, but building the string with the html was throwing me... THANKS!!!! Quote Link to comment https://forums.phpfreaks.com/topic/53727-solved-wrapping-if-statement-around-htmlphp/#findComment-265621 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.