in reply to Data format verification for insertion into a database
if (data_submitted()) { @errors = validate_data(); if (@errors) { output_errors(@errors); output_form(); } else { process_data(); } } else { output_form(); }
Forms appearence, data validation and processing are VERY application specific, so I don't think that you might cheat a lot there. On the other hand, the validate_data() sub can win a lot from simplified validations. I'd say that it would be very helpful if I could do something like this (pseudo-code again):
push @errors, "Age not in range" if (!is_integer($age,5,100)); push @errors, "Ugly date format" if (!is_date($date,"YYYY-MM-DD")); push @errors, "Unknown image type" if (!is_file_type($uploaded_file, " +image/jpeg"));
|
|---|