0

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

3
  • 1
    What is the error you're getting ? Commented Jul 12, 2010 at 9:24
  • 1
    (tipp) sprintf returns a formatted string Commented Jul 12, 2010 at 9:33
  • Why do you split the Base-64 value in chunks? Commented Jul 13, 2010 at 8:13

5 Answers 5

3
$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>";
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

Comments

1

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>';

3 Comments

Thank you..it is not working which is passing the argument something like as follows javascript:demosuccess(MQ== ,YWpqZGtkQHJpbi5jb20= ,1).here we need to put all with in quotes like javascript:"demosuccess('MQ== ','YWpqZGtkQHJpbi5jb20=' ,'1')".
changed, escape the quotes like this \'
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.
0

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'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.