laravel Method Illuminate\Validation\Validator::validateRequest does not exist - forms

when i submit a form and run form validation then it gaves me this error but my form validation is working on other page
In that file \vendor\laravel\framework\src\Illuminate\Validation\Validator.php
/**
* Handle dynamic calls to class methods.
*
* #param string $method
* #param array $parameters
* #return mixed
*
* #throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
$rule = Str::snake(substr($method, 8));
if (isset($this->extensions[$rule])) {
return $this->callExtension($rule, $parameters);
}
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
Errror= Method Illuminate\Validation\Validator::validateRequest does not exist

Maybe you wrote request instead of required? Like here:
$data = $request->validate([
'field' => 'request|string|max:255',
]);
Trying to fire validateRequest method suggest you were trying to use 'request' validation rule which doesn't exist.
All valid rules you can find here, but I think you just made a typo.

You should use a Validator facade class
In you Controller
use Validator;
See link Laravel validation

You can validate the form as below:
public function formSubmit(Request $request){
$request->validate([
'name' => 'required',
'address' => 'required',
'phone' => 'required',
]);
$customer =Customer::insert([
'name' => $request->name,
'address' => $request->address,
'phone' => $request->phone
]);
dd($customer);
echo "Data send Successfully";
}

you may try this method
$request->validate([
'sex' => ['required',Rule::in('f','m')]
]);
this one is worked for me

$request-> validate([
'name'=>'required',
'email'=>'required|email'|'unique:admins',
'password '=>'required|min:5|max:12'
After how many minutes of debugging the error was there's an extra '' in required and a space after 'password '. Please see corrected code below
$request-> validate([
'name'=>'required',
'email'=>'required|email|unique:admins',
'password'=>'required|min:5|max:12'

In my case, I forget to import Validator file and just added this line at the top of controller file where I was using Validator in function
use Illuminate\Support\Facades\Validator;
and it worked like a charm.

In my case I just misspelled required a few times.

Related

Why the Validation of my form in Livewire does'nt work?

I'm doing a form on livewire as i always did it. But tonight it decides to mess with me.
I have my protected rules, and, in order to apply them, i have the "$this->validate" as you can see it on my code.
Problem is, with "$this->validate" nothing happens, no data in my table.
When i do it without "$this->validate"...it works..but of course, the rules are not applied.
Have you an idea?
`
<?php
namespace App\Http\Livewire;
use App\Models\Demande;
use Livewire\Component;
class CreateDemande extends Component
{
public $content, $annonce,
$phone, $mail, $user_id;
protected $rules = [
'content' => 'required',
'user_id' => 'required',
];
public function store()
{
$user_id = auth()->user()->id;
$this->validate();
Demande::create([
'content' => $this->content,
'user_id' => $user_id,
]);
}
public function render()
{
return view('livewire.create-demande');
}
}
`
Maybe a trait's missing ?
I tried to create a new component and doing it again, but doesn't worked too.
I tried to pass my rules in the validation :
`
$this->validate(
[
'content' => 'required',
'user_id' => 'required',
]);
Demande::create([
'content' => $this->content,
'user_id' => $user_id,
]);
`
Is there some error on my code i can't see here?
Edit : Sorry dont know why but the "hello" i wrote on the begining don't want to show him

How to make a Symfony GET form redirect to route with parameter?

I want to create a form for searching a profile by username which redirect then to the profile page of the user. Btw, I use Symfony 3.2.
I reckon the natural way for doing this would be a GET action form. It would even allow a customer to change the url directly with the good username to see its profile.
Here is the code of my controller :
ProfileController.php
//...
/** #Route("/profil/search", name="profil_search") */
public function searchAction() {
$builder = $this->createFormBuilder();
$builder
->setAction($this->generateUrl('profil_show'))
->setMethod('GET')
->add('username', SearchType::class, array('label' => 'Username : '))
->add('submit', SubmitType::class, array('label' => 'Search'));
$form = $builder->getForm();
return $this->render('profils/profil_search.html.twig', [
'form' => $form->createView(),
]);
}
/** #Route("/profil/show/{username}", name="profil_show") */
public function showAction($username) {
$repository = $this->getDoctrine()->getRepository('AppBundle:User');
$searchedUser = $repository->findOneByUsername($username);
return $this->render('profils/profil_show.html.twig', [
'searchedUser' => $searchedUser,
]);
}
//...
This code will lead to the following error message :
Some mandatory parameters are missing ("username") to generate a URL for
route "profil_show".
I read the documentation thoroughly but couldn't guess, how can I pass the username variable to the profil_show route as a parameter ?
If my way of doing is not the good one, thanks for telling me in comments but I'd still like to know how to use GET forms.
EDIT :
Thanks to #MEmerson answer, I get it now. So for future noobs like me, here is how I did it :
/** #Route("/profil/search", name="profil_search") */
public function searchAction(Request $request) {
$data = array();
$builder = $this->createFormBuilder($data);
$builder
//->setAction($this->generateUrl('profil_show'))
//->setMethod('GET')
->add('username', SearchType::class, array('label' => 'Username : '))
->add('submit', SubmitType::class, array('label' => 'Search'));
$form = $builder->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
return $this->redirectToRoute('profil_show', array('username' => $data["username"]));
}
return $this->render('profils/profil_search.html.twig', [
'method' => __METHOD__,
'form' => $form->createView(),
'message' => $message,
]);
}
If you take a look at the error message it says that the problem is where you are trying to generate the URL for the path 'profil_show'.
Your controller annotations require that the URL be populated with a user name
/** #Route("/profil/show/{username}", name="profil_show") */
this means that Symfony is expecting http://yoursite.com/profil/show/username for the route. But if you want to pass it as a GET form posting it really should be expecting http://yoursite.com/profil/show?username
you can add a second route or change your existing route to be
/** #Route("/profil/show", name="profil_show_search") */
that should solve your problem.

TYPO3 7.6.12 Call to a member function getPage_noCheck() on string

I don't know why my Extension throws this error. Because other extensions like dd_googlesitemap use it in same way as me and this extension do not throw this error.
What am I doing wrong with my $pageId param:
/**
* Creates a link to a single page
*
* #param array $pageId Page ID
* #return string Full URL of the page including host name (escaped)
*/
protected function getPageLink($pageId) {
$conf = array(
'parameter' => $pageId,
'returnLast' => 'url',
);
$link = htmlspecialchars($this->cObj->typoLink('', $conf));
return GeneralUtility::locationHeaderUrl($link);
}
And this is the error output:
Call to a member function getPage_noCheck() on string
It is the method detectLinkTypeFromLinkParameter on line 6364.
Why do I get this error?
This error appears because the $GLOBAL['TSFE'] isnĀ“t initialized at the time I try to use it. After initialization it throws no more errors and works well.
Update:
For those who are still searching for this solution and still using typo3 7.6:
Search for the method initTSFE where it is defined on line 208 (this is the method to init the "TSFE") and where it is initialized on line 94 before getPageLink method
Here the link to the file https://ideone.com/f4TGMm
can you cast your pageUid to int like this
$conf = array(
'parameter' => (int)$pageId,
'returnLast' => 'url',
);

Zf2 multicheckbox at least one element is always required

I can't validate a zf2 form with multicheckbox because at least one checkbox is always required.
I found a lot of reference to this issue (for example here - https://github.com/zendframework/zf2/issues/4845), but i didn't found a solution for this.
Does anybody know how to solve this problem ?
UPDATE: I use a doctrine 2 objectmulticheckbox which is extended from zf2 multichechbox. As is commented below the override of getInputFilterSpecification method, will solve the problem with form validation, but the values will still remain in database (values populated by objectmulticheckbox).
I found a seemingly easier way to get around this issue by setting the input filter 'required' to false inside the controller, after the form is instantiated.
<?php
$form = new CampaignForm($multiCheckboxOptions); // Setting up checkbox in form class
$form->getInputFilter()->get('my_multi_checkbox')->setRequired(false);
?>
You can override the getInputFilterSpecification function on your form to set the field to not be required. For example:
public function getInputFilterSpecification() {
return array(
[...]
'the-multi-checkbox-field' => array(
'required' => false,
),
[...]
);
}
Ok i did a little hack to solve this problem.
So I added this code in the action controller:
$form->bind($client);
/** #var $request Request */
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
/** #var $client Client */
$client = $form->getData();
// hack because of - https://github.com/zendframework/zf2/issues/4694
if($request->getPost('reportSettings') === null){
$client->setReportSettings(null); // set null to remove all associations with this client
}
And also as it is described in the first answere, in form should be rewritten getInputFilterSpecification method, for field that shouldn't be required.

Zend_Navigation_Page and onclick attribute?

I've been asked to add some Google event tracking to a link on a site I'm 'fixing'.
This relies on the 'onclick' attribute and the ZEND framework (1.11.11) application seems to generate those links as described below.
I can't find out how to add custom attributes to this function, specifically, 'onclick'.
Is this even possible? I've never got along with Zend and any gurus out there will probably know far better than I if it's even possible.
/**
* #return Zend_Navigation_Page_Uri
*/
public function getBrochurePageUri()
{
return new Zend_Navigation_Page_Uri(array(
'label' => 'Brochure request',
'uri' => 'http://www.website.com/brochure/'
)
);
}
try adding the following:
'attribs' => array('onclick'=>'somefunction(params)')
resulting in the following:
return new Zend_Navigation_Page_Uri(array(
'label' => 'Brochure request',
'uri' => 'http://www.website.com/brochure/',
'attribs' => array('onclick'=>'somefunction(params)')
)
);