tags:

views:

61

answers:

5

I want to return HTML string as follows from my controller.

$returnValue = "<a onclick='demosuccess(".
    chunk_split( base64_encode( $details['clientid'] ) ).
    ",".chunk_split( base64_encode( $details['email'] ) ).
    ",1)' >$this->lang->line('link_sendactivation')</a>";

But,it getting error.I tried it by different combinations of single and double quotes .Please help me to call demosuccess function using above html string....Thanks

+1  A: 
$returnValue = "<a onclick=\"javascript:demosuccess(".chunk_split(base64_encode($details['clientid'])).",".chunk_split(base64_encode($details['email'])).",1);\">".$this->lang->line('link_sendactivation')."</a>";
Kaaviar
thank you for your respone
Ajith
+1  A: 
$returnValue = "<a onclick='demosuccess(".chunk_split(base64_encode($details['clientid'])).",".chunk_split(base64_encode($details['email'])).",1)' >".$this->lang->line('link_sendactivation')."</a>";
Sadat
thank you for your respone
Ajith
+1  A: 

Try breaking things up a bit,

$id = chunk_split(base64_encode($details['clientid']));
$email = chunk_split(base64_encode($details['email']));
$thirdthing = $this->lang->line('link_sendactivation');
$returnValue = '<a onclick="demosuccess(\''.$id.'\',\''.$email.'\',\'1\')" >'.$thirdthing.'</a>';
Moak
Thank you..it is not working which is passing the argument something like as followsjavascript:demosuccess(MQ== ,YWpqZGtkQHJpbi5jb20= ,1).here we need to put all with in quotes like javascript:"demosuccess('MQ== ','YWpqZGtkQHJpbi5jb20=' ,'1')".
Ajith
changed, escape the quotes like this \'
Moak
There is no need to use the `javascript` label if you don’t want to use it with `break` or `continue`. The `onclick` value is already interpreted as script code.
Gumbo
@Gumbo: Thanks, changed
Moak
+3  A: 
$client_id = chunk_split(base64_encode($details['clientid']));
$email = chunk_split(base64_encode($details['email']));    
$lang_line = $this->lang->line('link_sendactivation');
$returnValue = "<a onclick='demosuccess($client_id, \"$email\", 1)'>$lang_line</a>";
antpaw
great work.Thank you so much.it works
Ajith
A: 

The problem here is that you cannot use a a method call like your $this->lang->line('link_sendactivation') inside a string declaration.

You either need to get the return value of that method in advance and store it in a temporary variable:

$tmp = $this->lang->line('link_sendactivation');
$returnValue = "<a onclick='demosuccess(".chunk_split(base64_encode($details['clientid'])).",".chunk_split(base64_encode($details['email'])).",1)' >$tmp</a>";

Or you concatenate that return value with the other parts (just like you did it with chunk_split):

$returnValue = "<a onclick='demosuccess(".chunk_split(base64_encode($details['clientid'])).",".chunk_split(base64_encode($details['email'])).",1)' >".$this->lang->line('link_sendactivation')."</a>";

Or you use sprintf like Gordon suggested:

$returnValue = sprintf("<a onclick='demosuccess(%s,%s,1)' >%s</a>",
    chunk_split(base64_encode($details['clientid'])),
    chunk_split(base64_encode($details['email'])),
    $this->lang->line('link_sendactivation'));

Futhermore you probably forgot to quote the chunked Base-64 values in JavaScript. You can use json_encode to do that:

$returnValue = sprintf("<a onclick='demosuccess(%s,%s,1)' >%s</a>",
    json_encode(chunk_split(base64_encode($details['clientid']))),
    json_encode(chunk_split(base64_encode($details['email']))),
    $this->lang->line('link_sendactivation'));
Gumbo