I am currently using ExpressionEngine 2.5.5 and have a template with multiple conditional statements...
{if logged_in && member_group == '1' || member_group == '7'}
<div>Content</div>
{/if}
{if logged_in && member_group != '1' || member_group != '7'}
<div class="authNotice">
<p>You are not authorized to view this content.</p>
</div>
{/if}
{if logged_out}
<div class="authNotice">
<p>Please Log In or Register.</p>
</div>
{/if}
The second statement does not work properly as it displays the message "You are not authorized to view this content" even if the conditions are met.
Does anyone know the best practice for combining these three conditions in a single template?
Your second condition is always true. You should change
{if logged_in && member_group != '1' || member_group != '7'}
to
{if logged_in && member_group != '1' && member_group != '7'}
DISCLAIMER: I have no idea what ExpressionEngine is ;)
Related
Client side code
<script src='https://www.google.com/recaptcha/api.js'></script>
<script>
var verified = function() {
document.getElementById("loginform").submit();
};
</script>
<form action="www.example.com/" method="POST" id="loginform" onsubmit=" return validation()">
<input id="email" maxlength="80" name="email" size="20" type="text" placeholder="Enter Your Email" style="margin-bottom: 30px;"/><br>
<div id="captchadiv">
<div class="g-recaptcha" data-sitekey="site key" data-callback="verified"></div>
</div>
<button type="submit" value="Submit" id="reg_submit" style=" display:block;margin: 0 auto;"><img src="/favicon.png" style="width: 20px;float: left;" />Sign in</button>
</form>
Server Side code
reCAPTCHA=require('recaptcha2')
recaptcha=new reCAPTCHA({
siteKey:'site key',
secretKey:'secretKey'
})
I am working on node js.I am using google recaptcha2 and when i see lots of example and all example verify recaptcha using form submit. They define in action but my action method use in other navigation so i can use get, post request. I don't have any idea for how to use get, post request for recaptcha.I want to verify recaptcha on server side using get,post request.
I need help on back-end verification work.
Thanks advance!
Please try this code
Client side code not more secure so please use both side code
Client side
function validateform(){
var captcha_response = grecaptcha.getResponse();
if(captcha_response.length == 0 || grecaptcha != undefined )
{
// Captcha is not Passed
return ' Please verify you are not a robot.';
}else{
$.get('/captchaTest',{'response':captcha_response},function(response){
if(response == undefined && response.responseCode == undefined && response.responseDesc == undefined && response.responseCode !== 0 && response.responseDesc !== 'Sucess' ){
return ' You are a robot.';
}
grecaptcha.reset();
});
}
}
Server side
app.get('/captchaTest',function(req,res){
var requestQuery = req.query;
if( requestQuery != undefined && requestQuery != '' && requestQuery != null && requestQuery.response != undefined && requestQuery.response != '' && requestQuery.response != null ){
var response = requestQuery.response;
var verificationUrl = "https://www.google.com/recaptcha/api/siteverify?secret="+ secret_key +"&response=" +response;
// Hitting GET request to the URL, Google will respond with success or error scenario.
request(verificationUrl,function(error,response,body) {
body = JSON.parse(body);
// Success will be true or false depending upon captcha validation.
if(body.success !== undefined && !body.success) {
res.send({"responseCode" : 1,"responseDesc" : "Failed captcha verification"});
}else{
res.send({"responseCode" : 0,"responseDesc" : "Sucess"});
}
});
}else{
res.send({"responseCode" : 1,"responseDesc" : "Failed captcha verification"});
}
});
I am trying to use the following conditional statement in my template:
{if "{site_url}" == "http://dev.site.com" }
true
{if:else}
false
{/if}
When I test outputting site_url in the template I get http://dev.site.com, but this expression always evaluates false.
I've tried variations without brackets and quotes with no luck.
Try adding a custom variable to your config.php (/system/expressionengine/config/ folder):
//### Custom Variables ###
global $assign_to_config;
$protocol = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$assign_to_config['global_vars'] = array(
"root_url" => $protocol.$_SERVER['HTTP_HOST'],
"domain" => $_SERVER['HTTP_HOST']
);
Then change your template to be:
{if "{root_url}" == "http://dev.site.com" }
true
{if:else}
false
{/if}
or
{if "{domain}" == "dev.site.com" }
You might get a better answer in https://expressionengine.stackexchange.com/ but some ways to work around parse order issues include:
php on input
passing variables through embedded templates
low variables
writing your own plugin
exp:query calls
im try print an alert report before a submit form.
The constroller check that entity was valid and inform the result:
$estado = Array();
if(count($errors) > 0){
$estado['alert'] = 'alert-error';
$estado['message'] = $errors->get(0);
}else{
$estado['alert'] = 'alert-success';
$estado['message'] = "Usuario creado correctamente";
}
$this->getRequest()->getSession()->getFlashBag()->add('status',$estado);
return $this->redirect($this->generateUrl('alta_usuario'));
So, in the view:
{% if app.session.flashbag.has('status') %}
<div class="alert {{ app.session.get('status').alert }}">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ app.session.get('status').message }}
</div>
{% endif %}
But Symfony fails with the next message:
Impossible to access an attribute ("alert") on a NULL variable ("")
In the profiler the Flashdata is:
status : [{"alert":"alert-error","message":{}}]
Two questions:
1) Why "message" is null ? the entity has an error and $errors->get(0) should be get the first error ?
2) Why can't access the $estado values from the view ?.
Any ideas ?.
This question is much similar as below link.
You can find the answer at
Am I using the Symfony flash variables the wrong way?
<div id="navigation">
<ul>
<li>Action</li>
<li>Adventure</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<?php
$id = (isset($_GET['id'])); set the value
switch($id) {
case 'actiune':include('/actiune/index.php');//first page
break;
case 'aventura':include('/aventura/index.php');//second page
break;
}
?>
It takes me to /action/index.php when i access adventure Why?
Please I need a bit of help
Because you're switching on true/false here, as the result of isset - which is always boolean value - is assigned to $id directly. This line should be rewritten as...
$id = isset($_GET['id']) ? $_GET['id'] : '';
... where '' can be actually replaced with that default value.
In fact, you can redirect user at the very moment when you find that $_GET['id'] is empty, then analyze it's different values with switch. Like this:
if (! isset($_GET['id'])) { ... redirection ... }
switch ($_GET['id']) {
case 'first': ...; break;
case 'second': ...; break;
default: ...;
}
Pagination link not working on expression engine exp:search results.Page does not display the new result when pagination link is clicked.
{exp:search:total_results}</b>Result(s) for <b>{exp:search:keywords}
{exp:search:search_results entry_id={entry_id}
switch="#000000|#003300" status="Open"
dynamic="off" orderby="date" sort="desc"}
{exp:search:search_results switch="resultRowOne|resultRowTwo" paginate="bottom" limit="2"}
<?php $articlePath = "article";?>
{related_entries id="article_feature"}
{if title == "Bay Blog"}<?php $articlePath = "blog";?>
{/related_entries}
<b>{title}</b> from <em>{related_entries id="article_feature"}{title} {/related_entries}</em><br/>
{if:else}
<b>{title}</b> from <em>{related_entries id="article_feature"}{title} {/related_entries}</em><br/>
{/if}
{exp:trunchtml chars="250" inline="..."}
{article_body}
{/exp:trunchtml}
{related_entries id="article_issue"}
[ {title}] {/related_entries}
<br><br>
{if no_results}
Sorry!, Search result found!
{/if}
{/exp:search:search_results}
{paginate}
<div class='paginate'>
<span class='pagecount'>{page_count}</span>
</div>
{paginate}
When returning search results, use the auto_path variable when building your URLs:
{title}
Unlike other path variables, this variable does not require the Template Group and Template Name to be specified.
Instead, the path will automatically be determined by the Search Results URL setting for the channel in Channel Management.
Admin > Channel Administration > Channels > Preferences:
If you're using ExpressionEngine's Pages Module or Structure to create static pages, the following use case may be of help to you as well:
{if page_url == ""}
// If the Search Result is a Dynamic Page
{title}
{/if}
{if page_url != ""}
// If the Search Result is a Static Page
{title}
{/if}
You can also test to see what channel the search result is being fetched from and act on it conditionally:
{if channel_name == "about"}
{title}
{if:else}
{title}
{/if}