Unobtrusive PHP ?

Strange?

What do you say if we use this term for a form validation, server side? I say “Unobrusive PHP” because it’s what I work with, but it can be any other language.

Let me explain

We already do this in Javascript. We attach a class to a field we want to validate, then, when the user try to submit, we try to validate the input by a rule associated to the class. All is fine, only that we need to make this server-side too, we cannot trust the users, do we?

So what if to the input name we attach a specific segment, that will be validated once it reach the server, removes the attachment, and pass further the data like never happened?

Some code

<input type="text" name="email" />

for js validation would be

<input type="text" name="email" class="email"/>


for php would be

<input type="text" name="email___email" />

and the validation class would take the $_POST array, search for a value  that contains ___email, validates it, then simple remove the segment for further processing.

$_POST["emai"] = $_POST["email___email"];

This idea is the preamble of a future post regarding a more  universal validator for forms. It’s only a concept. Let me now your thoughts.