1

So i have this view

<form method="POST" action="/store">
<div class="control-group after-add-more">  
<div class="form-group">                                                                    
<label>Partner :</label>                                                                        
<input type="text" class="form-control" id="partner" name="partner" value="" placeholder="Partner Name" />                                                                  
</div>                                                          
<button class="btn btn-success add-more" type="button">                                                         
<i class="glyphicon glyphicon-plus"></i> Plus Partner</button>                                                      
                                            
<div class="copy hide">                                                         
<div class="control-group">                                                                     
<div class="form-group">                                                                        
<label> Partner :</label>                                                                       
<input type="text" class="form-control" id="partner2" name="partner2" value="" placeholder="Partner Name" />                                                                    
</div>                                                                                                                              
<button class="btn btn-danger remove" type="button">                                                                    
<i class="glyphicon glyphicon-remove"></i>                                                          
Delete Partner</button>
</div>      
                                            
</div>
<button type="submit">Submit</button>
</form>

this is jquery that i use

$(document).ready(function() {
         $(".add-more").click(function() {
            var html = $(".copy").html();
            $(".after-add-more").after(html);
        });
        $("body").on("click", ".remove",function() {
            $(this).parents(".control-group").remove();
        });
});

but when i try to submit , the input partner2 is returning null value

this is my controller

$kerma = Kerma::find(1)->get();
$kerma->partner()->createMany(['partner' => $request->input('partner')],['partner' => $request->input('partner2')])

anyone have a solution for me ? thanks in advance

5
  • Try var_dump($request->input('partner2')); without the return phrase Commented Nov 15, 2020 at 13:20
  • same the result is still null Commented Nov 15, 2020 at 13:26
  • Please paste the whole code of your HTML file and controller file Commented Nov 15, 2020 at 13:30
  • 1
    www116.zippyshare.com/v/nyHkmxvF/file.html here sir Commented Nov 15, 2020 at 13:47
  • Please paste it to your question. So, someone can help you with that :) Commented Nov 15, 2020 at 13:49

1 Answer 1

1

When submitting your request to the form:

  1. The routes file should have the POST method configured.
Route::post('store', 'YourController@yourmethod');
  1. Addition of CSRF token to the Form to prevent Page Expired issue. So, your blade file should be like below:
<form method="POST" action="{{url('store')}}">
@csrf
<div class="control-group after-add-more">  
<div class="form-group">                                                                    
<label>Partner :</label>                                                                        
<input type="text" class="form-control" id="partner" name="partner" value="" placeholder="Partner Name" />                                                                  
</div>                                                          
<button class="btn btn-success add-more" type="button">                                                         
<i class="glyphicon glyphicon-plus"></i> Plus Partner</button>                                                      
                                            
<div class="copy hide">                                                         
<div class="control-group">                                                                     
<div class="form-group">                                                                        
<label> Partner :</label>                                                                       
<input type="text" class="form-control" id="partner2" name="partner2" value="" placeholder="Partner Name" />                                                                    
</div>                                                                                                                              
<button class="btn btn-danger remove" type="button">                                                                    
<i class="glyphicon glyphicon-remove"></i>                                                          
Delete Partner</button>
</div>      
                                            
</div>
<button type="submit">Submit</button>
</form>
Sign up to request clarification or add additional context in comments.

3 Comments

it still returing null to partner2
i think the problem at jquery
when i decided to not use jquery , the partner2 is returning correct value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.