programmieren:html:forms
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| programmieren:html:forms [2026/08/12 10:23] – flash meshuggas trust admin | programmieren:html:forms [2026/09/03 14:56] (current) – Mistakes admin | ||
|---|---|---|---|
| Line 70: | Line 70: | ||
| <?php endif ?> | <?php endif ?> | ||
| </ | </ | ||
| + | |||
| + | The validation rules I made: | ||
| + | <code php> | ||
| + | if (strlen($post[' | ||
| + | session_start(); | ||
| + | $_SESSION[' | ||
| + | |||
| + | header(' | ||
| + | exit; | ||
| + | } | ||
| + | |||
| + | if (!preg_match('/ | ||
| + | session_start(); | ||
| + | $_SESSION[' | ||
| + | |||
| + | header(' | ||
| + | exit; | ||
| + | } | ||
| + | |||
| + | if (!preg_match( | ||
| + | '/ | ||
| + | $post[' | ||
| + | ) | ||
| + | || strlen($post[' | ||
| + | session_start(); | ||
| + | $_SESSION[' | ||
| + | |||
| + | header(' | ||
| + | exit; | ||
| + | } | ||
| + | |||
| + | if (!date_parse_from_format(' | ||
| + | session_start(); | ||
| + | $_SESSION[' | ||
| + | |||
| + | header(' | ||
| + | exit; | ||
| + | } | ||
| + | |||
| + | if (strlen($post[' | ||
| + | session_start(); | ||
| + | $_SESSION[' | ||
| + | |||
| + | header(' | ||
| + | exit; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== 3rd Iteration ==== | ||
| + | |||
| + | In the 3rd Iteration I simply added saving the data put into the form to the Database: | ||
| + | |||
| + | <code php> | ||
| + | public function savePostData($post): | ||
| + | { | ||
| + | $servername = " | ||
| + | $username = " | ||
| + | $password = ""; | ||
| + | $dbname = " | ||
| + | |||
| + | $conn = new mysqli($servername, | ||
| + | |||
| + | if ($conn-> | ||
| + | die(" | ||
| + | } | ||
| + | |||
| + | $sql = " | ||
| + | |||
| + | $stmt = $conn-> | ||
| + | if ($stmt) { | ||
| + | $stmt-> | ||
| + | |||
| + | $name = $post[" | ||
| + | $email = $post[" | ||
| + | $phone = $post[" | ||
| + | $birthday = $post[" | ||
| + | $message = $post[" | ||
| + | |||
| + | $stmt-> | ||
| + | } else { | ||
| + | echo " | ||
| + | } | ||
| + | |||
| + | $stmt-> | ||
| + | $conn-> | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | And displaying all entries in the index as a list: | ||
| + | |||
| + | <code php> | ||
| + | public function displayAllEntries(): | ||
| + | { | ||
| + | $servername = " | ||
| + | $username = " | ||
| + | $password = ""; | ||
| + | $dbname = " | ||
| + | |||
| + | $conn = new mysqli($servername, | ||
| + | |||
| + | if ($conn-> | ||
| + | die(" | ||
| + | } | ||
| + | |||
| + | $sql = " | ||
| + | $result = $conn-> | ||
| + | |||
| + | if ($result-> | ||
| + | while($row = $result-> | ||
| + | echo 'Name: ' . htmlspecialchars($row[' | ||
| + | } | ||
| + | } else { | ||
| + | echo "0 results"; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Mistakes ==== | ||
| + | |||
| + | Code style: | ||
| + | |||
| + | * Apperantly I had too much repetitive code | ||
| + | * Making it object oriented was good | ||
| + | |||
| + | Functionality: | ||
| + | |||
| + | * Apperantly it was just barely reached, no explanation as to why. | ||
| + | * I couldve done better validation | ||
| + | * I couldve displayed multiple validation messages for all that was wrong | ||
| + | * I couldve used PHP native validation functions | ||
| + | * I couldve positioned the Form better | ||
| + | |||
| + | Presenting: | ||
| + | |||
| + | * I was unprepared | ||
| + | * I didn't answer many questions | ||
| + | * There were some incidents with the streaming so that was bad blegh | ||
programmieren/html/forms.1786523018.txt.gz · Last modified: by admin
