0

I have a button that calls a modal form where user can change their group name. I want to pass the id into the form {!! Form::open(['action' => [ 'ContactsController@update', id]]) !!}. I tried using the same way that I passed value to group name input using jquery but can't work.

Button code:

 {{ Form::button('<i class="material-icons">dvr</i>', ['type' => 'button', 'class' => 'btn btn-warning btn-link btn-just-icon edit_btn', 'data-toggle'=>'modal', 'data-name'=>"$group_contact->group_name" 'data-id'=>"$group_contact->id", 'data-target'=>'#editGroupModal'] )  }}

Modal form code:

  {!! Form::open(['action' => [ 'ContactsController@update', ???],'method' => 'POST', 'class' => 'form-horizontal']) !!}
      <div class="form-group bmd-form-group">
          <input type="hidden" name="eventId" id="eventId"/>
          <span id="idHolder"></span>   
        {{Form::label('group_name','',['class' => 'bmd-label-floating', 'placeholder' => 'Enter group name'])}}
        {{Form::text('group_name','',['class' => 'form-control', 'autocomplete'=>'off'])}}
      </div>
      <div class="modal-footer">
        {{Form::submit('Update', ['class'=>'btn btn-primary'])}}
      </div>
    {!! Form::close() !!}

Update Controller:

public function update(Request $request, $id)

2 Answers 2

1

I think i found the way to do it by changing the attribute of action

$('#contactsEditForm').attr('action', '/contacts/' + groupID);
Sign up to request clarification or add additional context in comments.

Comments

0

Create a route for each controller function.

e.g Route::POST('/update-group', 'ContactsController@update')->name('update.group');

public function update(Request $request) {
 try {
     $input = $request->all(); 
     //$input['input_field_name']
  } catch (\Throwable $th) {
      echo "<pre>";print_r($th->__toString());die;
   }
}

And you have already passed Id in the hidden field.

Type this in your form action {!! Form::open(['route' => 'update.group','method' => 'POST', 'class' => 'form-horizontal']) !!}.

Or you can pass a parameter in the URL like below.

Route::POST('/update-group/{id}', 'ContactsController@update');
{!! Form::open(['action' => route('update-group', ['id' => $id])])!!}

Hope this will help! :) :) :) :)

3 Comments

So there isn't other way than created each function controller?
Can you please post the error message here for better clarification.
or i thinking of changing the attribute $('#contactsEditForm').attr('action', data[0]);

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.