[Proposal] Not empty HTML tags validation rule #684
Comments
What is the semantics here? Are you after content that would render into blank content in html? That would require you to parse the html, and apply html-rules (like treating style and script tags as non-rendered content), and check the resulting textContent. Another fun thing is the handling of |
hey @sisve, thanks for the reply. I knew I hadn't thought this through and glad you brought these things up. Okay, so to clear up the semantics: You can validate that the user can't submit an empty string Now, to do the same thing with a WYSIWYG editor is much harder to validate that the submitted data contains "user entered content" vs junk created by the editor. I've worked with a couple of editors that if you enter something and then clear it, it will submit:
or something similar. So I guess what I mean by Hopefully that is a little more clear, but still there is obviously issues with the things that you have raised. Don't know how I missed Perhaps a better name would be Because Laravel doesn't Route::get('/', function () {
$csrf = csrf_field();
return <<<HTML
<form method="POST">
$csrf
<input name="data" value=" ">
<input type="submit" value="Submit">
</form>
HTML;
});
Route::post('/', function () {
dd(request()->data);
}); Perhaps this is going down a rabbit hole not suitable for the core validation? But I think that initial implementation still makes sense. I want to strip all the tags, remove any whitespace (not entities) and check that it isn't empty.
Side note: I would love to hear someone's real world, in production use of the zero-width-space?!? Didn't even know that existed - TIL! |
More I think about this, as 5.5 is around the corner with custom validation objects, this is probably not really a feature that would make it into core. |
I've used a couple of WYSIWYG editors that will sometimes add empty
<p>
tags automatically - or if you had content and then clear the content, a single empty tag remains.If you try and validate the content is
required
it will be okay as Laravel won'tnull
it like it would with an empty string.What are people's thoughts on doing up a PR for a
not_empty_html
validation rule?Is there a better name?
Is there a better way already available with the core rules?
Is there a better way to do this, than my attempt?
Is this just stupid?
This is how I'm currently adding the rule to use...
The only thing I could imagine getting through that could cause weird issues would be CSS in a
<style>
tag, as it would look as if there is no content, but there is. I might have not considered all the possibilities though.The text was updated successfully, but these errors were encountered: