Set a variable in a Foundation's reveal modal - CakePHP - cakephp

I'm trying to set a variable in a reveal modal with CakePHP.
The reveal modal i'm using is with Zurb Foundation
I have to generate a code and display it.
I have a HomeController with a generatecode() function.
In my Home.ctp I have a div with reveal modal (cf. Basic section here)
I have also a link button generate with that code :
echo $this->Html->Link('Unlock Link', array('action'=>'unlockpwd'), array('class' => 'button small', 'data-reveal-id' => 'modal_unlockpwd'));
Here is my action code :
function unlockpwd() {
$this->set('code', $this->Function->generatePwdLock());
$this->redirect($this->referer());
}
And in my Home.ctp, i just display $code in the reveal modal but i get an undefined variable error.
I think it's because i display the modal before i set $code.
How can I solve this problem ? I tried the setFlash, it works but the reveal modal seems better for the user.
Thanks for your help :)

You set 'code' as a variable and redirect away from the page so the variable is lost. Solution would be to do:
function unlockpwd() {
$this->Session->write('Code', $this->Function->generatePwdLock());
$this->redirect($this->referer());
}
where you want to see it:
echo $this->Session->read('Code');
$this->Session->delete('Code'); //if you want to show only once

Related

Controller name changed when clicking another controller hyperlink

This is my hyper-link code, everything is working fine but when I click on the last link I can see my view file but after clicking last link I am getting error message when I click rest of the link.My controller name has changed.My main controller name is tutorials. I want to put another controller hyper-link in my my default layout.
Html->link('Home',array('action'=>'index')); ?>
Html->link('Form',array('action'=>'add')); ?>
Html->link('View',array('action'=>'show')); ?>
Html->link('Ajax',array('action'=>'quick')); ?>
Html->link('Multiple',array('controller'=>'Infos', 'action'=>'multiple')); ?>
When you click on the last link you move to another controller, and when you click again on the rest of the links you are going to the Infos controller quick, show, add... methods, and probably they dont exist.
Change the links to this and all links should work through all your site.
Html->link('Home',array('controller' => 'Tutorials', 'action'=>'index'));
Html->link('Form',array('controller' => 'Tutorials', 'action'=>'add'));
Html->link('View',array('controller' => 'Tutorials', 'action'=>'show'));
Html->link('Ajax',array('controller' => 'Tutorials', 'action'=>'quick'));
Html->link('Multiple',array('controller'=>'Infos', 'action'=>'multiple'));

TinyMCE: cake php plugin [ cannot submit form ]

I use https://github.com/CakeDC/TinyMCE to download plugin and did follow all the step to integrate on my cakePHP project. so right now, all the textarea was successfully changed to tinyMCE editor
But when click "SUBMIT" to submit my form, page cannot submit and post data. Without loading editor my form can submit and post data.
Is any jquery problem ? please advise me.
thank you.
Bootsrab.php
CakePlugin::load('TinyMCE');
Configure::write('TinyMCE.editorOptions', array('width' => '500px','height'=>'250px' ));
Controller:
public $helpers=array('Html','Form','TinyMCE.TinyMCE');
View:
$this->TinyMCE->editor(array('theme' => 'advanced', 'mode' => 'textareas'));
echo $this->Form->input('user_requirements',array('required'=>true) );
Layout : default
loding js file:
echo $this->Html->script(array('ddsmoothmenu','jquery-1.7.1.min','jquery-ui-1.8.17.custom.min'));
You've set the field to be required, so the problem you are experiencing is probably the browser based form validation.
The problem is that the validation applies before TinyMCE injects the contents into the textarea, and so the validation will always fail as the textarea is empty. This is a very long known "bug" btw:
http://www.tinymce.com/develop/bugtracker_view.php?id=4768
http://www.tinymce.com/develop/bugtracker_view.php?id=5671
In Firefox you might notice a validation bubble that appears "behind" the browser in the bottom left corner of the screen, and in Chrome for example it would throw the following error: "An invalid form control with name='...' is not focusable".
The quick and dirty fix would be to set required to false. In order to keep the required class on the generated container div you would have to set this manually using the div option:
'div' => array('class' => 'input text required')
It's also possible to disable browser validation completely by defining the novalidate attribute on the form:
$this->Form->create('ModelName', array('novalidate' => true));
or using the formnovalidate attribute on the submit button:
$this->Form->submit('Submit', array('formnovalidate' => true));
Theoretically it would also be possible to listen to the invalid event and display custom validation bubbles, but the problem here is that the browser behavior is not consistent, ie in Chrome it's not possible to validate invisible (using display or visibility) fields. Also the content would still be missing in the textarea field.
What seems to work is using opacity to hide the field, that way one could position the textarea under the editor, and the validation bubble would be displayed correctly. However that would also require to inject the editor contents in the textarea manually when pressing Enter and when clicking the submit button (or probably even simpler using proper editor change events). I'll see if I can come up with an example for this later on.
Update: I've implemented a fix/workaround in form of a TinyMCE 4.x plugin, as this was bugging me in some of my own applications too, see https://github.com/ndm2/tinymce-validatable

How to generate 'a href="javascript:void(0)"' like link in cakephp?

How to generate 'a href="javascript:void(0)"' like link in CakePHP?
I make an application, the content will insert into the editor textarea when user click a list of image. I add a class to these images and write some code in the javascript file. Everything is going well.
But the link of the image is a URL address, but not 'href="javascript:void(0)' like URL. Anyone could tell me how to make it in CakePHP?
Thanks in advance!
<?php
echo $this->Html->link(
'/path/to/image/',
'javascript:void(0)'
);
?>
You can either set a path to the image or use the Html helper to generate the image tag code. The second parameter will set the href.
Don't believe there is any dynamic way, however when you are creating your form element you can set it in the options array 'href' => 'javascript:void(0)'

How to modify login.ctp

I'm a newbie to CakePHP and i'm trying to modify the login.ctp so that it would go to a different DIV tag. I already have a default.ctp layout placed in /views/layout but i don't want the menus to appear on the login page when you bring up the site. How do i go about doing it?
Thanks,
Lyman
make a login layout that has no menu, and in login(), set $this->layout= 'login';
in login function, save variable:
$this->set('nomenus', true);
in default.ctp check
if( empty($nomenus) ) {
... menus ...
}

CakePHP passing parameters to action

Hi im kinda new in cakephp and having a lot of trouble adjusting.. Here's my biggest problem ..
Im trying to pass a parameter to an action, it does load, but when my script goes from the controller to the view, and goes back to the controller again, its gone.
CONTROLLER CODE
function add($mac = 0)
{
if(isset($this->params['form']['medico']))
{
$temp= $this->Person->find('first', array('conditions' => array('smartphones_MAC' => $mac)));
$id= $temp['Person']['id'];
$this->Union->set('events_id', $id+1);
$this->Union->set('people_id', $id);
$this->Union->save();
}
VIEW CODE (This is a menu, i only have one button right now)
<fieldset>
<legend>SELECCIONE SU ALERTA</legend>
<?php
echo $form->create('Event');
echo $form->submit('EMERGENCIA MEDICA',array('name'=>'medico'));
echo $form->end();
?>
</fieldset>
When you create the form you don't include the additional url parameters or the fields as inputs. Without either of these the parameters will vanish as they are not part of the new request. You can append additional parameters to the form submission url with
$form->create('Event', array(
'url' => array('something', 'somethingelse')
));
This will create a form that points at /events/add/something/somethingelse.
I'm no big fan of using some helpers (like $html) or some methods (like $form's create() and end()). I kinda didn't get your problem, but I think it might be that you have to make a POST request to the same url you are actually into.
<form method="GET" action="<?=$this->here ?>">
Maybe you should give a further explanation of what you are trying to achieve.
You might want to try using named parameters.
I asked a similar question which you might find helpful:
cakephp adding record with some parameters fixed

Resources