Spring Error during execution of processor - spring

Full error is:
Error during execution of processor
'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor'
(search:12)
My search.html page displays when I have:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<!--<meta charset="UTF-8">-->
<title>Search Users</title>
</head>
<body>
<h3>Search Users</h3>
<form th:action="#{/user/search}" th:object="${searchCriteria}" method="post">
<p>First Name: <input type="text" value="*{firstname}"/></p>
<p>Last Name: <input type="text" value="${searchCritera.lastname}"/></p>
<br/>
<input type="submit" value="search"/>
</form>
</body>
</html>
But I then changed value to th:field for *{firstname} and ${searchCritera.lastname} as below:
<form th:action="#{/user/search}" th:object="${searchCriteria}" method="post">
<p>First Name: <input type="text" th:field="*{firstname}"/></p>
<p>Last Name: <input type="text" th:field="${searchCritera.lastname}"/></p>
<br/>
<input type="submit" value="Search"/>
</form>
Now I get the error above and can't seem to fix it. I tried th:value but it throws another error:
Exception evaluating SpringEL expression: "searchCritera.lastname"
(search:12)

In general, when you're using dollar signs, use th::
<input type="text" th:value="${searchCriteria.lastname}"/>
And spell the variable name correctly.
Also include name= or th:field= as appropriate (or instead, depending on what you're trying to accomplish).

Related

Preserve values in modified object Thymeleaf

I'm creating an Object in GET method and initialize it with nulls. Then I set some values and send it to the POST method, but after this process all of values that I set earlier are nulls. How could I repair it? I've tried to use hidden fields, but it didn't help.
HTML code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet" th:href="#{/styles.css}" />
</head>
<body>
<form method="POST" th:action="#{sendorder}" th:object="${details}">
<label for="name">Name: </label>
<input type="text" th:field="*{name}"/>
<br/>
<input type="hidden" th:field="*{order}" id="order"><label for="surname">Surname: </label>
<input type="text" th:field="*{surname}"/>
<br/><label for="room">Room: </label>
<input type="text" th:field="*{room}"/>
<br/>
<br/>
<h2>Please, choose your company:</h2>
<select th:field="*{company}">
<option th:each="i : ${companies}" th:value="${i.id}" th:text="${i.name}">
</option>
</select>
</div>
</div>
<input type="submit" value="Submit Order"/>
</form>
</body>
</html>

i am using laravel for authentication , my register works but login fails when i data dump the array for password and email is empty

I am new to laravel and seem to have issues with authentication. I created a custom login page and wanted to use the auth() function to allow registration and login. Here is my login controller it shows the connection to the blade file the registration has no issues but the login is giving me problems.
When I dd() it returns an empty array, the database seems fine proved by registration.
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use auth;
class LoginController extends Controller
{
public function index()
{
return view('auth.login');
}
public function store(Request $request)
{
if(!auth()->attempt($request->only('email','password'))) {
return back()->with('status','Invalid login Details');
}
dd($request->only('email','password'));
return redirect()->route('dashboard');
}
}
```
below is the blade file responsible for submitting the form to authenticate the user I suspected the session but without it I cant check
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="google-signin-client_id" content="407063748479-dbmn68b26gcbeln4hevvcr97qnrg6hrd.apps.googleusercontent.com">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://kit.fontawesome.com/64d58efce2.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="../assets-Authenticate/css/RegistrationStyling.css" />
<title>Sign in & Sign up Form</title>
</head>
<body>
<div class="container">
<div class="forms-container">
<div class="signin-signup">
#if (session()->has('status'))
{{ session('status') }}
#endif
<!--Sign In Form-->
<form action="{{route('login')}}" class="sign-in-form" method="POST">
#csrf
<h2 class="title">Sign in</h2>
<div class="input-field">
<i class="fas fa-user"></i>
<input type="text" placeholder="User Email" required />
</div>
<div class="input-field">
<i class="fas fa-lock"></i>
<input type="password" placeholder="Password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters"/>
</div>
<input type="submit" value="Login" class="btn solid" />
<div class="reset">
Forgot Password ?
</div>
</form>
```
You forgot to add a name to your inputs try:
<input type="password" name="password" placeholder="Password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters"/>
And
<input type="text" name="email" placeholder="User Email" required />
You can't run auth without adding a name use this code in the input tag instead.
<input type="password" name="password" placeholder="Password"
required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"
title="Must contain at least one number and one uppercase and lowercase
letter, and at least 8 or more characters"/>
<input type="text" name="email" placeholder="User Email" required />

How to submit Laravel VueJS dynamic form data?

I am new to Vue.js. I am trying to make a form dynamic (only a certain part of the form dynamic.). A user can have multiple guarantors. So I made the Guarantor form Dynamic with VueJS. When I submit the form and return the request, I see only the last array. Its always the last array, all others are lost.
This is the blade file.
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{ asset('css/app.css')}}">
<title>Laravel</title>
</head>
<body>
<div id="app">
<div class="container pt-5">
<form action="{{ route('submit.store')}}" method="post">
#csrf
<div class="card-body">
<h4 class="card-title">User Detail</h4>
<input type="text" class="form-control mb-1" name="user_name" id="user_name" placeholder="Name" />
<input type="email" class="form-control mb-1" name="user_email" id="user_email"
placeholder="Email" />
<textarea name="about" class="form-control" id="about" cols="30" rows="10"
placeholder="About"></textarea>
</div>
<dynamic-form></dynamic-form>
</form>
</div>
</div>
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
And this is how the VueComponent looks.
<template>
<div>
<button class="btn btn-success mb-3" #click.prevent="addNewUser">Add User</button>
<div class="card mb-3" v-for="(user, index) in users" :key="index">
<div class="card-body">
<span class="float-right" style="cursor:pointer" #click.prevent="removeForm(index)" >X</span>
<h4 class="card-title">Guarantor No: {{ index }}</h4>
<input type="text" class="form-control mb-1" name="name" id="name" placeholder="Name" v-model="user.name" />
<input type="email" class="form-control mb-1" name="email" id="email" placeholder="Email" v-model="user.email"/>
<textarea name="about" class="form-control" id="about" cols="30" rows="10" placeholder="About" v-model="user.about"></textarea>
</div>
</div>
<input type="submit" class="btn btn-primary" value="submit">
</div>
</template>
<script>
export default {
name: 'dynamic-form',
data() {
return{
users: [
{
name: '',
email: '',
about: ''
}
]
}
},
methods: {
addNewUser: function() {
this.users.push({
name: '',
email: '',
about: ''
});
},
removeForm: function(index) {
this.users.splice(index, 1);
}
}
}
</script>
How can I tackle this problem?
In PHP, values with the same name attribute value will get overwritten. (See the "How do I get all the results from a select multiple HTML tag?" section here).
You can create arrays of values by adding a bracket to the name. For example, if you made the name of the "name" input name[], name will be an array of names in PHP.
In your case, you could use this format: name="guarantors[][name]". That way you will get an array in PHP under the key guarantors (e.g. $request->guarantors) and each of the values in guarantors will be an array with the values name, email, etc.

Get value of hidden field in form

Here is my login form with hidden field name "callbackUrl". How can i get the value of this hidden field in controller? User's attributes are username and password. callbackUrl is not.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="/resources/css/bootstrap.min.css" rel="stylesheet">
<link href="/resources/css/common.css" rel="stylesheet">
<title>Authentication Service</title>
</head>
<body>
<form method="POST" action="/login" modelAttribute="userFormLogin" class="form-signin">
<h2 class="form-heading">Log in</h2>
<input name="username" type="text" class="form-control" placeholder="Username"
autofocus="true"/>
<input name="password" type="password" class="form-control" placeholder="Password"/>
<input name="callbackUrl" type= "hidden" id="callbackUrl">
<h2>${error}</h2>
<br/>
<button class="btn btn-lg btn-primary btn-block" type="submit">Log In</button>
<h4 class="text-center">Create an account</h4>
</form>
</body>
<script>
var url_string = window.location.href; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("callbackUrl");
console.log(c);
document.getElementById("callbackUrl").value = c;
</script>
</html>
add #RequestParam("callbackUrl") String callBackUrl to the method in your controller.
Like so:
public String myMethod(#RequestParam("callbackUrl") String callBackUrl, …) {
System.out.println(callBackUrl); //this will print the url to console
}

POST method not working in laravel 5

**THIS is my code for form creation and action is set to post but it is showing error "tokenmismatchexception in verifycsrftoken.php line 53 laravel 5.1";
<html>
<body>
<form action="/abc" method="post">
<b style="padding-right:110px;">Patient's Name:</b>
<input type="text" name="fullname" required><br><br>
<b style="padding-right:50px;">Required Blood Group:</b>
<option>A+</option>
<select>
<option>B+</option>
<option>AB+</option>
<option>O+</option>
<option>A-</option>
<option>B-</option>
<option>AB-</option>
<option>O-</option>
</select><br><br>
<input
type="submit"
style="position:absolute;right:170px;"
name="submit"
value="Request">
</form>
</body>
</html>
You need to include the CSRF token in your form data. Add:
<input type="hidden" name="_token" value="{{ csrf_token() }}">
right after your opening form tag.

Resources