Open muazzamazaz opened 7 years ago
you can get all data from form with $form->getFieldValues()
, and then pull data from that.
$data = $form->getFieldValues();
show null values
Did you set up the form in the view template?
yes there is view code as:
@extends('layouts.app')
@section('content')
{!! form($form) !!}
{!! Form::token() !!}
@endsection
You don't need Form::token()
. Did you set up csrf middleware?
public function store(FormBuilder $formBuilder) {
$form = $formBuilder->create(\App\Forms\MembersForm::class);
echo print_r($form->getFieldValues(), true);
return;
}
$form->getFieldValues()
throws an error: Call to undefined method App\Forms\MembersForm::getFieldValues()
@tpfuhl did you properly extend the Form class from the package?
I did a composer update
as outlined in the README. All is working well, except the store function. Perhaps I should pass a Request parameter to the function store(FormBuilder $formBuilder)
, additionnally to the FormBuilder ?
Getting the names is working well, but the Values are empty:
foreach ($form->getFields() as $field) {
echo "<br>field name: " . $field->getName();
echo " ----field value: " . $field->getValue();
}
I can access the request's raw data (yes, it's ugly) and retrieve the entered form values. It would be nice to get them via a FormBuilder method, though.
$arequest = (array)$form->getRequest();
echo "<pre>---Form Data: ";
$myData = (array)$arequest["request"];
foreach ($myData as $row)
foreach ($row as $key=>$val)
echo "\n $key=>$val";
echo "</pre>";
@tpfuhl it's really strange that you can call getRequest()
, but not call getFieldvalues()
. Both methods exist on the form class.
might be a conflict with other packages ? I load these ones from composer.json :
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"barryvdh/laravel-debugbar": "^2.0@dev",
"laravelcollective/html": "5.1.*",
"codingo-me/dropzoner": "^1.0",
"intervention/image": "^2.3",
"yajra/laravel-datatables-oracle": "6.1.*",
"cviebrock/eloquent-sluggable": "3.1.4",
"doctrine/dbal": "^2.5",
"twbs/bootstrap": "3.3.7",
"kris/laravel-form-builder": "1.6.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"ignasbernotas/laravel-model-generator": "^1.2"
},
I got problems when calling the update function:
public function edit(int $id, FormBuilder $formBuilder) {
$record = Member::find($id);
$form = $formBuilder->create(\App\Forms\MembersForm::class, [
'method' => 'PUT',
'url' => action('MembersController@update'),
'model' => $record,
]);
The Formbuilder has generated a form without instantiating the {id}:, nonetheless the record is loaded and the values correctly displayed in the form. Probably a silly mistake . Any hints ?
<form method="POST" action="http://localhost:8000/members/%7Bid%7D" accept-charset="UTF-8"><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="..."> ...
The defined route is the default route generated by Route::resource('members', 'MembersController');
and I added the routes Route::post( 'members/{id}/update',['middleware' => 'auth', 'uses' => 'MembersController@update']); Route::get( 'members/{id}/update',['middleware' => 'auth', 'uses' => 'MembersController@update']);
Thanx, Th.
@tpfuhl where do you expect id to exist in the form?
But I'm getting following error: