Forum Moderators: coopster
if(!filter_has_var(INPUT_POST, "topic"))
{
echo("You did not enter a topic.");
}
else
function spamcheck($field)
if(isset($_POST['submitted'])) {
$error = 0;
$error += check_topic($_POST['topic']);
$error += check_email($_POST['email']);
// etc...
if($error > 0) {
print_error_msg();
} else {
// use data in useful way
}
}
// Configurables at the top, where we can find them.
$title='Post a Topic';
$errtitle='Error Posting Topic';
$successtitle=Topic Successfully Posted';
define ('MYSCRIPT', 'my-script.php');
// So we can access it without globals in functions.
// This is, after all, a constant. :-)
//
if(isset($_POST['submitted'])) {
$error = check_input();
if($error) { $output = output_form($errtitle,$error); }
else {
add_topic();
$output = output_success($successtitle);
}
}
else { $output = output_form($title); }
header("content-type:text/html");
echo $output;
exit; // retentive and optional :-)
function check_input() {
$err = null;
// here you go through all variables in global $_POST
// throw away what you don't need
// cleanse them, removing malicious characters
// if some error is found, append it to $err, for example,
// if ($_POST['some_required_field']=='') { $err .= "<li>The some_required_field is required.</li>"; }
return $err;
}
function output_form($formtitle,$errors=null) {
$form = '<form action="' . MYSCRIPT . '" method="post">';
if ($errors) {
$form .= '<p class="warning">There are errors with your input:</p><ul> . $errors . '</ul>';
}
// you know the drill, build your form
$form .= '<p><input type="submit" value="submit"></p></form>';
// A useful bit here - another function you would write
// to put $form and $formtitle into a template.
$form = insert_to_template($formtitle,$form);
return $form;
}