I'm beginning to believe that nobody actually knows how to validate simple forms and insert that validation code into a dreamweaver page.

I there anybody out there who believes they can accomplish this. If so, are you prepared to help me accomplish this, at which time we could post here a relevant tutorial/explanation.

I have been playing around with preg_match and preg_match_all, along with various regexpressions but they do not seem to give the expected results.

Dani AI

Generated

raised the common issue that PHP regexes often do not behave as expected, and suggested reading material. Below is a concise, practical approach that fits into a Dreamweaver workflow and shows why preg_match/preg_match_all are frequently misused.

A minimal server-side validation flow: trim inputs, check required fields, validate with built-ins where possible, then use regex only when a pattern is really needed. filter_var is the preferred validator for emails and URLs; regex should be anchored and use the correct modifiers. preg_match_all counts/fills matches and is not a substitute for whole-string validation — use preg_match with ^ and $ for that.

Example skeleton (place processing at top of a .php page before any output):

<?php
$errors = [];
$name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
if ($name === '') {
$errors[] = 'Name is required';
} elseif (!preg_match('/^[\p{L} \'-]{1,100}$/u', $name)) {
$errors[] = 'Invalid name';
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Invalid email';
}
if (empty($errors)) {
// sanitize for output with htmlspecialchars() and insert using prepared statements
}
?>

Dreamweaver notes: save pages with a .php extension, edit PHP in Code view or use editable regions in templates, and either post the form to the same script or to a dedicated processor. Avoid relying solely on Dreamweaver GUI helpers; they may produce code that needs manual review.

Security and reference notes: prefer prepared statements for DB inserts and escape output with htmlspecialchars. See the PHP docs for filter_var and preg_match, the PDO prepared-statement docs at PDO prepared statements, and OWASP guidance on input validation at OWASP Input Validation Cheat Sheet.

Recommended Answers

All 3 Replies

Try and buy/rent the book "How to do everything PHP MYSQL" By Vikram Vaswami. It has a chapter on validating form input in the way you ask

Well done jbennet. You could post your answer to any question in this php section. A simple 'No' would have been quite sufficient.

the answer is yes, im saying its in that book, because i have it but cant be bothered typing the source onto this site as its like 3 pages of code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.