Yii button with property submit - is not working - button

Yesterday it was working. After many changes (but not with it template) - it's not.
Yii generates button as usually, but now by clicking it does nothing.
<?= CHtml::button('Sell', array(
'submit' => CController::createUrl('product/selll', array('productID' => $data->id)),
'style' => 'width:80px',
)); ?>
Maybe i have found the problem - it is because jquery.yiiactiveform.js is not loading automaticly. Why it's not loading any more?
I have found solution. The problem is Yii form above, i've comment input text field, than no one Yii::button is working at all.
This is a code of form above:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'searform',
'enableClientValidation' => true,
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
),
'action' => array("user/searchForm"),
));?>
!!!!If i comment this textField - no one CHtml::button dont work.!!!!!
<?php echo $form->textField($search,
'product',array('width'=>'179px','height'=>'17px','value'=>$value,'save'=>$value)); ?>
<? /*
<div id="srcBtnWrap">
<?= CHtml::submitButton('',array('id'=>'srcBtn')); ?>
</div> */ ?>
<? //= CHtml::submitButton('go'); ?>
<?
$this->endWidget();
?>
Is it Yii bug, or i do something wrong?

jquery.yii.js should be loaded. If it is loaded - check JS console for errors.
Check if your action does not use die() or exit()

You have enabled client validation. Please, check errors and give us model fields (rules)
'enableClientValidation' => true,
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
),

Related

Can their be actioncontroller and no view for button in yii

I have a the register button which I have created in cgridview I need to know whether can we have action in controller buuton and no view for that particular action for that button in yii
view user
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'dataProvider'=>$model->countregister($_GET['id']),
'enablePagination' => true,
'filter'=>$model,
'columns'=>array(
'name',
'email',
array(
'class'=>'CButtonColumn',
'template'=>'{Register}{update}{view}',
'buttons'=>array(
'Register'=>array(
'label'=>'Register',
.'url'=>Yii::app()->createUrl('register/create',array( 'email'=>$data->email) )
)
),
),
),
)); ?>
controller user
public function actionCreate($email)
{
$model=$this->loadModel($email);
if($_SESSION['userid'])
{
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
));
}
//$this->redirect(array('display','id'=>$model->productid));
$this->redirect(array('user/login'));
}
i don get error but then the below line not the url iam looking
/localhost/test/index.php/register/create/product/create
it should be
/localhost/test/index.php/product/create/id/1
i think there's something wrong in line 1
Please let me know how do i resolve this
change this
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
to
$this->redirect(Yii::app()->createUrl('product/create',array( //line 1
'id'=>$model->productid))
You can parametrise your individual CButtonColumn instances:
array(
'class' => 'CButtonColumn',
'template' => '{Register}{view}{update}',
'buttons' => array(
'Register' => array(
'label' => 'Register',
'url'=>Yii::app()->createUrl('register/create', array('email' => $data->email)),
'visible'=>'$data->entries == 0',
),
'view' => array(
'visible'=>'$data->entries > 0',
)
)
),
But to answer you question after you updated your response (I was already typing it out)
You can use the raw type:
'type'=>'raw',
and the url becomes something like :
'url'=>'Yii::app()->createUrl("register/create",array( "email"=>$data->email) )'
thx to #let-me-see
source: http://www.yiiframework.com/wiki/106/using-cbuttoncolumn-to-customize-buttons-in-cgridview/#hh2
this works
$this->redirect(array('product/create','id'=>$model->productid));

cakephp, giving a cake form custom styling

How to I over ride the basic styling for a form in cakePHP? I think the default limits the width of a form to 40% but I need one of my forms to be 100%.
Is something like this the way to go?
<?php echo $this->Form->create('Quote', array('novalidate' => true, 'div' => array('class' => 'div-class'), 'before' => '<div class="quotes-form">', 'after' => '</div>')); ?>
There's any number of ways to do this.
One way would be to do what you're doing. Another would be to not bother with that, and just edit Cake's default css directly, so all forms get styled the way you want.
UPDATE:
You could just do it like this:
<div class="quotes-form">
<?php echo $this->Form->create('Quote', array('novalidate' => true, 'div' => array('class' => 'div-class'))); ?>
<?php // rest of your form elements go here ?>
</div>
Then your css can just be like
.quotes-form form {
background: red;
}

Is it possible to give condition to check directory and based on that give the code?

I'll try to be as clear as I can because it's pretty difficult to write it down...
Situation: Problem occured when working with WordPress. I have WPML (multilingual site) plugin installed and it works perfectly but the problem is that I am using this theme which has custom posts such as Homepage Text and Homepage Boxes and those two posts that appear on my homepage do not have a possibility of translating content into other languages to have that Homepage Text and Boxes in different languages (that part of the WPML plugin just doesn't appear there). Homepage Text and Homepage Boxes, those two appear on the left side of wordpress - it's a part of menu, just like Links, Pages or Comments...
I kind of came up with one way of solving this.
I created a few more of these custom posts. Now I have:
Homepage Text (home_text)
Homepage Boxes (home_boxes)
Homepage Text English (home_text_en)
Homepage Boxes English (home_boxes_en)
Homepage Text Russian (home_text_ru)
Homepage Boxes Russian (home_boxes_ru)
There are two pieces of code in index.php for these two custom posts. I'll show you one:
<div id="homepage-text">
<?php query_posts(array(
'post_type'=>'home_text',
'orderby' => 'ASC'
));
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post();?>
<h2><?php the_title() ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
</div><!-- /homepage-text -->
After this, there's a similar code for Homepage Boxes...
Way of solving: Writing a code which says: "if the address you are coming from says http://www.website.eu - use homepage text and boxes that are home_text and home_boxes; If it's http://www.website.com/EN - use home_text_en, and so on... I hope you get what I'm saying..
Is here anyone who had enough time to read all of this and would be so kind and write me that piece of code that translates my words into php?
That's my guess of how should that look but I'm stugling with writing conditions.
if (condition that it's the main language directory)
{
register_post_type( 'home_text',
array(
'labels' => array(
'name' => __( 'Homepage Text' ),
'singular_name' => __( 'Homepage Text' )
),
'public' => true,
'supports' => array('title','editor')
)
);
}
elseif (condition that it's english language directory .com/en)
{
register_post_type( 'home_text_en',
array(
'labels' => array(
'name' => __( 'Homepage Text English' ),
'singular_name' => __( 'Homepage Text English' )
),
'public' => true,
'supports' => array('title','editor')
)
);
}
else
{
register_post_type( 'home_text_ru',
array(
'labels' => array(
'name' => __( 'Homepage Text Russian' ),
'singular_name' => __( 'Homepage Text Russian' )
),
'public' => true,
'supports' => array('title','editor')
)
);
}
Thank's in advance.
Domantas.
You can use the Page Referer function of WordPress http://codex.wordpress.org/Function_Reference/wp_get_referer to do something like:
$page_referer_url = wp_get_referer();
if(strpos($page_referer_url,'.com/en')!==FALSE) { // Check if the text '.com/en' is part of the referer URL
// code for english
}
else {
// code for non english
}
You can find how strpos() works here http://php.net/manual/en/function.strpos.php

user-menu in secondary-menu: why?

I've created a sub of the zen-theme. And am mighty proud of it, but up in the top right corner (#secondary-menu) the user-menu shows up - perfectly.
I just don't understand how it get's there?
In structure/blocks the user-menu appears in the Disabled section (Region: None)
In fact, there IS no region called "secondary-menu" (id of the element gotten from Firebug)
Isn't that strange?
I can't comment on your specific template files but the standard Zen page.tpl.php file has this in it:
<?php if ($secondary_menu): ?>
<nav id="secondary-menu" role="navigation">
<?php print theme('links__system_secondary_menu', array(
'links' => $secondary_menu,
'attributes' => array(
'class' => array('links', 'inline', 'clearfix'),
),
'heading' => array(
'text' => $secondary_menu_heading,
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
</nav>
<?php endif; ?>
Which should answer how the menu gets printed to the page. If you want to dig one step deeper, the $secondary_menu variable is set up in template_preprocess_page().
As to why it's the user menu...if you go to admin/structure/menu/settings you should see this:
If you change the secondary link source to something else you should see that reflected in your theme too.

Use node-menu on page

I would like to use the node-menu (see image) on a page in Drupal.
Is this possible and, if yes, how?
If the page you are referring is a custom page output from your module, and "mymodule/page" is the path for that page, for which you want the tabs "View" and "Edit," then you should implement hook_menu() using code similar to the following one:
function mymodule_menu() {
$items = array();
$items['mymodule/page'] = array(
'page callback' => 'mymodule_page_view',
'access arguments' => array('view mymodule page'),
);
$items['mymodule/page/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['mymodule/page/edit'] = array(
'title' => 'Edit',
'page callback' => 'mymodule_page_edit',
'access arguments' => array('edit mymodule page'),
'weight' => 0,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
If the page you are referring is a page that is shown at example.com/mymodule/page, and that should show what you see at example.com/node/7, then you can implement the following code, in Drupal 7:
function mymodule_url_inbound_alter(&$path, $original_path, $path_language) {
if (preg_match('|^mymodule/page|', $path)) {
$path = 'node/7';
}
}
The equivalent for Drupal 6 is writing the following code in the settings.php file:
function custom_url_rewrite_inbound(&$result, $path, $path_language) {
if (preg_match('|^mymodule/page|', $path)) {
$result = 'node/7';
}
}
I didn't write the symmetric code for hook_url_outbound_alter(), and custom_url_rewrite_outbound() as I suppose you are not interested in rewriting example.com/node/7 to make it appear as example.com/mymodule/page, but you are interested in making appear example.com/mymodule/page the same as example.com/node/7.
Okay; a node page usually has those View and Edit tabs. So my next question is to wonder why they aren't appearing on your node page already. Have you by chance created a custom page template for this node type and removed the code that prints the tabs? Or is there a chance you're logged in as a user that doesn't have permission to edit this type of node?
There must be a reason why you're not getting those tabs; they should be there, by default.
If you do have a custom page template for this node type, look for code that looks something like this:
<?php if ($tabs): ?>
<div class="tabs"><?php print $tabs; ?></div>
<?php endif; ?>
If you don't see code like that, try adding it.
If you DO see code like that, try to isolate what's different about this content type compared to other content types where you DO see those tabs.

Resources