deep singh
deep singh

Reputation: 339

Laravel 5 form not working (not inserting data)

        public function save()
 {
        //return \View::make('student.view');

        $validation= array(
                      'first_name'=>'required',

                      'email'=>'required'

                          );
        $v1= Validator::make(Input::all(),$validation);

I think it fails after this line and not inserting the data and it just again shows the form like as v1 fails and it goes to view file (form) after pressing the submit button.

        if( $v1->fails())
        {
        return Redirect::to('view')->withErrors($v1);
        }
        else
        { $poststudent=Input::all();
          $data = array('first_name'=>$poststudent['first_name'],
                         'last_name'=>$poststudent['last_name'],
                         'email'=>    $poststudent['email'],
                    'interested'=>    $poststudent['interested'], 
                         'skills'=>   $poststudent['skills']);

        $check=0;
        $check=DB::table('students')->insert($data);

        if($check > 0)
        {
        return Redirect::to('/');
        }
        else
        {
        return Redirect::to('/view');
        }

        }

        }

view.blade.php file is here (in this, there is features of form):

   <form action="<?=URL::to('/save')?>" method="POST">

    <input type="hidden" name="_token" value="{{ csrf_token() }}">


    <div class="form-group">
    <label for= "first_name"> FIRST NAME </label>
     <input name="FIRST NAME" type="text" value="" class="form-control" id="first name"/>
   </div>

  <br /><br />
  <div class="form-group">
  <label for= "last_name"> LAST NAME </label>
   <input name="LAST NAME" type="text" value="" class="form-control" id="LAST NAME"/>
  </div>

 <br /><br />
  <div class="form-group">
  <label for= "EMAIL"> EMAIL </label>
   <input name="EMAIL" type="text" value="" class="form-control" id="EMAIL"/>
   </div>



    <br /><br />
    <div >
    <label for= "INTERESTED"> INTERESTED </label><br />
    <input type="radio" name="INTERESTED" value="ANDROID DEVELOPER" />
    ANDROID DEVELOPER<br />
    <input type="radio" name="INTERESTED" value="WEB DEVELOPER" />
    WEB DEVELOPER<br />
    <input type="radio" name="INTERESTED" value="GAME DEVELOPER" />
    GAME DEVELOPER <br />
    <input type="radio" name="INTERESTED" value="JAVA DEVELOPER" />
    JAVA DEVELOPER<br />
   </div>

   <br /><br />
   <div >
   <label for= "SKILLS"> SKILLS </label><br />
   <textarea name="SKILLS" cols="50" rows="6"></textare a>
    </div>



   <br />
   <br />


   <input type="submit" value="Submit" name="save" class="text" />


    </form>

I don't know how to fix this.

Upvotes: 1

Views: 1637

Answers (1)

Ariful Haque
Ariful Haque

Reputation: 3750

In your Blade view, you using element name in wrong way. e.g name="Last Name" You should use like:

<input name="last_name" type="text" value="" class="form-control" id="LAST NAME"/>

Then your this code will work.

$data = array('first_name'=>$poststudent['first_name'],
                         'last_name'=>$poststudent['last_name'],
                         'email'=>    $poststudent['email'],
                    'interested'=>    $poststudent['interested'], 
                         'skills'=>   $poststudent['skills']);

Update

You also need to use

 public function save(Request $request)

and without

 $poststudent=Input::all();

use

 $poststudent = $request->all();

Upvotes: 1

Related Questions