I’m trying to figure out how to add in a remember me functionality into my script with code igniter. Here’s what I”m attempting to do with the checkbox. I’m getting a syntax error for the if statment. Am I not using it correctly?
<?php echo form_label(form_checkbox( 'remember', 1, if (isset($this->input->cookie('xtrcook'))) { TRUE } ) . ' Auto-login in future.', 'remember' ); ?>
You have a syntax error because you’re trying to pass this as an argument:
That’s not how expressions work in PHP. You want this to be
TRUEis thextrcookcookie is set, so just pass in this:Actually,
$this->input->cookie()returns either the cookie value orFALSE, and both are always “set” soisset()is not appropriate here, you can use! empty()or!== FALSEinstead:The whole thing:
It is a bit complicated still, might be easier to pass on the
form_label()function and just write this: