I’ve used PHP for basic procedural coding, and I’d like to start using an object-oriented approach. I get the syntax, and I get the concept, but I’m having trouble translating it to the real world. So suppose you have a basic form that you validate and then save. With a procedural approach, you’d do something like this (pseudocode with a PHP flavor).
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
validate form
if ($no_errors == TRUE) {
save form data
$form_message = 'some confirmation message';
}
else {
$form_message = 'some error message';
}
}
else {
//must be first time through
$form_message = 'hello, please fill this out';
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Customer Form</h1>
<h2><?= $form_message ?></h2>
<form method="post">
<field 1>
<field 2>
<field 3>
<field 4>
</form>
</body>
</html>
So, PHP coders more advanced than me, how would you use OOP for the above? To clarify, I’m not looking for a general form processing engine. That’s way too complex for now. I’m just looking to translate the above into the OOP paradigm. Thanks!