Comments (6)
That's the code that you use. If it's not working for you, then please show your code.
from formr.
I need code like this screenshot
from formr.
Ok, I think I understand what you want. Add this function to class.formr.php
and see if it's what you're looking for
public function error($key)
{
foreach ($this->errors as $k => $message) {
if ($key == $k) {
$this->_echo($message);
}
}
}
Then use it in your form like this
$form->text('first_name', 'First name');
$form->error('first_name');
$form->text('last_name', 'Last name');
$form->error('last_name');
from formr.
Yeah u got me right 🙌, really appreciate and one more pls can unique validation be added, I mean to check data already exist in database field
from formr.
Cool, I'll add that to the next release.
Can you give me an example of what you mean by unique validation? Normally you'd just do if($database->result == $somevariable)
, so I'm unclear how you'd use Formr to validate a database result, especially since Formr doesn't work with databases.
from formr.
This is sample class
class UniqueRule extends Rule
{
protected $message = ":attribute :value has been used";
protected $fillableParams = ['table', 'column', 'except'];
protected $pdo;
public function __construct(PDO $pdo)
{
$this->pdo = $pdo;
}
public function check($value): bool
{
// make sure required parameters exists
$this->requireParameters(['table', 'column']);
// getting parameters
$column = $this->parameter('column');
$table = $this->parameter('table');
$except = $this->parameter('except');
if ($except AND $except == $value) {
return true;
}
// do query
$stmt = $this->pdo->prepare("select count(*) as count from `{$table}` where `{$column}` = :value");
$stmt->bindParam(':value', $value);
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
// true for valid, false for invalid
return intval($data['count']) === 0;
}
}
And this is the usage
$validation = $validator->validate($_POST, [
'email' => 'email|unique:users,email'
]);
Check the library here
https://github.com/rakit/validation
from formr.
Related Issues (20)
- Getting each field error message HOT 2
- hidden elements don't work properly with fastform HOT 1
- FastForm with hush option HOT 2
- POST after form submit contains "submit" entry HOT 4
- Pass data to fastform for editing HOT 3
- upload rename HOT 1
- Regex rule confusing HOT 2
- custom_validation_messages not working HOT 1
- Method Select Menus not working HOT 1
- Honeypot HOT 3
- Honeypot browser autofill with a false "password" variable has side effects HOT 2
- info: How to limit choices on checkbox list HOT 1
- formrToken value output in sent emails HOT 2
- failed to install in laravel project HOT 1
- php 8.2 compatiblity HOT 2
- Select Multiple not working in fastform HOT 1
- Email error even when empty HOT 1
- Form fields are susceptible to XSS HOT 4
- Infinite loop in Formr::_error_message when using custom wrapper HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formr.