Question

I want to make a reusable form validation system, similar to something that would be implemented in Javascript. Ideally I could use things like class names or input types from form elements to decide what validation tests to apply.

Is there a way to implement this in PHP? That is: Is there anyway to get a hold of these HTML attributes on the server-side?

Was it helpful?

Solution

Yes, see DOMDocument. But I'm not sure I would recommend it based on what you're trying to do, as that could get pretty ugly.

I had a similar idea and asked on StackExchange a while back.

OTHER TIPS

Try getting the input through $_POST['field_name'] and loop through the array given by wesly murch. Add switch statements like if arraykey=required // doo something arraykey=minlength=> //do something

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top