1

I am new at Laravel. I am building a code that displays the records that have been checked. Following is my code.

{!! Form::open(array('action' => 'ClientsController@store','method' => 'POST', 'name' => 'f1'))!!}

@foreach($clients as $client)

{!! Form::checkbox('agree', $client->email, null, ['class' =>'questionCheckBox']) !!}

<article>
    {{ $client->user_name }}
    &nbsp;
    {{ $client->email }}

</article>
@endforeach
{!! Form::close() !!}

{!! Form::open(array('action' => 'ClientsController@display','method' => 'GET'))!!}

<div class="form-group">
    {!! Form::submit('show-selected ',['class' => 'btn btn-primary form-control']) !!}
</div>

{!! Form::close() !!}

I have to display $client->email when I click button "show-selected".

My controller method is,

public function display() {
    $client = Client::all();
    dd(Input::has('agree'));
    $client = Input::has('agree') ? true : false;
    return $client->email;
}

This should return true, but it is returning false, I am not getting how to get the values of checked check boxes on another page.

Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
Shweta
  • 1,212
  • 4
  • 20
  • 36
  • Inside the form with action "display" you are not passing the checkbox value. That is whey you are getting false.. Inside your "display()" check this by dd(Input::all());.... Is it required to use 2 forms. ?? – ArtisanBay Nov 06 '15 at 08:30
  • @ArtisanBay : Display code is working now properly. Can you tell me how to fetch value of my form {!! Form::checkbox('agree', $client->email, null, ['class' =>'questionCheckBox']) !!} The value i am passing is "$client->email". – Shweta Nov 06 '15 at 10:56
  • When you click the show-selected button, you are trying to get all the $client->email that are checked within the store() method. Am I correct ?? – ArtisanBay Nov 06 '15 at 11:13
  • Yes. Now i am getting only single email with the code `$client = Input::get('agree'); echo "Hiii". " " .$client;` But it gives only on value of checked check-box. What should i do if i have to get response of multi-selected check-boxes – Shweta Nov 06 '15 at 13:00
  • yes. but not all, only selected with check-box. – Shweta Nov 07 '15 at 07:14

1 Answers1

0

This Worked.

My blade file is:

    {!! Form::open(array('action' => 'ClientsController@display','method' => 'GET'))!!}


<div class="form-group">
    {!! Form::checkbox("agree[]", 'email_1', null) !!} <p>email_1</p>
</div>

<div class="form-group">
    {!! Form::checkbox("agree[]", 'email_2', null) !!} <p>email_2</p>
</div>

<div class="form-group">
    {!! Form::checkbox("agree[]", 'email_3', null) !!} <p>email_3</p>
</div>


<div class="form-group">
    {!! Form::submit('Show-Selected',['class' => 'btn']) !!}
</div>

{!! Form::close() !!}

And the display method is:

public function display(){
        $data = Input::get('agree');
                $count = count ($data);
                echo "Selected email is/are:" . $count;
                echo "<br/>";
                foreach ($data as $big_name){
                    echo $big_name;
                    echo "<br/>";
        }
    }

After clicking button "Show-selected",the value of checked check-boxes will display.

Shweta
  • 1,212
  • 4
  • 20
  • 36