I have now managed to get server-side validation to work using Ben's solution. Integrated into my code (which only creates database entries when the form is submitted) Ben's solution looks like this...
And just above the form...
The only difference is that I have used the following PHP in the form...
...instead of as in the online examples...
PHP Code:
<?php
require_once("/httpdocs/formtools/global/api/api.php");
if(isset($_POST['form_submitted']))
{
$fields = array();
$rules = array();
$errors = array();
$rules[] = "required,fm_name,Please enter your name.";
$rules[] = "required,fm_email,Please enter your email address.";
$rules[] = "valid_email,fm_email,Please enter a valid email address.";
$rules[] = "required,fm_subject,Please enter a subject.";
$rules[] = "required,fm_message,Please enter a message.";
$errors = validate_fields($_POST, $rules);
if(empty($errors))
{
$fields = ft_api_init_form_page(1);
$params = array(
"submit_button" => "form_submitted",
"next_page" => "thank-you.php",
"form_data" => $_POST,
"finalize" => true
);
ft_api_process_form($params);
$fields = array_merge($fields, $_SESSION["form_tools_form"]);
}
else
{
$fields = array_merge($fields, $_POST);
}
}
?>
And just above the form...
PHP Code:
<?php
if(!empty($errors))
{
echo "<div class='error'>Please fix the following errors:\n<ul>";
foreach($errors as $error)
{
echo "<li>$error</li>\n";
}
echo "</ul></div>\n";
}
?>
The only difference is that I have used the following PHP in the form...
PHP Code:
<?php echo htmlspecialchars(@$fields['fm_name']); ?>
...instead of as in the online examples...
PHP Code:
<?=htmlspecialchars(@$fields['fm_name'])?>