I'm using Ckeditor on a field of a CakePHP form.
No problems saving the information on the database the problem is when I echo the content of that field. If the field as a link of the type mailto I get a denied: in the beginning of the href attribute.
For example:
name#domain.com
To echo the field value I'm using:
echo $data['Ent']['text'];
you can use :
<?php echo $this->Html->link($v['mail'],'mailto:'.$v['mail'],array('target' => '_blank'));?>
Dont know why Ckediter is doing that but you can remove it using jquery
<a id="link1" href="denied:mailto:name#domain.com">name#domain.com</a>
<script>
$(document).ready(function (){
$("#link1").attr("href","mailto:name#domain.com");
});
</script>
Related
I am working on a project with cakephp right now. And I am wondering if there is a way to add attribute for a img tag, this is in my view:
Here is my code:
echo '<img id="image">';
echo $this->Js->get('#image',
array('htmlAttributes' => array('src' => 'somesourcehere')));
Edit:
I found another way to do this without using JsHelper, but use HtmlHelper,
echo $this->Html->image('somesourcehere',array('alt' => 'CakePHP'));
But the issue is the src attribute would be url like, while I was trying to set the src as base64 data, so it would be something like this in HTML
<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==">
However, I can only get
<img src="/img/data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==">
Is there a way to get rid of the /img/part in my src ? So I can make the image show up
Update
I am too dumb, only need to do
echo '<img src="data:image/png;base64,'.$source.'">';
CakePHP Html image method produce relative or absolute src path to images.
In your case if need to use Helper, then use HtmlHelper method called tag:
<?php
echo $this->Html->tag(
'img',
null,
array(
'id' => 'image',
'src' => 'data:image/png;base64,'.$source'
)
);
?>
or just simple combine html and php:
<img src="data:image/png;base64, <?php echo $source; ?>">
Is it possible to bind in cakephp an event to a svg node element ?
I have the RequestHandler working correctly with divs, but i was
asked to set in the page a SVG that has several clickable areas.
If i do something like the following code:
<object id="mysvg" type="image/svg+xml" data="/img/mysvg.svg">
<p>Error, browser must support "SVG"</p>
</object>
and then add the jshelper code:
$this->Js->get('#mysvg-nodeID')->event('click', $this->Js->request(
array('action' => 'myaction', 'param01'),
array('async' => true, 'update' => '#main_div')));
It doesn't seem to work.
Can anyone share some thoughts ?
Best regards
Answering my own question in case some else also needs this.
There's probably a better solution, please share if you find one :)
Anyway, this one serves it's purpose. As i din't find a way to get
the event associated to the svg node i added javascript for that part.
<script type="text/javascript">
//<![CDATA[
var a = document.getElementById("mysvg");
//it's important to add an load event listener to the object, as it will load the svg doc asynchronously
a.addEventListener("load",function(){
var svgDoc = a.contentDocument; //get the inner DOM
var delta = svgDoc.getElementById("mysvg-nodeID"); //get the inner element by id
delta.addEventListener("mousedown",
function(){
<?php
echo $this->Js->request(array('action' => 'myaction', 'param01'),array('async' => true, 'update' => '#main_div'));
?>
},false); //add behaviour
</script>
Which Submit Button was Clicked in CakePHP?
** what is solution for 2 buttons on same form with only 1 action in cakephp? **
i have following code,1 form contain 2 buttons print & ship,if i click
print button,page is redirected on printorder page but problem is , if i click ship
button it is not working & page is redirected on printorder.
==========================================================================
<?php // in index.ctp file
echo $this->Form->create('User',array('action'=>'orders','type' =>'post'));
echo $this->Form->submit('Ship',array('name'=>'user','value'=>'Ship','id'=>'1'));
echo $this->Form->submit('Print',array('name'=>'user','value'=>'Print','id'=>'2'));
echo $this->Form->end();
?>
<?php // in UserController
public function orders()
{
if($this->params->data['form']['user'] = "Print" )
{
$this->redirect(array('action'=>'printorder'));
}
if($this->params->data['form']['user'] = "Ship")
{
$this->redirect(array('action'=>'shiporder'));
}
}
?>
It's because you have created one form and you are submitting 2 different values on the "USER" form.
so it will redirected because action of the form is common.
To avoid it.. Using of 2 different forms are the best way.
Another way is to use javascript but I suggest to use 2 different forms.
Typical solution to two submit buttons situation is to create a submit button (default action) and a regular button to handle another action. Than you can use the JavaScript to implement the behaviour of the second button, e.g. to set a value of a hidden field which contains the actual 'action' string:
echo $this->Form->create('User',array('action'=>'orders','type' =>'post'));
echo $this->Form->hidden('submit_action', array(id='submit_action')); ?>
echo $this->Form->submit('Ship',array('value'=>'Ship','id'=>'ship_button'));
echo $this->Form->button('Print',array('value'=>'Print','id'=>'print_button'));
echo $this->Form->end();
And the js:
<script>
var form = <get your form here>
var print_button = document.getElementById('print_button');
print_button.onclick = function() {
// Set value of print button to the #submit_action hidden field
document.getElementById('submit_action').value = print_button.value;
// Submit the form
form.submit();
}
</script>
I followed the top voted (not selected solution) from Two submit buttons in one form, which suggested applying different values to each submit button, and checking those on submit.
However, CakePHP didn't easily play with this technique, as despite setting 'value' key in the $options array of $this->Form->submit, no value was set on the generated element. So, I followed the suggestions from here, and used the 'name' value key.
view.ctp
$this->Form->submit('Submit 1', array('name' => 'action1'));
$this->Form->submit('Submit 2', array('name' => 'anotherAction'));
controller.php
if (array_key_exists('action1', $this->request->data)) {
/** setup any data you want to retain after redirect
* in Session, Model, or add to redirect URL below
*/
// redirect to another action
$this->redirect(array('action' => 'myOtherAction'));
} else if (array_key_exists('anotherAction', $this->request->data)) {
// do something with anotherAction submit
}
I want to be able to add a meta tag from a view (or controller if possible) in CakePHP
I have a page like /mycontroller/myview but when it is accessed with filters like:
/mycontroller/myview/page:2/max_price:500
Then I want to add meta no follow tags.
There is a meta method on the HtmlHelper class.
When I call it like this:
$this->Html->meta('keywords', 'test test test', array('inline'=>false));
It creates a meta tag like this:
<meta name="keywords" content="test test test" />
However, when I call it like this:
$this->Html->meta('robots', 'noindex, nofollow', array('inline'=>false));
I would naturally expect and want it to create this:
<meta name="robots" content="noindex, nofollow" />
Instead I get this though:
<link href="http://www.example.com/mycontroller/noindex, nofollow" type="application/rss+xml" rel="alternate" title="robots" />
What am I doing wrong?
From the documentation page (last line)
If you want to add a custom meta tag then the first parameter should be set to an array. To output a robots noindex tag use the following code:
echo $this->Html->meta(array('name' => 'robots', 'content' => 'noindex'));
In your case:
echo $this->Html->meta(array('name' => 'robots', 'content' => 'noindex, nofollow'),null,array('inline'=>false));
Hope this helps
Here's a tweaked version of the code from this page. I've tested it, and it does work:
<?php
echo $this->Html->meta(
array('name' => 'robots', 'content' => 'noindex, nofollow'),
null,
array('inline'=>false));
?>
Obviously you can write this in a single line -I just broke it down for ease of viewing here.
You can set variables from the view to the layout in the same way you set from controller to view using $this->set(), I would have a setup like this:
// View
if($condition) {
$this->set('nofollow', true);
}
// Layout (in <head>)
if(isset($nofollow) && $nofollow) {
echo $this->Html->meta(array('name' => 'robots', 'content' => 'noindex, nofollow'));
}
Now you have a short 1-liner to add the nofollow directive from any view file.
For $this->Session->setFlash('this is message','flash_error'); you
only need to create flash_error.ctp in the elements folder to have a different look.
But what is with $this->Session->setFlash('this is message')? How do I modify the standard layout? I don't want to modify it with css or javascript.
Laheab answer is right. But you can override it using the AppController beforeRender function. In your app/app_controller.php write this function :
function beforeRender(){
if ($this->Session->check('Message.flash')) {
$flash = $this->Session->read('Message.flash');
if ($flash['element'] == 'default') {
$flash['element'] = 'flash_error';
$this->Session->write('Message.flash', $flash);
}
}
}
It will override the 'default' flash element with 'flash_error'. Then in app/views/elements create flash_error.ctp
The HTML for flash messages is output in the flash method of the SessionHelper class. I find the easiest way to achieve what you're trying to do is to override the core SessionHelper class. To do this
Copy lib/Cake/View/Helper/SessionHelper.php to app/View/Helper/SessionHelper.php
Cake will now use the SessionHelper class in your app as opposed to it's own. Now you can update the flash method to output the HTML you want. On line 136, you'll see this:
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>';
As an example, if I'm using Twitter Bootstrap, I'll update this line to be:
$out = '<div class="alert fade in"><a class="close" data-dismiss="alert" href="#">×</a>' . $message . '</div>';
According to CakePHP book entry on flash():
<?= $session->flash(); ?>
in a view file outputs:
<div id='flashMessage' class='message'>My Message</div>
So there is nothing to override but the CSS for this id in cake.generic.css.
Hope I understood the question correctly. =)
You cannot override default HTML for a flash message. What I did is: created the following function in app_controller:
protected function _f($message, $url=false) {
$this->Session->setFlash($message,'message');
if($url) $this->redirect($url);
}
Created my own message.ctp template in views/elements.
Then used the _f function inc all controllers like this:
$this->_f('This is a flash message','/page_to_redirect/');
Have you tried to create a default.ctp in elements folder?
That might be what you wanted?