如何解决laravel中未定义的索引错误

时间:2014-08-14 08:13:43

标签: php laravel-4

大家好,我是laravel的新人,我以父母的形式创建了父母形式,父母填写了他的详细信息。所以我的问题是当用户输入所有填充时,当提交按钮时,给出的错误是Undefined index:username。 这个查询的确切原因是什么,我显示我的控制器以及我的视图

控制器

public function parentStepOne(){

    $username = $_REQUEST["username"];    
    $valid_username = Guardian::where('username', '=', $username)->count();

        if($valid_username  == 0){
          $guardian = new Guardian; 
          $guardian->username = $username;
          $guardian->password = Hash::make($_REQUEST["password"]);
          $guardian->save();
          Session::put("guardian",$guardian->id);
          return Redirect::to("/parents/pstep2");
        }

我的观点

<div class="form"> {{ Form::open(array('url' => '/api/v1/parent/parent_step_1', 'class' => "rgform form-horizontal worldoo-form", 'id' => "registrationForm", 'method' => "POST" )) }}
                    <div class="form-group "> {{ Form::label('username', 'Parent’s Username:', array('class' => "control-label")); }}
                      <div class=""> {{ Form::text('username', '', array('class' => "form-control", 'id' => "username"));}} </div>
                      <p>Please confirm your username, your e-mail will be your unique login ID.</p>
                      </div>
                    <div class="form-group"> {{ Form::label('password', 'Please choose a password for yourself:', array('class' => "control-label"));}}
                      <div class=""> {{Form::password('password', array('class' => "form-control", 'id' => "password"));}} </div>
                    </div>
                    <div class="form-group "> {{ Form::label('confirm_password', 'Please re - enter the same password:', array('class' => "control-label"));}}
                      <div class=""> {{Form::password('confirm_password', array('class' => "form-control", 'id' => "confirm_password"));}} </div>
                      <p>Please remember or note your password you will need it to log into worldoo as a parent.</p>
                    </div>
                    <div class="form-group">
                      <div class="text-center"> {{Form::submit('Next', array('class' => "btn btn-primary worldoo-btn"));}} </div>
                    </div>
                    {{ Form::close() }} </div>




}   

2 个答案:

答案 0 :(得分:0)

我想首先说我从未使用过laravel,但通过阅读,我可以看到这可能有用吗?

<div class=""> {{ Form::text('username', '', array('name' => "username", 'class' => "form-control", 'id' => "username"));}} </div>
<p>Please confirm your username, your e-mail will be your unique login ID.</p>
</div>

php REQUEST变量使用&#39;名称&#39; input元素的属性,而不是id。

答案 1 :(得分:0)

尝试:$username = Input::get('username');