shawnmccool / laravel-form-base-model Goto Github PK
View Code? Open in Web Editor NEWA base model for forms.
A base model for forms.
On the review page of the multi_page example, here is the error :
Unhandled Exception
Message:
Undefined variable: foods
Location:
/Applications/MAMP/htdocs/laravel/laravel/view.php(354) : eval()'d code on line 30
Stack Trace:
#0 /Applications/MAMP/htdocs/laravel/laravel/laravel.php(40): Laravel\Error::native(8, 'Undefined varia...', '/Applications/M...', 30)
#1 /Applications/MAMP/htdocs/laravel/laravel/view.php(354) : eval()'d code(30): Laravel\{closure}(8, 'Undefined varia...', '/Applications/M...', 30, Array)
#2 /Applications/MAMP/htdocs/laravel/laravel/view.php(354): eval()
#3 /Applications/MAMP/htdocs/laravel/laravel/blade.php(71): Laravel\View->get()
#4 [internal function]: Laravel\{closure}(Object(Laravel\View))
#5 /Applications/MAMP/htdocs/laravel/laravel/event.php(199): call_user_func_array(Object(Closure), Array)
#6 /Applications/MAMP/htdocs/laravel/laravel/event.php(138): Laravel\Event::fire('laravel.view.en...', Array, true)
#7 /Applications/MAMP/htdocs/laravel/laravel/view.php(325): Laravel\Event::until('laravel.view.en...', Array)
#8 /Applications/MAMP/htdocs/laravel/laravel/view.php(546): Laravel\View->render()
#9 /Applications/MAMP/htdocs/laravel/laravel/response.php(246): Laravel\View->__toString()
#10 /Applications/MAMP/htdocs/laravel/laravel/laravel.php(138): Laravel\Response->render()
#11 /Applications/MAMP/htdocs/laravel/public/index.php(34): require('/Applications/M...')
#12 {main}
Hey Shawn,
I've been puzzling over how to add internationalised messages to the form model.
I know I can create the $messages array in the form model, but I can't pull in Lang::line function results (PHP fundamentals at issue here).
public static $messages = array(
'test_required' => 'This is a custom message that will render',
'test2_required' => __('message.this_throws_a_php_error'),
);
So I thought I'd try handling it in the __construct using something like:
public function __construct() {
$this->messages['test_required'] = __('messages.custom');
}
But this does nothing. This probably isn't an issue with the plugin itself but more a way of passing Lang returns to a static variable declared in a class.
Perhaps there's another way around it but I haven't found anything yet.
Any advice much appreciated!
Cheers,
Alex
Hey Shawn,
I've just encountered an issue using ::get().
I have a form model called RegistrationForm
In step one post I do a sample:
RegistrationForm::set('test', 0);
Then in step two get I run:
var_dump(RegistrationForm::all());
var_dump(RegistrationForm::get('test'));
And that outputs
array(1) {
["test"]=>int(0)
}
NULL
This causes me an issue using either bool or int inputs on the registration form. I can get around it at the moment by assigning RegistrationForm::all() to a variable and just picking the values from there, but it looked like an issue to me so I thought I'd post it here.
Cheers!
Alex
Hey Shawn,
Originally I was escaping inputs like name, description etc at the final form post, but I realised that this doesn't take effect until after the review stage. Now whilst the review stage is only visible to the person submitting the multi-step form I'd still prefer to escape these inputs as soon as they're submitted.
So step one user enters a html link as their name, if they go back to step one I want to have already run strip_tags and htmlentities etc on the field.
I'm not sure how to achieve this with the form base model as my post_step_one controller just lists the fields to be collected as an array.
Is it something that can be done in before_validation?
If so perhaps you could be kind enough to give a little hint as to how to do it?
Cheers!
Alex
Hi,
we just figured out that there is an error in your save_input() method of line 193 when you pass an input parameter to this method.
It should be
static::set( $field_name, array_key_exists($field_name, $input) ? $input[$field_name] : '' );
since you refer to $input on line178 (but never use $input later on)
if( is_null( $input ) )
$input = Input::all();
Above line will fix this issue.
Can you please add this to this great bundle.
Thanks,
Dennis
Hi Shawn.
I'm still enjoying the model and playing with it.
In order to make the model even more abstract and reusable, do you see a way to set default values from a DB query ?
I've tried the following but my category:all()
is returned empty.
public static $categories = array();
public function __construct()
{
echo '<pre>';
print_r(Category::all());
echo '</pre>';
static::$categories = Category::all();
}
May it be because the FormModel is called before any Database call ?
Cheers.
Not sure if this is example code or what the issue is here, but this is what I get when accessing page 2 of your multipage example.
Array to string conversion
Location:
E:\backup\xampp\htdocs\laravel\laravel\input.php on line 43
Stack Trace:
#0 E:\backup\xampp\htdocs\laravel\laravel\laravel.php(40): Laravel\Error::native(8, 'Array to string conversion', 'E:\backup\xampp\htdocs\laravel\laravel\input.php', 43)
#1 E:\backup\xampp\htdocs\laravel\laravel\input.php(43): Laravel\{closure}(8, 'Array to string conversion', 'E:\backup\xampp\htdocs\laravel\laravel\input.php', 43, Array)
#2 E:\backup\xampp\htdocs\laravel\bundles\form-base-model\formbase_model.php(186): Laravel\Input::has('favorite_foods')
#3 E:\backup\xampp\htdocs\laravel\bundles\form-base-model\controllers\examples.php(108): FormBase_Model::save_input(Array)
#4 [internal function]: Form_Base_Model_Examples_Controller->post_multi_page_example_two()
#5 E:\backup\xampp\htdocs\laravel\laravel\routing\controller.php(323): call_user_func_array(Array, Array)
#6 E:\backup\xampp\htdocs\laravel\laravel\routing\controller.php(283): Laravel\Routing\Controller->response('multi_page_example_two', Array)
#7 E:\backup\xampp\htdocs\laravel\laravel\routing\controller.php(165): Laravel\Routing\Controller->execute('multi_page_example_two', Array)
#8 E:\backup\xampp\htdocs\laravel\laravel\routing\route.php(153): Laravel\Routing\Controller::call('form-base-model::examples@(:1)', Array)
#9 E:\backup\xampp\htdocs\laravel\laravel\routing\route.php(124): Laravel\Routing\Route->response()
#10 E:\backup\xampp\htdocs\laravel\laravel\laravel.php(125): Laravel\Routing\Route->call()
#11 E:\backup\xampp\htdocs\laravel\public\index.php(34): require('E:\backup\xampp\htdocs\laravel\laravel\laravel.php')
please could you update your process for using with larave >= 5.1?
So when I use:
return Redirect::back()->with_input()->with_errors( PropertyForm::$validation );
I get no rule errors, but redirects with input
But
PropertyForm::save_input();
return Redirect::back()->with_errors( PropertyForm::$validation );
returns rule errors
Is this the way form-base-model is supposed to be used without with_input?
Thx for this great bundle.
Is this project dead ? Is there any plan on migrating it to packagist ?
The dot syntax does not work, when having HTML input arrays such as the following for example,
class User extends FormBaseModel\Base {
public static $rules = array(
'user.email' => 'required|email',
);
}
class User_Controllers extends Controller {
// ...
public function post_index()
{
if( ! User::is_valid()) {
return Redirect::back()->with_input()
->with_errors(User::$validation)
;
}
else {
// ...
}
}
}
This seems to return null
,
{{ Form::text('user[email]', User::old('user.email') }}
{{ $errors->has('user.email') ? $errors->first('user.email', '<p class="help-block">:message</p>') : '' }}
In contrast to that, this will return old input.
{{ Form::text('user[email]', Input::old('user.email') }}
{{ $errors->has('user.email') ? $errors->first('user.email', '<p class="help-block">:message</p>') : '' }}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.