yii ajax validation errors show up - ajax

I have the following form:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'new-agenda-entry',
'enableAjaxValidation'=>true,
'action'=>'')); ?>
<div class="four columns">
<div class="right top5 sufix10">
<?php echo $form->labelEx($model,'eventTime'); ?>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'UserAgenda[eventTime]',
'model'=>$model,
'options'=>array(
'dateFormat'=>'yy-mm-dd',
'minDate'=>'new Date()',
) // jquery plugin options
));?>
<?php echo $form->error($model, 'eventTime'); ?>
</div>
<div class="right top5 sufix10">
<?php echo CHtml::dropdownList('eventTime_hour', false, $this->getHourArray()); ?>
<?php echo CHtml::dropdownList('eventTime_min', false, array('00'=>'00', '30'=>'30')); ?>
</div>
<?php echo $form->labelEx($model,'note'); ?>
<?php echo $form->textField($model, 'note');?>
<?php echo $form->error($model, 'note'); ?>
The model is successfully validated on the server as I can see the response in Firebug:
{"UserAgenda_eventTime":["Event time cannot be blank."],"UserAgenda_note":["Note cannot be blank."]}
The message seems fine, so does the html but the hidden inputs generated by yii remain hidden and empty.

in the action maybe (create or update) you have to uncomment // $this->performAjaxValidation($model); like this you have an ajax validation, if the problem persist I think posting it to yiibootstrap discussion in yii forums i better, I see that you use yiibootstrap, try it with default yii form widget.

Related

Magento: How to show custom attribute on product page below description

I have a custom attribute for products in which I add a video URL.
I made this Embed video responsive using css.
Now I want to call the custom attribute on the product page, so it shows the video.
The file responsible for this is: description.phtml
I've tried the following:
?>
<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
<h2><?php echo $this->__('Details') ?></h2>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
</div>
<div class="std">
<?php echo $_product->getAttributeText('video') ?>
</div>
<?php endif; ?>
But I get the error:
Fatal error: Call to a member function getAttributeText() on a non-object in /data/web/public/app/design/frontend/base/default/template/catalog/product/view/description.phtml on line 40
The video does show however. I'm probably doing this all wrong. Can I fix this with a simple edit of the code, or do I have to use an entirely different approach?
Thanks.
<?php echo $this->getProduct()->getAttributeText('video'); ?>
Try this. Or on top of document add this
<?php $_product = $this->getProduct(); ?>

not working login form to display error in model window after server side validation in yii

I have a login form in modules which uses a chtml textfield which using jQuery does client side validation but if the user does not exist and enters both fields it redirect to the login url and does not display the error in a modal popup.
I am calling modules login via ajax in main layout. It can be in any page and calls the login perfectly.
but the only thing not WORKING is server side validations if login credentials are wrong. It redirects to the user/login page and not display the server side validation error in the modal window.
<?php echo CHtml::beginForm(); ?>
<div class="row1">
<?php echo CHtml::activeTextField($model,'username',array('placeholder'=>'Username or Email','class'=>'pclas')) ?>
</div>
<div class="row1">
<?php echo CHtml::activePasswordField($model,'password',array('placeholder'=>'Password','class'=>'pclas')) ?>
</div>
<div class="remsub">
<div class="rememberMe1">
<?php echo CHtml::activeCheckBox($model,'rememberMe',array('class'=>"btn1"));echo CHtml::activeLabelEx($model,'rememberMe',array('class'=>"btn1")); ?>
<?php ?>
</div>
<div class="submit1">
<?php echo CHtml::submitButton(UserModule::t("Login"),array('class'=>"btn")); ?>
</div>
<div class="regpwd">
<?php echo CHtml::link(UserModule::t("Register"),Yii::app()->getModule('user')->registrationUrl,array('class'=>'pclas1')); ?> | <?php echo CHtml::link(UserModule::t("Lost Password?"),Yii::app()->getModule('user')->recoveryUrl,array('class'=>'pclas1')); ?>
< /div>
</div>
<?php echo CHtml::endForm(); ?>
<?php
$form = new CForm(array(
'elements'=>array(
'username'=>array(
'type'=>'text',
'maxlength'=>32,
),
'password'=>array(
'type'=>'password',
'maxlength'=>32,
),
'rememberMe'=>array(
'type'=>'checkbox',
)
),
'buttons'=>array(
'login'=>array(
'type'=>'submit',
'label'=>'Login',
),
),
), $model);
?>
and its a LOGIN FORM AND NOT A SIGN UP FORM is what my need is possible or any ohter solutions would be appreciated
Yes, please add your code so that we know what you're up to.
Some things that could help:
Perhaps users who are using the form are not allowed to access the controller/action that does the validation? That would cause Yii to redirect him/her to login page. Try looking at the permissions for the controller/action that does the validation.
Make sure your forms have enabled ajax validation:
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'user-form',
'enableAjaxValidation'=>true, <----------
'enableClientValidation'=>true,
'focus'=>array($model,'firstName'),
)); ?>

Ajax validation in Yii form

In my form I want to make an ajax validation for the radio buttons of gender.
I have an attribute gender in the model users, at the rules of model I put gender as a required field, but when I submit the form without selecting any gender the validation doesn't work to tell me that the gender cannot be blank, here is my code:
<div class="row">
<?php echo $form->labelEx($model,'gender'); ?>
<?php echo $form->radioButton($model,'gender',array('value'=>'0')) . 'Male<br>'; ?>
<?php echo $form->radioButton($model,'gender',array('value'=>'1')) . 'Female'; ?>
<?php echo $form->error($model,'gender'); ?>
</div>
You should be using radioButtonList() instead of radioButton().
<?php echo $form->labelEx($model,'gender'); ?>
<?php echo $form->radioButtonList($model,'gender',array('1'=>'Male','2'=>'Female')); ?>
<?php echo $form->error($model,'gender'); ?>

Displaying posts from specific categories with the AheadWorks blog extension for Magento

I'm using the AheadWorks blog extension for Magento, and my blog pages are working fine. But I want excerpts of my latest posts from certain categories to appear on my home page. I've successfully setup everything thus far by adding:
<block type="blog/blog" name="blog.latest" template="aw_blog/blog-home.phtml" />
to "layout.xml", by adding:
<?php echo $this->getChildHtml('blog.latest') ?>
to my home page's phtml file, and by creating "template/aw_blog/blog-home.phtml".
The problem is that I can't figure out how to limit what categories are shown. For example, you'll see in my "blog-home.phtml" file below that I'm trying to limit the posts to the "news" category. I've tried lots of solutions from other forums, but no matter what I do, I see posts from every category. Does anyone know what I need to add/take away from my code to limit the categories?
<?php $posts = $this->getPosts("news"); ?>
<div id="messages_product_view">
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>
<?php echo Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml(); ?>
</div>
<?php $numberOfPosts = 1 ?>
<?php $renderedPosts = 0 ?>
<?php foreach ($posts as $post): ?>
<div class="postWrapper">
<div class="postTitle">
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
</div>
<div class="postContent"><?php echo $post->getPostContent(); ?></div>
<?php echo $this->getBookmarkHtml($post) ?>
<div class="tags"><?php echo $this->getTagsHtml($post) ?></div>
<div class="postDetails">
<?php if ($this->getCommentsEnabled()): ?>
<?php echo $post->getCommentCount(); ?> <a href="<?php echo $post->getAddress(); ?>#commentBox" >Comments</a> |
<?php endif; ?>
<?php $postCats = $post->getCats(); ?>
<?php echo "<h1>" . $postCats[2] . "</h1>"; ?>
<?php if (!empty($postCats)): ?>
<?php echo Mage::helper('blog')->__('Posted in'); ?>
<?php foreach ($postCats as $data): ?>
<?php echo $data['title']; ?>
<?php endforeach; ?>
<?php else: ?>
<?php endif; ?></div>
<?php $renderedPosts ++ ?>
<?php if ($renderedPosts = $numberOfPosts) {
break;
}
?>
</div>
<?php endforeach; ?>
<?php //$this->getPages(); ?>
Following is the quick solution:
Go to aw_blog frontend template, default might be this app/design/frontend/base/default/template/aw_blog/menu.phtml
check and replace:
if ($posts = $this->getRecent():
with
$currentBlogCat = Mage::getSingleton('blog/cat');
if ($posts = $this->getRecent($currentBlogCat['cat_id'])):
Now open up /app/code/community/AW/Blog/Block/Menu/Sidebar.php
check for the below function:
public function getRecent()
add a parameters to it:
public function getRecent($currentCat=false)
Also, replace the following code block
$collection = clone self::$_collection;
if (array_key_exists('categories',$data = $this->getData();) && count(explode(',', $data['categories'])) == 1) {
with
$collection = clone self::$_collection;
$data = $this->getData();
if($currentCat>0)$data['categories']=$currentCat;
# Category fix #
if (array_key_exists('categories',$data ) && count(explode(',', $data['categories'])) == 1) {
Thanks!

Yii validation: some errors are not displayed

Here is my rules method:
public function rules() {
$newRules = array(
array('password_verification, valid_from, valid_until', 'required'),
array('password_verification', 'length', 'min'=>6, 'max'=>32),
array('password_verification', 'compare', 'compareAttribute'=>'password'),
array('username, email', 'length', 'min'=>3,'max'=>255),
array('password', 'length','min'=>6, 'max'=>32), array('username, email', 'unique'),
array('email', 'email'), array('id, type, username, password, email, valid_from, valid_until', 'safe'),
);
return array_merge($newRules,parent::rules());
}
And here is my view (fields which give a hard time):
<div class="row">
<?php echo $form->labelEx($user,'password_verification',array('label'=>'Verification mot de passe','class'=>'forsys-label')); ?>
<?php echo $form->passwordField($user,'password_verification',array('size'=>30,'maxlength'=>32)); ?>
<?php echo $form->error($user,'password_verification') ?>
</div>
<div class="row">
<?php echo $form->labelEx($user,'valid_from',array('label'=>'Valide depuis le','class'=>'forsys-label')); ?>
<?php echo $form->dateField($user,'valid_from'); ?>
<?php echo $form->error($user,'valid_from'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($user,'valid_until',array('label'=>"Valide jusqu'au",'class'=>'forsys-label')); ?>
<?php echo $form->dateField($user,'valid_until'); ?>
<?php echo $form->error($user,'valid_until'); ?>
</div>
Some informations:
enableClientValidation and enableAjaxValidation are both at true
datefield is a costum method. It's not where the problem come from (a colleague use it in the same way I use it without this problem).
My Problem:
For "valid_until" and "valid_from" errors are not displayed on the HTML.
If I let "password_verification" empty, when I change the focus an error appears (because of ajaxValidation onChange), but none errors if I let "valid_until" or "valid_from" empty.
But these errors are noticed by Yii, I can see them in firebug if I check the ajax request response.
So if all fields are empty, nothing will be created in DB because of 3 errors, but only one (password_validation) will be displayed.
If any body have an idea, you're welcome :)
Sorry for my approximate english
Thank you for read me, have a good day.
Michaƫl
You have these attributes marked as "safe" in the last rule. Probably that's the reason. Remove that rule or add a scenario for it (usually attributes are declared as safe on 'search' scenario - e.g. add 'on'=>'search' element to that rule).

Resources