I have the following piece of code which I use to display a downloadable link only if the user is logged in. The code used to work.
After the user is logged in, the link tells me I still need to login. I expect it has to do with formkey.
How can I go about fixing this?
<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): /*If user is not logged in*/ ?>
<?php $registerUrl = $this->getData('registerUrl'); /** generate your register URL*/ ?>
<div>
<?php echo "<a href='$registerUrl'>Please login to download, gelieve eerst in te loggen, Bitte erst Anmelden </a>"; /*Ask user to Register*/ ?>
</div>
<?php else: /*If user logged in*/ ?>
<?php $downloadUrl = $this->getData('downloadUrl');/**generate your download URL */ ?>
<div>
<?php echo "<a href='$downloadUrl'>Link</a>"; /* Allow user to download */ ?>
</div>
<?php endif; ?>
I found the solution. I added
<?php Mage::getSingleton('core/session')->getFormKey() ?>
Just before
<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): /*If user is not logged in*/ ?>
Related
How do I change the header after login, or is using another header even the right way to do it? Meaning there would be two different headers(guest/user). I've searched for it, mostly about redirects of the entire page, not what I am looking for.
Sorry for the noob question. :/
Make two files in your view with guest_header.php and user_header.php when user is logged in user user_header.php as your header file in your layout or simply use guest_header.php
and in your column layout use it like below
when user is logged in
<?php if(Yii::app()->user->id): ?>
<?php $this->beginContent('//layouts/user_header.php'); ?>
when user is guest
<?php else: ?>
<?php $this->beginContent('//layouts/guest_header.php'); ?>
<?php endif; ?>
Added this line
<?php $this->endContent(); ?>
<?php $this->beginContent('//layouts/main'); ?>
<?php echo $content; ?>
</div><!-- content -->
<?php $this->endContent(); ?>
I have three module 1 ) client 2 ) producer and search , I want to show login form in header
Login form is for producer , means producer can login
themes\mytheme\views\layouts
<div id=weppr>
<div class=fr header-right>
<?php $form=$this->beginWidget(CActiveForm, array(
id=>login-form,
enableClientValidation=>true,
clientOptions=>array(
validateOnSubmit=>true,
),
));
echo $form->textField($model,username,array(placeholder=>Enter Email,class=>login-input));
echo $form->passwordField($model,password,array(placeholder=>Enter Password,class=>login-input));
echo CHtml::submitButton(Login,array(class=>login-button));
$this->endWidget();
<div>
<?php echo $content; ?>
</div>
It gives error ,
Is possible to put in main.php , Is it acceptable coding , If not please how to do , and how to integrate login page that should be visible on every page with different module
I think you should try something like this:
LoginWidget.php
<?php class LoginWidget extends CWidget {
public function run() {
$model = new LoginFormModel;
$form= $this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'action'=>array('site/login'),
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
)
));
echo $form->textField($model,'username',array('placeholder'=>'Enter Email',class=>'login-input'));
echo $form->passwordField($model,'password',array('placeholder'=>'Enter Password',class=>'login-input'));
echo CHtml::submitButton('Login',array(class=>'login-button'));
$this->endWidget();
} } ?>
In your Layout File:
<?php $this->widget('LoginWidget'); ?>
That should do it!
hopefully a quick question here, have not been able to find out the answer on google. Anyway I have the following File upload field.
<div class="row">
<?php echo CHtml::form('', 'post', array('enctype' => 'multipart/form-data')); ?>
<?php echo $form->labelEx($model, 'doc'); ?>
<?php echo CHtml::activeFileField($model, 'doc'); ?>
<?php echo $form->error($model, 'doc'); ?>
</div>
The question I have is how to change the default text? On the page in question the upload field comes up with "No file chosen" beside the button when the page loads. I wish to change this text, anyone tell me how? Thanks.
I quick & dirty fix is this:
<?php echo CHtml::activeFileField($model, 'type',array('style'=>'width:100px;', 'onchange' => 'this.style.width = "100%";')); ?>
i've have problem in understanding how can i render contact form created by default from Yii at the bottom of my Home Page.
What i can use? renderPartial() or simply render() and what is the right way to do this?
<?php $this->renderPartial('contact', array('model'=>$model)); ?> return me error of undefined value $model.
I'm new on Yii Framework someone can help me?
TIA
Now i have problems building contact Portlet
This is my component ContactForm.php
<?php
Yii::import('zii.widgets.CPortlet');
class ContactForm extends CPortlet
{
public $title="Contact Us";
protected function renderContent() {
$form = new ContactForm;
if(isset ($_POST['ContactForm']))
{
$form->attributes=$_POST['ContactForm'];
if($form->validate())
$this->controller->refresh ();
}
$this->render('contactForm', array('form'=>$form));
}
}
And this is my contacForm.php view that give me error:
<?php echo CHtml::beginForm(); ?>
<div class="row">
<?php echo CHtml::activeLabel($form,'name'); ?>
<br/>
<?php echo CHtml::activeTextField($form,'name') ?>
<?php echo CHtml::error($form,'name'); ?>
</div>
<div class="row">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php echo CHtml::endForm(); ?>
CException
ContactForm and its behaviors do not have a method or closure named "getAttributeLabel".
This is the part of SiteController where there is the contact function:
/**
* Displays the contact page
*/
public function actionContact()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$headers="From: {$model->email}\r\nReply-To: {$model->email}";
mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
$this->refresh();
}
}
$this->render('contact',array('model'=>$model));
}
Where is the error?
Looks like a use case for a portlet. Here is a tutorial for creating a User-login portlet; with the contact form, it should be similar:
http://www.yiiframework.com/doc/blog/1.0/en/portlet.login
I have 10 pages, 4 of which should be accessible by logged in users.
Is there a plugin that exists to password protect these pages? Ideally, you can login once and then subsequently view all these protected pages.
I have Googled a bit, but haven't been able to find something that lets you protect individual pages, only the entire WordPress platform.
Does something like this exist, and if there are multiple, which is the best in your experience?
Thanks
You could use a Membership Plugin. Most of them cost money. A Google search turned up a free one called MemberWing, but I haven't tried it and can't speak to how good it is.
Generally a membership plugin will handle registration and access control. If you decide that's overkill, you could focus just on content protection with a Custom Page Template. Below, I've attached a generic WordPress Page Template that will hide content from guests. It's based off of WordPress' old default theme. If the user is not logged in, it'll display a message telling them they can't access the content as a guest.
<?php
/*
Template Name: Protected Content
*/
get_header(); ?>
<div id="content" class="narrowcolumn" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php
if(is_user_logged_in()) {
the_content('<p class="serif">Read the rest of this page ยป</p>');
}
else {
echo "You must be logged in to access this content!";
}
?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
<?php comments_template(); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Private posts should do what you want. You shouldn't need a plugin.