2015-11-06 31 views
1

我是Laravel的新手。我正在构建一个显示已检查记录的代码。 以下是我的代码。在laravel的另一个页面上显示已检查的值

{!! Form::open(array('action' => '[email protected]','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' => '[email protected]','method' => 'GET'))!!} 

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

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

我一定要显示$client->emai l当我点击按钮"show-selected"

我控制器的方法是,

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

这应返回true,但它返回false,我没有得到如何获得另一页上的检查复选框的值。

+0

搜索AJAX。 – aldrin27

+0

在带有“显示”操作的窗体中,您没有通过复选框值。这是乳清你得到错误..在你的“显示()”检查由dd(输入::所有()); ....是否需要使用2种形式。 ?? – ArtisanBay

+0

@ArtisanBay:显示代码正常运行正常。你能告诉我如何获取我的表格 {!! Form :: checkbox('agree',$ client-> email,null,['class'=>'questionCheckBox'])!!} 我传递的值是“$ client-> email”。 – Shweta

回答

0

This Worked。

我的刀片文件是:

{!! Form::open(array('action' => '[email protected]','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() !!} 

和显示方法是:

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/>"; 
     } 
    } 

点击按钮后“显示选择”的选中的复选框的值就会显示出来。

相关问题