Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/289083-2-php-issues-in-section-of-code/
Share on other sites

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">' : ''; ?>

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>' : ''; ?>
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:

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.

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.

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 by jpopuk

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);
?>
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.