I am having a weird problem. I added an upload image field to a form. Every thing work fine when i use this code in the twig file
{{ form_start(form) }}
<button>d</button>
{{ form_end(form) }}
But when ever i want to use form_widget to costumize the look of the form this error appear when ever i try to sumit the form
FatalErrorException
Error: Call to a member function getFileName() on string.
This is the View that cause the problem
{% extends 'BridgeTravelBundle:Admin:layout.html.twig' %}
{% block body %}
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<form method="POST" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Nom</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
{{ form_widget(form.name, { 'attr': {'class': 'form-control', 'placeholder': 'Prenom' } }) }}
{{ form_errors(form.name) }}
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Icon</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
{{ form_widget(form.icon, { 'attr': {'class': 'form-control', 'placeholder': 'Prenom' } }) }}
{{ form_errors(form.icon) }}
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Icon</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
{{ form_widget(form.file) }}
{{ form_errors(form.file) }}
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<button class="btn btn-success">Valider</button>
</div>
</div>
</form>
</div>
</div>
{% endblock body %}
This is the Action that control the form.
public function addCategoryAction(Request $request){
$category=new Category();
$form=$this->createForm(CategoryType::class,$category);
$form->handleRequest($request);
if ($form->isSubmitted())
{
$image= $form['file']->getData();
$em=$this->getDoctrine()->getManager();
$req = $request->request->get('Bridge_TravelBundle_Category');
$category->setName($req['name']);
$category->setIcon($req['icon']);
$name = $req['name'];
try {
if(!is_dir("CategoriesPictures")){
mkdir("CategoriesPictures");
}
move_uploaded_file($image,"CategoriesPictures/".$image->getFileName());
rename("CategoriesPictures/".$image->getFileName() , "CategoriesPictures/".$name.".jpg");
}
catch (IOExceptionInterface $e) {
echo "Erreur Profil existant ou erreur upload image ".$e->getPath();
}
$em->persist($category);
$em->flush();
return $this->redirectToRoute('admin_categories');
}
return $this->render("BridgeTravelBundle:Admin:addcategory.html.twig",array('form' => $form->createView(),));
}
This the CategoryType.php
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CategoryType extends AbstractType
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name')
->add('icon')
->add('file',FileType::class, array(
'multiple' => false,
'attr' => array(
'accept' => 'image/*',
)
)
) ;
}
/**
* {#inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Bridge\TravelBundle\Entity\Category'
));
}
/**
* {#inheritdoc}
*/
public function getBlockPrefix()
{
return 'Bridge_TravelBundle_Category';
}
}
This attribute enctype='multipart/form-data' is missing from your form tag.
You should just you form_start & form_end instead writing form tag by yourself.
You can also put custom attributes with form_start function like this
{{ form_start(form, { 'attr': {'class': 'foo', 'id': 'bar' } }) }}
Also, form_end is very important because it also print out form_rest and any missing field.
<form method="POST" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">
will become
{{ form_start(form, { 'attr': { 'id': 'demo-form2', 'data-parsley-validate': null, 'class': 'form-horizontal form-label-left' } }) }}
and
</form>
will become
{{ form_end(form) }}
Related
I have a User Entity and I collect all the data in a form called Register. But once after registering, I want to edit some of the fields of a user by a form. But some fields are avoided being updated (email) and Password field is optional. I tried rendering the same register form but $form->handleRequest($request) throws an error saying:
Expected argument of type "string", "NULL" given at property path
"password".
I want to know if there is a way to do this?
I tried $form->submit($request->request->get($form->getName()),false);
instead of $form->handleRequest($request); but it didn't work.
// This is my controller.
/**
* #Route("/update/{id}", name="update")
* #param $id
* #param Request $request
* #param UserPasswordEncoderInterface $passwordEncoder
* #param UserRepository $userRepository
* #return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function updateUser($id,Request $request, UserPasswordEncoderInterface $passwordEncoder, UserRepository $userRepository){
$user = $userRepository->find($id);
$form = $this->createFormBuilder($user)
->add('email',EmailType::class,[
'label'=>'Email',
'required' => false,
'attr'=>['placeholder'=>"Email"]
])
->add('password',RepeatedType::class,[
'type' => PasswordType::class,
'invalid_message' => 'The password fields must match.',
'required' => false,
'options' => ['attr' => ['class' => 'password-field']],
'first_options' => ['label' => 'Password','attr'=>['placeholder'=>"Password"]],
'second_options' => ['label' => 'Confirm Password','attr'=>['placeholder'=>"Confirm Password"]],
])
->add('firstName',TextType::class,['label'=>'First Name', 'attr'=>['placeholder'=>"First Name"]])
->add('lastName',TextType::class,['label'=>'Last Name','attr'=>['placeholder'=>"Last Name"]])
->add('address',TextareaType::class,['required' => false,'label'=>'Address','attr'=>['placeholder'=>"Address"]])
->add('idNumber',TextType::class,['label'=>'NIC Number','attr'=>['placeholder'=>"NIC Number"]])
->add('phoneNumber',TelType::class,['label'=>'Phone Number','attr'=>['placeholder'=>"Phone Number"]])
->add('image',FileType::class,['label'=>'Photo','required'=>false,'attr'=>['hidden'=>"hidden", 'accept'=>"image/jpeg, image/png"]])
->add('save',SubmitType::class,[
'label'=>'Register',
'attr' => [
'class'=>"btn btn-outline-success float-right"
]
])
->getForm();
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
if($user->getPassword() !=""){
$user->setPassword($passwordEncoder->encodePassword($user,$user->getPassword()));
}
$em = $this->getDoctrine()->getManager();
$em->flush();
return $this->redirectToRoute('home');
}
return $this->render('register/update.html.twig', [
'form'=>$form->createView(),
]);
}
// And this is my TWIG file.
{% extends 'base.html.twig' %}
{% block title %}Edit Info{% endblock %}
{% block refHome %}{{ path('main') }}{% endblock %}
{% block body %}
<div class="container" style=" margin-left: auto;margin-right: auto;margin-top: 1cm;" >
<div class="row">
{# <div class="col-lg-2"></div>#}
<div class="col-lg-10">
<div class="card" style="width: 50rem;text-align: center;">
<div class="card-body">
<h3 class="card-title float-left">Edit Info</h3>
<div style="margin-top: 2cm;">
<p class="card-text">
<form name="register" id="register_form" method="post" enctype="multipart/form-data">
<div id="register">
<div class="container">
<div class="row">
<div class="col-sm-5">
{{ form_errors(form.firstName) }}
{{ form_widget(form.firstName) }}
</div>
<div class="col-sm-2"></div>
<div class="col-sm-5">
{{ form_errors(form.lastName) }}
{{ form_widget(form.lastName) }}
</div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div class="row">
<div class="col-sm-6">
{{ form_errors(form.email) }}
{{ form_widget(form.email) }}
</div>
<div class="col-sm-1"></div>
<div class="col-sm-5">
{{ form_errors(form.idNumber) }}
<input type="text" id="register_idNumber" placeholder="NIC Number" onkeypress="isInputNumber(event)" pattern="^[0-9]{9}[a-zA-Z]$" value="{{ form.idNumber.vars.value }}" name="register[idNumber]" required="required" class="form-control" " /> <div class="input-group-append">
</div>
</div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div class="row">
<div class="col-sm-5">
<div style="margin-top: 0.5cm;"></div>
{{ form_errors(form.phoneNumber) }}
<input type="tel" id="register_phoneNumber" value="{{ form.phoneNumber.vars.value }}" name="register[phoneNumber]" onkeypress="isPhone(event)" required="required" placeholder="Phone Number" class="form-control" pattern="^[0-9]{10}$" />
</div>
<div class="col-sm-2"></div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div class="row" >
<div class="col-sm-7">
{{ form_errors(form.address) }}
{{ form_widget(form.address) }}
</div>
<div class="col-sm-1" hidden="hidden">
{{ form_widget(form.image) }}
</div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div class="form-group row">
<div class="col-sm-7">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="defaultUnchecked" style="float: left">
<label class="custom-control-label" for="defaultUnchecked">Change Password</label>
</div>
</div>
</div>
<div style="margin-top: 0.5cm;"></div>
<div id="register_password" >
<div class="form-group row">
{% for passwordField in form.password %}
<div class="col-sm-5">
{{ form_errors(passwordField) }}
{{ form_widget(passwordField) }}
</div>
<div class="col-sm-2"></div>
{% endfor %}
</div>
<div style="margin-top: 0.5cm;"></div>
</div>
</div>
{{ form_widget(form.save,{'label':"Update"}) }}
{{ form_widget(form._token) }}
{{ form_errors(form) }}
</form>
</p>
</div>
</div>
</div>
</div>
<div class="col-lg-1"></div>
</div>
</div>
{% endblock %}
{% block javascripts %}
<script>
const checkBoxPwd = document.getElementById('defaultUnchecked');
const pwdDiv = document.getElementById('register_password');
pwdDiv.style.visibility = "hidden";
checkBoxPwd.addEventListener("change",function () {
if (checkBoxPwd.checked == true){
pwdDiv.style.visibility = "visible";
}else{
pwdDiv.style.visibility = "hidden";
}
});
</script>
<script>
function isInputNumber(eve) {
var ch = String.fromCharCode(eve.which);
if (document.getElementById('register_idNumber').value.length < 9){
if (!(/[0-9]/.test(ch))){
eve.preventDefault();
}
}else {
if (!(/[a-zA-Z]/.test(ch))){
eve.preventDefault();
}
}
if (document.getElementById('register_idNumber').value.length > 9){
eve.preventDefault();
}
}
function isPhone(eve) {
var ch = String.fromCharCode(eve.which);
if (!(/[0-9]/.test(ch))){
eve.preventDefault();
}
if (document.getElementById('register_phoneNumber').value.length > 9){
eve.preventDefault();
}
}
</script>
{% endblock %}
I am using symfony2. Actually i have created form using form type. but when i render the form, following error occurred
ContextErrorException: Catchable Fatal Error: Argument 1 passed to Symfony\Component\Form\FormRenderer::searchAndRenderBlock() must be an instance of Symfony\Component\Form\FormView
Here is my code
Controller
$profile = new profile();
$myForm = $this->createForm(new ProfileFormType(), $profile);
return $this->render('ProfileBundle:Profle:profile.html.twig', array(
'form' => $myForm,
'vendor' => $vendor,
'productId' => $productId
));
profile.twig.html
<form action="{{ path('profile_new') }}" method="POST" {{ form_enctype(form) }} id="frmProfile">
<div class="box-body col-sm-6">
<div class="form-group">
<label class="control-label">First Name: </label>
{{ form_widget(form.firstName, { 'attr': { 'placeholder': 'Title', 'class': 'form-control'}}) }}
<div class="serverError">{{ form_errors(form.firstName) }}</div>
</div>
</div>
<div class="box-body col-sm-6">
<div class="form-group">
<label class="control-label">Last Name: </label>
{{ form_widget(form.lastName, { 'attr': { 'placeholder': 'Title', 'class': 'form-control'}}) }}
<div class="serverError">{{ form_errors(form.lastName) }}</div>
</div>
</div>
<div class="box-body col-sm-6">
<div class="form-group">
<label class="control-label">User Name: </label>
{{ form_widget(form.username, { 'attr': { 'placeholder': 'Title', 'class': 'form-control'}}) }}
<div class="serverError">{{ form_errors(form.username) }}</div>
</div>
</div>
</form>
What am i doing wrong?
Replace 'form' => $myForm with 'form' => $myForm->createView(). Function createView() will create view of form object.
return $this->render('ProfileBundle:Profle:profile.html.twig', array(
'form' => $myForm->createView(), // << Add "->createView()"
'vendor' => $vendor,
'productId' => $productId
));
I am doing a web application with symfony3 and I need a way to let the users to edit and update their profile. I used FosUserBundle to manage the the users access but i don't know what steps to take to solve my problem.
Does someone have some ideas or useful links to share ?
thank you
I Solved the problem. Yes it's my first question on stackoverflow and I'm learning.
here is my code:
dogController.php
/**
* #Route("/profile/edit", name= "edit_profile" )
*/
public function edit_profileAction(Request $request)
{
$user = $this->getUser();
$form = $this->createForm(UserType::class, $user);
$form->handleRequest($request);
if ($form->isValid()) {
/** #var $userManager \FOS\UserBundle\Model\UserManagerInterface */
$userManager = $this->get('fos_user.user_manager');
$event = new FormEvent($form, $request);
$dispatcher = $this->get('event_dispatcher');
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);
$userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
//$url = $this->generateUrl('fos_user_profile_show');
$url = $this->generateUrl('edit_profile');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
$this->get('session')->getFlashBag()->add(
'notice',
'Profile Updated!'
);
return $response;
}
return $this->render('dog/edit_profile.html.twig',array('form'=>$form->createView()));
}
UserType.php
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Vich\UploaderBundle\Form\Type\VichImageType;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Form\Extension\Core\Type\FileType;
class UserType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options){
$builder->add('username')
->add('name')
->add('surname')
->add('email')
->add('telephone')
->add('imageFile', FileType::Class );
}
public function setDefaultOptions(OptionsResolverInterface $resolver){
$resolver->setDefaults( array('data_class' => 'AppBundle\Entity\User') );
}
public function getName() {
return 'appBundle_user';
}`enter code here`
}
edit_profile.html.twig
<header>
<div class="container">
<div class="row">
<div class="col-lg-12">
<h2 class="name">Edit Profile</h2>
<div class="row" >
<div class="col-lg-12">
<div class="input_width" >
{% for flashMessage in app.session.flashbag.get('notice') %}
<div class="alert alert-success alert">
{{ flashMessage }}
</div>
{% endfor %}
{{form_start(form, {'attr': {'class': 'form-horizontal'}} )}}
{{ form_errors(form) }}
<div class="form-group">
{{ form_label(form.username) }}
{{ form_errors(form.username) }}
{{ form_widget(form.username , {'attr': {'class': 'form-control'}} ) }}
</div>
<div class="form-group">
{{ form_label(form.email) }}
{{ form_errors(form.email) }}
{{ form_widget(form.email , {'attr': {'class': 'form-control'}} ) }}
</div>
<div class="form-group">
{{ form_label(form.name) }}
{{ form_errors(form.name) }}
{{ form_widget(form.name , {'attr': {'class': 'form-control'}} ) }}
</div>
<div class="form-group">
{{ form_label(form.surname) }}
{{ form_errors(form.surname) }}
{{ form_widget(form.surname, {'attr': {'class': 'form-control'}}) }}
</div>
<div class="form-group">
{{ form_label(form.telephone) }}
{{ form_errors(form.telephone) }}
{{ form_widget(form.telephone, {'attr': {'class': 'form-control'}}) }}
</div>
<div class="form-group">
{{ form_label(form.imageFile) }}
{{ form_errors(form.imageFile) }}
{{ form_widget(form.imageFile) }}
</div>
<input type="submit" value="Submit" class="btn btn-default bluInput " />
{{form_end(form)}}
</div>
</div>
</div>
</div>
</div>
</div>
</header>
Basically I had to create a form type class linked to my entity, then, use it in my controller as long as the Fos user bundle user manager.
I've created a User class in my Bundle based on FOS\UserBundle\Model\User\BaseUser to register my users.
Here is my User.php :
class User extends BaseUser
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// Constructor
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
Here is my UserType.php :
class UserType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('valider', 'submit')
;
}
/**
* #param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'CSW78\Bundle\Entity\User'
));
}
public function getParent()
{
return 'fos_user_registration';
}
/**
* #return string
*/
public function getName()
{
return 'user';
}
}
I overrode register.html.twig, putting it in /app/resources/FOSUserBundle/views/Registration and it is called.
Here is my register.html.twig :
{% block body %}
<div id="cadre" class="arrondi">
<h1>Inscription</h1>
<br>
{% block fos_user_content %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register form-horizontal">
<div id="fos_user_registration_form">
<div class="form-group">
{{ form_label(form.username, 'Identifiant :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.username, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.email, 'Email :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.email, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.plainPassword.first, 'Mot de passe :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.plainPassword.first, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.plainPassword.second, 'Mot de passe (confirmation) :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.plainPassword.second, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
{{ form_widget(form._token, {'attr': {'class': 'form-control'}}) }}
{{ form_widget(form.valider, {'attr': {'class': 'btn btn-info btn-responsive btn-color'}}) }}
{{ form_end(form) }}
</div>
</form>
{% endblock %}
</div>
{% endblock %}
The problem is there is no validation made when I click on the submit button.
I thought that the validation constraints would inherit from the BaseUser validation constraints.
Is there something else to specify to call the BaseUser validation constraints on my User object ?
Another question: what if I want to customize the error messages, should I override the validation.xml file to do that ?
Thank you.
David
I'm trying to add a new match into the database but if I purposely don't enter anything into the form, no errors are displayed. I have based this on my registration form which works perfectly. If I correctly fill out the form all data goes into the database correctly.
MatchController.php
public function postCreate()
{
$validator = Validator::make(Input::all(), Match::$rules);
if ($validator->passes())
{
$datetime = Input::get('year')."-".Input::get('month')."-".Input::get('day')." ".Input::get('time').":00";
$match = new Match;
$match->type = Input::get('match_type');
$match->associate = Input::get('associate');
$match->date = $datetime;
$match->location = Input::get('location');
$match->save();
$matchp1 = new Matchplayer;
$matchp1->user_id = Input::get('id');
$matchp1->match_id = $match->id;
$matchp1->team = 1;
$matchp1->save();
$matchp2 = new Matchplayer;
$matchp2->user_id = Input::get('opponent');
$matchp2->match_id = $match->id;
$matchp2->team = 2;
$matchp2->save();
return Redirect::to('members/matches/create')->with('message', 'Match created!');
}else{
return Redirect::to('members/matches/create')->withErrors($validator)->withInput();
}
}
Match Model (Match.php)
class Match extends Eloquent{
protected $table = 'matches';
public static $rules = array(
'match_type'=>'required',
'associate'=>'alpha|min:2'
'location'=>'required|alpha|min:2',
'team_mate2'=>'required_if:match_type,doubles',
'opponent2'=>'required_with:team_mate2'
);
}
Match Creation View (matchCreate.php)
<div class="row clearfix">
<!-- Error Message Box -->
#if(Session::has('message'))
<div class="col-md-8 col-md-offset-2">
<div class="alert alert-info">{{ Session::get('message') }}</div>
</div>
#endif
<div class="col-md-9">
<!-- Top Menu BEGIN -->
<ul class="nav nav-pills nav-justified">
<li>{{ HTML::link('members/logout', 'Profiles') }}</li>
<li>{{ HTML::link('members/logout', 'Leagues') }}</li>
<li class="active">{{ HTML::link('members/logout', 'Add Match') }}</li>
<li>{{ HTML::link('members/logout', 'Results & Fixtures') }}</li>
<li>{{ HTML::link('members/logout', 'Matchboard') }}</li>
</ul>
<!-- Top Menu END -->
<div class="page-header">
<h3>Create a Match</h3>
</div>
<div class="col-sm-6">
{{ Form::open(array('url'=>'members/matches/create', 'action' => 'post', 'class'=>'form-horizontal')) }}
{{ form::hidden('id', Auth::user()->id) }}
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Match Type</label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('match_type', '<span class="help-block">:message</span>') }}
{{ Form::select('match_type', array('singles' => 'Singles', 'doubles' => 'Doubles'), 'singles', array('id' => 'match_type', 'class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label for="gender" class="col-sm-5 control-label col-sm-pad">League Associate</label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('associate', '<span class="help-block">:message</span>') }}
{{ Form::text('associate', Input::old('associate'), array('class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Team Mate #1<br><small></small></label>
<div class="col-sm-7 col-sm-pad">
<p class="form-control-static">{{ Auth::user()->first_name." ".Auth::user()->last_name }}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Opponent #1</label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('opponent', '<span class="help-block">:message</span>') }}
{{ Form::select('opponent', $users, 'key', array('class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Team Mate #2<br><small>(Doubles Only)</small></label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('team_mate2', '<span class="help-block">:message</span>') }}
{{ Form::select('team_mate2', $users, 'key', array('class' => 'form-control input')); }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Opponent #2<br><small>(Doubles Only)</small></label>
<div class="col-sm-7 col-sm-pad">
{{ $errors->first('opponent2', '<span class="help-block">:message</span>') }}
{{ Form::select('opponent2', $users, 'key', array('class' => 'form-control input')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Date</label>
{{ $errors->first('day', '<span class="help-block">:message</span>') }}
<div class="col-lg-2 col-sm-pad">
{{ Form::selectRange('day', 1, 31, 'a', array('class' => 'form-control input input-sm dob-form-control')) }}
</div>
<div class="col-lg-2 col-sm-pad">
{{ Form::selectRange('month', 1, 12, 'a', array('class' => 'form-control input input-sm dob-form-control')) }}
</div>
<div class="col-lg-3 col-sm-pad">
{{ Form::selectRange('year', 2014, 2015, 'a', array('class' => 'form-control input-sm input dob-form-control')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Time</label>
<div class="col-lg-3 col-sm-pad">
{{ $errors->first('time', '<span class="help-block">:message</span>') }}
{{ Form::select('time', $times, 'key', array('class' => 'form-control input input-sm dob-form-control')) }}
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label col-sm-pad">Location</label>
<div class="col-sm-7 col-sm-pad">
{{ Form::text('location', Input::old('location'), array('class' => 'form-control input')) }}
</div>
</div>
{{ Form::submit('Create', array('class'=>'btn btn-success btn-block')) }}
{{ Form::token() . Form::close() }}
</div>
<div class="col-sm-6">
</div>
</div>
#include('includes.sidemenu')
</div>
routes.php
Route::post('members/matches/create', 'MatchController#postCreate');
You're creating your Validator object incorrectly. The make() method has four parameters:
/**
* Create a new Validator instance.
*
* #param array $data
* #param array $rules
* #param array $messages
* #return \Illuminate\Validation\Validator
*/
public function make(array $data, array $rules, array $messages = array(), array $customAttributes = array()) { ... }
You're passing each of your validation rules as a separate array, rather than together as one array. Subsequently, you aren't passing any of your input data, either, so it has no actual data to validate against.