1

What i'm trying to accomplish is something like this:

<?php
        if (Session::has('tk'))
        {
            $tk = Session::get('tk');
        } else {
            $tk = 1;
        }
        if (Session::has('ntk'))
        {
            $ntk = Session::get('ntk');
        } else {
            $ntk = 0;
        }
    ?>
    {{ Form::open(array('url' => 'aanvullen')) }}
        <table>
            <tr>
                <td>
                    {{ Form::submit('Toepassen') }}
                </td>
                <td>
                    {{ Form::checkbox('tijdkritisch', <?php $tk ?>, true) }} Tijdkritisch (TK) <br>
                    {{ Form::checkbox('niettijdkritisch', <?php $ntk ?>, false) }} Niet-tijdkritisch (NTK)
                <td>
            </tr>
        </table>
    {{ Form::close() }}

Somehow in my Form::checkbox this doesn't work. So my question is how do I accomplish this?

What i've also tried was this:

Session::get('tk', 1);
Session::get('ntk', 0);

Because this way I don't need the if because it gives a default value

1
  • Change <?php $tk ?> to simply $tk, the same goes for <?php $ntk ?> Commented Apr 21, 2014 at 19:27

2 Answers 2

2

In your code, following:

{{ Form::checkbox('tijdkritisch', <?php $tk ?>, true) }} Tijdkritisch (TK) <br>
{{ Form::checkbox('niettijdkritisch', <?php $ntk ?>, false) }} Niet-tijdkritisch (NTK)

Should be changed to this:

{{ Form::checkbox('tijdkritisch', $tk , true) }} Tijdkritisch (TK) <br>
{{ Form::checkbox('niettijdkritisch', $ntk, false) }} Niet-tijdkritisch (NTK)

Remove the <?php ?> from {{ }}, also you may write the code like this:

$tk = Session::has('tk') ? Session::get('tk') : 1;
$ntk = Session::has('ntk') ? Session::get('ntk') : 0;

Or like this (Seems you are aware of this, anyways):

$tk = Session::get('tk', 1);
$ntk = Session::get('ntk', 0);
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much. So for everyone how sees this post. Inside the {{ }} never put php tags.
@WereWolf-TheAlpha, thanks for adding the suggestion to reduce its code with Session::get('tk', 1).
@WereWolf-TheAlpha, Thank you for that first suggestion. That's way better than the one that I was aware of.
1

Don't put PHP tags inside blade directives, instead just put your PHP code inside the blade directive as you would do for a PHP tags:

Using blade directives:

{{ Form::checkbox('name', $tk, true) }} 

Using PHP tags:

<?php echo Form::checkbox('name', $tk, true) ?>

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.