404 NOT FOUND with LARAVEL6 [duplicate] - php

This question already has an answer here:
404 Not found with laravel 6
(1 answer)
Closed 2 years ago.
i have a problem while passing a variable into the URL , the route exists but still" 404 NOT FOUND" .
Form :
<form action="/rdv_{{$go->ID}}" method="post" role="form" data-aos="fade-up">
#csrf
<input placeholder="Email" type="email" class="form-control" name="email" id="email" />
<input placeholder="Votre numéro de téléphone " type="text" class="form-control" name="tel"
id="subject" />
<div id="buttons">
<button type="submit" class="btn btn-primary"> Prendre un rendez-vous </button>
</div>
</form>
Controller :rendezv.php:
public function rdv ($ID) {
$nm=request('email');
$tel=request('tel');
$ID=request('{{$go->ID}}');
$doctor=doc::findOrFail($ID);
$rdv = new rendezvous() ;
$rdv->Email=$nm;
$rdv->Numéro_de_téléphone=$tel;
$rdv->IDD=$doctor->ID;
$rdv-> save();
return redirect('/index') ;
}
}
Web.php
Route::post('/rdv_{ID}','rendezv#rdv');
The error is only "404 | Not Found". When I click the button for " Prendre un rendez-vous" the address became: " http:/ /localhost:8000/ rdv_1032569" and the error is probably there.

I re-modified the code as follows:
View: I updated the form action and added an hidden input field which has the value "$go-ID".
<form action="/rdv" method="post" role="form" data-aos="fade-up">
#csrf
<input placeholder="Email" type="email" class="form-control" name="email" id="email" />
<input placeholder="Votre numéro de téléphone " type="text" class="form-control" name="tel" id="subject" />
<input type="hidden" class="form-control" name="goID" value="{{$go->ID}}" />
<div id="buttons">
<button type="submit" class="btn btn-primary"> Prendre un rendez-vous </button>
</div>
</form>
Controller: I assumed that $go->ID in the view is the same as $doctor->ID in the controller. So, I assigned the value of $rdv->IDD to be $ID;
public function rdv () {
$nm=request('email');
$tel=request('tel');
$ID=request('goID');
$rdv = new rendezvous() ;
$rdv->Email=$nm;
$rdv->Numéro_de_téléphone=$tel;
$rdv->IDD=$ID;
$rdv-> save();
return redirect('/index') ;
}
Route: I removed '_{ID}' from the route.
Route::post('/rdv','rendezv#rdv');

The error is most likely from this $doctor=doc::findOrFail($ID);
If there's no doc model with the ID specified, laravel automatically returns a 404.
To change this behaviour, use find() and handle the return manually e.g
$doctor=doc::find($ID);
if(!$doctor) {
// return here
}

Change route
Route::post('/rdv/{ID}','rendezv#rdv')->name('rdv');
and form route
actions="{{ route('rdv', [$go->ID]) }}"

Related

Action route Prestashop FORM 1.7.x

I find myself learning to develop modules in PrestaShop but not capturing data from a form to work on it in the back
<form action="{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}" method="post">
<fieldset class="form-group">
<div class="form-group form-group-lg">
<label class="form-control-label" for="input2">Ingresa tu codigo de seguimiento</label>
<textarea required name="comment" class="form-control" id="comment"></textarea>
</fieldset>
<br>
<input type="submit" class="btn btn-primary" value="Buscar">
</div>
This is the function where it should receive the data but I don't know why it doesn't work.
public function getWidgetVariables($hookname, array $configuration){
if(Tools::isSubmit('comment')){
return Tools::getAllValues();
}
}
What am I doing wrong? (im using xampp to run in local)

Laravel does not show errors when there are many errors. It,s Bug?

Duplicate of https://github.com/laravel/framework/issues/31123
Laravel Version: 6.8.0 ,6.10.1
PHP Version: 7.4
Languages from https://github.com/caouecs/Laravel-lang
Description:
For some languages, when validated errors too much, errors not show in blade (not send in session)
Language example: ru (not show >=6 errors), si (not show >=8 errors) in my code.
Steps To Reproduce:
New laravel 6 app + https://github.com/caouecs/Laravel-lang
conf/app.php
locale' => 'ru',
// locale' => 'si',
View:
#extends('layouts.app')
#section('content')
<div class="container">
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form" method="post" action="{{route('testvalid')}}">
#csrf
<input class="form-control" name="field1" />
<input class="form-control" name="field2" />
<input class="form-control" name="field3" />
<input class="form-control" name="field4" />
<input class="form-control" name="field5" />
<input class="form-control" name="field6" />
<input class="form-control" name="field7" />
<input class="form-control" name="field8" />
<input class="form-control" name="field9" />
<input class="form-control" name="field10" />
<input class="form-control" name="field11" />
<input type="submit" class="btn btn-primary">
</form>
</div>
#endsection
Action:
public function testvalidpost(Request $request){
$request->validate([
'field1'=>['required'],
'field2'=>['required'],
'field3'=>['required'],
'field4'=>['required'],
'field5'=>['required'],
'field6'=>['required'],
'field7'=>['required'],
'field8'=>['required'],
'field9'=>['required'],
'field10'=>['required'],
'field11'=>['required'],
]);
echo ok;
}
Try to set SESSION_DRIVER=file to get it work
See related

Show custom error message

I'm trying to show errors in form validation.
But these messages are always visible.
<form name="user-form" method="POST" action="{{route('registrationUser')}}">
<div class="col-lg-8">
Логин <input type="text" name="log" ng-model="mobile" required pattern="[a-zA-Z ]*"><br>
<span class="help-block" ng-show="errors.log[0]"><p>Только английский</p></span>
</div>
Пароль <input type="text" name="pass" ng-minlength="8" ng-pattern="regex" required pattern="[a-zA-Z]{8,32}" ><br>
<div ng-show="user-form.pass.$error.pattern">Name doesn't match pattern!</div>
<button ng-click='SaveUser()' name="Регистрация">Регисрация</button>
</form>
you can add another condition to ng-show
<div ng-show="user-form.pass.$error.pattern && buttonclicked">Name doesn't match pattern!</div>
and set that condition to true in your controller
$scope.SaveUser= function () {
$scope.buttonclicked = true;
};
so error messages will be visible only when user clicks on submit button

Multiple form authentication in the same domain

I have a website with two form authentication in different pages, have different input name and link to different pages . The problem is that when I save my authentication to a browser (chrome) of a form , the browser fill in the fields with the same data in the other form . How is it possible?
First form
<form action="" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input type="email" name="private_email" class="form-control" id="email1" value="" placeholder="Enter email" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" name="private_password" value="" id="password1" placeholder="Password" required>
</div>
<input type="submit" name="login" class="btn btn-default" value="Login">
</form>
Second Form (It is a form of a cms)
<form action="http://escuolainsieme.it/shop/login" method="post" id="login_form" class="box">
<h3 class="page-subheading">Sei già registrato?</h3>
<div class="form_content clearfix">
<div class="form-group form-ok">
<label for="email">Indirizzo email</label>
<input class="is_required validate account_input form-control" data-validate="isEmail" type="text" id="email" name="email" value="">
</div>
<div class="form-group">
<label for="passwd">Password</label>
<span><input class="is_required validate account_input form-control" type="password" data-validate="isPasswd" id="passwd" name="passwd" value=""></span>
</div>
<p class="lost_password form-group">Hai dimenticato la password?</p>
<p class="submit">
<input type="hidden" class="hidden" name="back" value="my-account"> <button type="submit" id="SubmitLogin" name="SubmitLogin" class="button btn btn-default button-medium">
<span>
<i class="icon-lock left"></i>
Entra
</span>
</button>
</p>
</div>
</form>
Login.php
<?php session_start(); // Starting Session
$error = ''; // Variable To Store Error Message
if (isset($_POST['private_login'])) {
if (empty($_POST['private_email']) || empty($_POST['private_password'])) {
$error = "<div class='alert alert-danger'>Compila tutti i campi</div>";
} else {
$email = mysqli_real_escape_string(conn(), $_POST['private_email']);
$password = mysqli_real_escape_string(conn(), $_POST['private_password']);
$cls_utente = new utente();
if ($cls_utente->check_user($email, $password) == 1) {
$_SESSION['login_user'] = $email; // Initializing Session
$_SESSION['is_logged'] = true;
} else {
$error .= "<div class='alert alert-danger'>Email o password errati</div>";
}
}}?>
You can try using autocomplete="false" or autocomplete="off" to disable it, not sure if it will work but give it a try.
As far as i am concerned it's not possible to make the browser 'realize' that they are different forms and they should not be auto-filled with the same data.
Have a look at these 2 answers, answer1 answer2 for more information how browser detects the forms.
You must add another one column in your user table, example if you add type column the value set default super admin,moderator, user. Now you can check the login authentication with this column.If user-name and password and type is equal redirect to particular page.so you can redirect different page depends upon the user type..

Change Symfony2 FOSUserBundle registration form POST parameters?

This is how the registration form of FOSUserBundle looks like:
<form action="/Symfony/web/signup/" method="POST" class="fos_user_registration_register">
<div id="fos_user_registration_form">
<input type="hidden" id="fos_user_registration_form__token" name="fos_user_registration_form[_token]" value="c248f3ef17b082803ae9948c03d137c380f0dc24"/>
<div>
<label for="fos_user_registration_form_username">Username:</label><input type="text" id="fos_user_registration_form_username" name="fos_user_registration_form[username]" required="required" maxlength="255" pattern=".{2,255}"/>
</div>
<div>
<label for="fos_user_registration_form_email">Email:</label><input type="email" id="fos_user_registration_form_email" name="fos_user_registration_form[email]" required="required"/>
</div>
<div>
<label for="fos_user_registration_form_plainPassword_first">Password:</label><input type="password" id="fos_user_registration_form_plainPassword_first" name="fos_user_registration_form[plainPassword][first]" required="required"/>
</div>
<div>
<label for="fos_user_registration_form_plainPassword_second">Verification:</label><input type="password" id="fos_user_registration_form_plainPassword_second" name="fos_user_registration_form[plainPassword][second]" required="required"/>
</div>
</div>
<div>
<input type="submit" value="Register"/>
</div>
So, as you can see,
<input type="email" id="fos_user_registration_form_email" name="fos_user_registration_form[email]"
MAIN QUESTION: How can I change the id to something like id="email" and also the name to something like name="email"? And it has to work, obviously.
Here you can see: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/views/Registration/register_content.html.twig {{ form_widget(form) }}, but I can't trace this to where it goes. I also presume the RegistrationFormHandler would have to be edited to support these parameters.
Alter buildForm function in RegistrationFormType class:
# FOSUserBundle/Form/Type/RegistrationFormType.php
class RegistrationController extends ContainerAware
{
// ...
public function getName()
{
return 'fos_user_registration';
}
}
Change fos_user_registration to whatever you want.

Categories