Home > Software engineering >  I am getting null value from input field on submit
I am getting null value from input field on submit

Time:11-27

Before any downvotes, I am a student and I am still learning and this is a platform for me to learn. I have searched and watched tutorail but still not able to find my error.I am trying to store data to database. But before that I want to make sure that I am getting data from fields. But I am getting [] in response. Here is the view code:

<form action="submit" method = "POST" enctype="multipart/form-data">
                        @csrf
                        <h2><input type="file" name="imagefile"  /><br/>
                            <i  style="font-size:20px;color:orangered"></i>&nbsp;&nbsp;Document</h2><br />
                                
                          <h4 style="font-size:15px;color:antiquewhite">Title</h4>
                                    <input type="text" name="title" placeholder="Title" ><br />
                                  
                        <br />
                        <h4 style="font-size:15px;color:antiquewhite">Category</h4>
                                    <select type="text" name="category" placeholder="Select">
                                        <option value="Arts and Craft">arts and craft</option>
                                        <option value="Business">business</option>
                                    </select>
                                    <br />
                                 
                                <button  type="submit">Upload</button>
                     </form>

Here is controller code:

function uploadfilesuploader(Request $req)
    {
        $user = new uploader;
        $user-> title = $req->title;
        $user-> category = $req->category;        
        var_dump($user->title).die();
}

Here is the route:

Route::post('submit','App\Http\Controllers\register@uploadfilesuploader');

I am expecting data from fields. I have multiple post routes with submit. Could that be an issue?

Route::post('submit','App\Http\Controllers\register@savebuyer');
Route::post('submit','App\Http\Controllers\register@savefreelancer'); 
Route::post('submit','App\Http\Controllers\register@fsignin'); 
Route::post('submit','App\Http\Controllers\register@uploadfilesuploader');

As where ever I see they use this submit, so I used that. Could it confuse the web to which submit to use?

CodePudding user response:

As you figured it out, the problem is in your multiple routes that has the same path. This is not gonna work unless the HTTP methods are different (one is GET and another one is POST). Change the others and use a related path to them. A friendly advice, watch a good course or read a good book for learning Laravel (there are plenty of them, and some good ones are free too.). If you do it now it would be easier than later.

  • Related