Sun Dial Menu

Debugging PHP forms

I have taken the online php feedback form offline. I am looking at other things and nobody has used it to date.

If I pickup the development of the forms for the Village Hall I may continue. However, the server log capabiity of the hosting package, TSO, is not as good as the HostingUK one. As such I am not sure that the same notices and warnings are thrown there.

For some reason I put the message construction ($Bindo) before the form???? I think that all I need is some re-ordering.

My plan was to echo the contents of the submitted form at the top of the page and "push" the "filled" form down on the screen. I think that I will have to use a manipulation of the DOM to add this text to a div at the top of the main content.

Undefined indexes

This could be due to the form validation that I adopted

mod_fcgid: stderr: PHP Notice: Undefined index: name in /var/www/vhosts/ on line 171, referer:

also email

The php validation page, which uses the same method does not generate these warnings

Timezone setting not set

mod_fcgid: stderr: PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/vhosts/ on line 198, referer:

The php Validation that doesn't throw errors:

The code looks pretty much the same apart from the verbose message echoed back to the screen. However, this is where the "Notice" is thrown

The PHP:

// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";

  if (empty($_POST["name"])) {
    $nameErr = "Name is required";
  } else {
    $name = test_input($_POST["name"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
      $nameErr = "Only letters and white space allowed"; 

The HTML form:

p> span class="error">* required field /span> /p>
 form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
  <input type="submit" name="submit" value="Submit">  

  Name: input type="text" name="name" value=" ?php echo $name;?>">
  span class="error">*  ?php echo $nameErr;?> /span>

The validation function

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
Top Menu

Site design by Tempusfugit Web Design -