Laravel Post method is not working because of the special characters - laravel

I am facing a very abnormal situation here.
Below are the image of simple HTML form, with input type files and text and text area.
<form method="POST" action="{{ route('vendor.package.store') }}" enctype="multipart/form-data">
{!! csrf_field() !!}
<input type="text" class="form-control" id="title" name="package_name" value="{{ old('title')) }}" required>
</form>
When I enter "On-The-Day (OTD) Vacation In Bali Island", and hit "Submit Button", Laravel redirect me to the index page, means the below function does not trigger at all.
public function store(Request $request){
return $request->all();
}
So, I tried to answer enter "(OTD)" & "On-The-Day", Laravel redirect me to the store function
But whenever I tried to enter "On-The-Day (OTD)", fails.
When I try to enter "-Day (OTD)", fails
When I try to enter "-DaZ (OTD)", success.
P/S: my local development can accept On-The-Day (OTD) Vacation In Bali Island, only in production side cannot process the word.
Appreciate if you could help

Related

How to keep the fields of a form after being redirected by login or registration in Laravel?

The business logic is as follows:
Fill out the form to publish a card.
Click on publish card button.
Publish if only if the user is authenticated.
If you are not authenticated, request to log in with the option to register.
If the user is registered or logged in, redirect to the form keeping the fields filled.
This is the logic of what I want to do
Note:
I currently show the login view if it is not authenticated with the help of laravel's Authentication Middleware.
The login view has the option to register.
I do not have much experience in laravel, I would like you could be explicit in your answer.
Try this one
<input type="text" class="form-control" placeholder="Name" name="name" required value="{{ old('name') }}">
this keep old value when you return page.
if you want redirect page with data, use Compact.
for example
$data["name"] = "name"
$data["gender"] = "something"
return view('your blade file path', compact('data'));
and on blade file
<input type="text" class="form-control" placeholder="Name" name="name" required value="{{ $data['name'] }}">

Append data to form using through DOM?

Form which uses POST method:
<div>
<form action="{{ route('post.store') }}" method="POST">
<input type="text" name="name">
<input type="text" name="text">
<button type="submit">Submit</button>
</form>
#foreach ($comments as $comment)
{{ $comment->text }}
Reply
#endforeach
</div>
Array of $comments is being returned when the view itself is returned.
Basically, I am intrested if there is a way to append $comment->id to the data that will be sent to server on Submit button click using Laravel Blade or AlpineJS, but without creating any additional functions between <script> tags? I mean, is it possible to do something like this: Reply?
EDIT:
I expressed myself wrongly. I don't want to append new id every time Reply is clicked, but to overwrite corresponding property in data which is going to be sent to server when Submit button is clicked with the $comment->id for which Reply was clicked for.
I assume you are using Laravel Resource Controller
Not sure I totally understand why you want to send all comment ids when submitting the form but when calling the route post.store you should better send the post id
<form action="{{ route('post.store', ['post' => $post]) }}" method="POST">
If you want to get all comment id and have proper model relationships set up in your models you can get all comments for a post in your controller.
To send a specific id in your form create a new <input name="comment_id" value=""> and let that field be populated.

Laravel - CSRF Token Mismatch - Header Token gets regenerated

I'm struggeling the last 2 weeks on the following problem:
First of all my problem only occours when I try to deploy my current Laravel (6.11) project on the live server. On my Localhost everything works fine.
In every FORM I used the #csrf tag to set the token as well as the meta tag in the head section of my page. If I search into the developer tool in Chrome the tokens in head and form match perfectly. When the POST request gets sent I get an 419 Page Expired error. I figured out that the HEAD token gets recreated on each request so a token mismatch occours.
I already tried the following things:
Diffrent syntax of the csrf tag
I excepted all FORMS in the VerifyCsrfToken.php - these ended up in a redirect to my index.php without submited form
I checked all Laravel config settings which were recommended in diffrent Forum Posts
I tried a empty laravel installation with a basic login setup on my server - This worked
I currently work with git. On the a previous commit version (16th of december) which I uploaded to my server on that exact Date I had no problem at all but when I tried to reupload the exact same git commit date, the same problem happens.
Greatings Max
If you need any code I'll upload here.
Controller:
function fakeAuthentifizierung(Request $request){
$username = $request->input('benutzernameLogin');
$password = $request->input('passwortLogin');
session(['key' => 'mt171043']);
session(['eingeloggt' => true]);
/*****
* ABFRAGE ADMINRECHTE
* BITTE DIESEN TEIL SPÄTER IN ECHTE AUTHENTIFIZIERUNG ÜBERNEHMEN
*
*/
$admin = false;
// SPÄTER BENUTZERID AUS LOGIN SESSION ÜBERGEBEN
// astmedin5 als TESTZWECK
$rechte = Benutzer::getBenutzerBerechtigung("astmedin5");
//Berechtigung Abfragen
if($rechte->name != 'Student' && 'Lehrbeauftragter'){
session(['admin' => true]);
}else{
session(['admin' => false]);
}
/***
*
* ABFRAGE ENDE
*/
return redirect(route('index',app()->getlocale()));
}
View:
<form method="POST" action="{{ action('LoginController#FakeAuthentifizierung', app()->getLocale()) }}">
#csrf
<h1>{{ __('Login') }}</h1>
<label class="col" for="benutzernameLogin">{{ __('Benutzername') }}</label>
<input name="benutzernameLogin" id="benutzernameLogin" class="inputLogin col mb-4" type="text"
aria-label="Text input with checkbox" placeholder="{{ __('Benutzername') }}" required>
<label class="col" for="passwortLogin">{{ __('Passwort') }}</label>
<input name="passwortLogin" id="passwortLogin" class="inputLogin col mb-4" type="password"
aria-label="Text input with checkbox" placeholder="{{ __('Passwort') }}" required>
<div class="col-8 float-left">
<input id="checkboxPasswortAnzeigen" type="checkbox">
<label for="checkboxPasswortAnzeigen">{{ __('Passwort anzeigen') }}</label>
</div>
<button type="submit" class="btn-slash col-3 inverted fontLight float-right">{{ __('Login') }}</button>
</form>

Laravel 5.3 Form post error session store not set on request

I have a public view with a form. To access the form my route is admin.new_athlete when I post the form the action calls admin.create_athlete
I have this statement in form {{ csrf_field() }} just before the first label. This is after the submit button <input type="hidden" name="_token" value="{{ Session::token()}}">
Attached is web.php and controller.
Please advise on the error.

How to populate edit form fields in laravel 5.3

I have a problem in populating edit form fields in my first Laravel 5.3 application. In examples I have found online, they have used Form facade to do it. However, I prefer to use plain html.
This is my controller action
public function edit()
{
$profile = Profile::find(Auth::user()->id);
return view('profile.edit', ['profile' => $profile]);
}
In my view file I have a form like this
<form method="POST" action="{{ url('profile/update') }}">
{{ csrf_field() }}
<input id="name" type="text" name="name" value="{{ old('name') }}">
...
</form>
Problem is, above input field is not populated with the value of the $profile->name.
I can get it to work, setting the value attribute like
{{ (old('name')) ? old('name') : $profile->name }}
Since I'm new to Laravel framework I want to know if there is a better way to do that.
Use old($key, $default). It will return $default if $key is not found.

Resources