jpopuk Posted June 9, 2014 Share Posted June 9, 2014 Hi, first of all I am trying to do a section hidden from guests on a website. I have groups for each user (groups_admin, _mod, _member etc.) I have it so ADMIN only view content at the moment, but not sure how to add GROUPS_MOD & GROUPS_MEMBER: <?php echo $user_data['group_id'] == GROUPS_ADMIN ? 'content' : ''; ?> Secondly, where the content section is, I have HTML placed inside it which works fine, but it also has some PHP code. How would I get it so the php code works? This is what I have... <?php echo $user_data['group_id'] == GROUPS_ADMIN ? '<form method="post" action="<?php echo get_url(\'/products/\', $product[\'category_id\'], $product[\'product_id\'], $product[\'product_name\']); ?>?action=review">' : ''; ?> As you can see the form action line has a php url to generate the relevant link for a specific product. If anyone has any suggestions or can help in any way that would be much appreictaed. Cheers, Paul Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 9, 2014 Share Posted June 9, 2014 I haven't looked too closely at the code, but I noticed that you're opening a PHP tag within PHP. Try changing this: <?php echo $user_data['group_id'] == GROUPS_ADMIN ? '<form method="post" action="<?php echo get_url(\'/products/\', $product[\'category_id\'], $product[\'product_id\'], $product[\'product_name\']); ?>?action=review">' : ''; ?> To this: <?php echo $user_data['group_id'] == GROUPS_ADMIN ? '<form method="post" action="' . get_url('/products/', $product['category_id'], $product['product_id'], $product['product_name']) . '?action=review">' : ''; ?> Quote Link to comment Share on other sites More sharing options...
jpopuk Posted June 9, 2014 Author Share Posted June 9, 2014 Thanks for quick response but have tried that. I know that within the content section when using a ' you have to put a backwards slash in front of it to enable the HTML. Not quite sure how to do it with PHP though? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 9, 2014 Share Posted June 9, 2014 I looks like get_url() is a user-defined function. What does the code look like? Does it expect multiple arguments or one long string? Quote Link to comment Share on other sites More sharing options...
jpopuk Posted June 9, 2014 Author Share Posted June 9, 2014 It looks exacrly like this: <?php echo $user_data['group_id'] == GROUPS_ADMIN ? '<br /> <script type="text/javascript" src="/ckeditor/ckeditor.js"></script> <form method="post" action="<?php echo get_url(\'/products/\', $product[\'category_id\'], $product[\'product_id\'], $product[\'product_name\']); ?>?action=review"> <input type="hidden" name="info_id" value="<?php echo $product[\'product_id\']; ?>" /> <h4>Review Product</h4> <fieldset> <p align="center">Fields marked with a <span class="important">*</span> are required. </p> <p>Please note, you must be registered to post a product review.</p> <table border="0" cellpadding="3" cellspacing="1"> <tr> <td valign="top">Review: <span class="important">*</span></td> <td><textarea name="review" cols="20" rows="5"></textarea> <script type="text/javascript"> CKEDITOR.replace( \'review\', { uiColor: \'#000000\', toolbar: [ [ \'Bold\', \'Italic\', \'Underline\' ], [ \'Cut\', \'Copy\', \'Paste\', \'-\', \'Undo\', \'Redo\' ], [ \'Link\', \'Unlink\' ] ], height: 100, width: 400, }); </script></td> </tr> <tr> <td><a href="javascript:;" onClick="sendGetRequest(\'/includes/get_captcha.php\', \'CaptchaContainer\');">Reload image</a></td> <td><div id="CaptchaContainer" style="height: 32px;"><?php require_once(\'../includes/get_captcha.php\'); ?></div></td> </tr> <tr> <td>Security Code:</td> <td><input type="text" name="code" /> <img src="/images/q-mark.gif" alt="Please enter the values shown above (case insensitive)" title="Please enter the values shown above (case insensitive)" width="15" height="15" /></td> </tr> </table> </fieldset> <p align="center"><input type="submit" name="submit" value="Submit Review" /></p> </form>' : ''; ?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 9, 2014 Share Posted June 9, 2014 I was actually wondering about the code that defines get_url(). Quote Link to comment Share on other sites More sharing options...
jpopuk Posted June 9, 2014 Author Share Posted June 9, 2014 function get_url($page_url, $category_id, $info_id = '', $info_name = '', $default_page = 0) { return $page_url . (array_key_exists($category_id, $GLOBALS['categories']) ? get_url_tidy($GLOBALS['categories'][$category_id]['category_name']) . '-' . $category_id . '/' : '') . ($info_id != '' && $default_page == 0 ? get_url_tidy($info_name) . '-' . $info_id . '.htm' : ''); } Haha, sorry! This is the get_url function: Quote Link to comment Share on other sites More sharing options...
jpopuk Posted June 10, 2014 Author Share Posted June 10, 2014 I don't think the function is any relevance to the issue I am having. I just need to figure out how I can activate PHP with the ' content ' part of the script. HTML is fine, and as I mentioned you simply add a backwards slash in front of an apostrophe. But when doing this for PHP it just causes an error. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 10, 2014 Share Posted June 10, 2014 As the initial code stands... <?php echo $user_data['group_id'] == GROUPS_ADMIN ? '<form method="post" action="<?php echo get_url(\'/products/\', $product[\'category_id\'], $product[\'product_id\'], $product[\'product_name\']); ?>?action=review">' : ''; ?> ...you're just going to get the following form tag: <form method="post" action="<?php echo get_url('/products/', $product['category_id'], $product['product_id'], $product['product_name']); ?>?action=review"> Note the PHP code within the action attribute. I imagine you want to execute the get_url() function so that it's output is used for the action attribute. In order for the function to execute, the function call needs to be made outside of a PHP string. So it seems like you need to use a solution like the one mentioned in Reply 2. Quote Link to comment Share on other sites More sharing options...
jpopuk Posted June 11, 2014 Author Share Posted June 11, 2014 (edited) As I mentioned I tried that but to no effect. Is there a way that the content section can be inserted in another way? <?php echo $user_data['group_id'] == GROUPS_ADMIN ? 'content' : ''; ?> Something like? .... <?php echo $user_data['group_id'] == GROUPS_ADMIN ?) { ?> content <?php : ''; ?> } ?> I have tried this but it did not work. If anyone has a suggestion that would be great. Thanks Edited June 11, 2014 by jpopuk Quote Link to comment Share on other sites More sharing options...
boompa Posted June 11, 2014 Share Posted June 11, 2014 Maybe avoid trying to stick everything on one line and write a function? <?php function get_review_link($user_data, $product) { if ($user_data['group_id'] == GROUPS_ADMIN) { return '<form method="post" action="' . get_url('/products/', $product['category_id'], $product['product_id'], $product['product_name']) . '?action=review">'; } return ''; } echo get_review_link($user_data, $product); ?> Quote Link to comment Share on other sites More sharing options...
jpopuk Posted June 11, 2014 Author Share Posted June 11, 2014 Issue solved! Next point is, how do I add additional GROUPS ID: <?php echo $user_data['group_id'] == GROUPS_ADMIN ? I want to add GROUPS_MOD and GROUPS_MEMBER Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 11, 2014 Share Posted June 11, 2014 You could use in_array(). <?php echo in_array($user_data['group_id'], array(GROUPS_ADMIN, GROUPS_MOD, GROUPS_MEMBER)) ? Quote Link to comment Share on other sites More sharing options...
jpopuk Posted June 11, 2014 Author Share Posted June 11, 2014 That worked great. Thank you very much Quote Link to comment 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.