Page 1 of 1

validation loop interferes with sticky form for star rating

Posted: Sun Nov 08, 2009 8:02 am
by Dvae
Dear All

I'm developing a website for my green holiday business. I have created a page where people can rate holiday building blocks with a star rating system. They can fill in their name and email and a short message at the end and submit their ratings.

I have created a php validation page where their name and email gets checked before it is emailed to me. If everything validates first time, the email is sent to me correctly and I receive all information as entered in the form.

If it doesn't validate, the user is presented with a form where they can correct their errors. The form is sticky, so anything they have already filled out, is still there.

This works fine for the name, email, and message variables. And even the star-ratings seem to be sticky (I have added a temporary table to check their values). However, after correcting any errors, the value of the star-ratings disappears and they are not emailed through to me.

Could someone please point me in the right direction of how to solve this?

The relevant code follows below:

Code: Select all

 
<?php
// name variables
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$kondolovo = $_REQUEST['kondolovo'];
$cultures = $_REQUEST['cultures'];
$driving = $_REQUEST['driving'];
$mladezhko = $_REQUEST['mladezhko'];
$stoilovo = $_REQUEST['stoilovo'];
$sinemorets = $_REQUEST['sinemorets'];
$varvara = $_REQUEST['varvara'];
$ropotamo = $_REQUEST['ropotamo'];
$sozopol = $_REQUEST['sozopol'];
$lakes = $_REQUEST['lakes'];
 
// Check the server will send.
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
      // Make variable $error
   $error = '';
   
      // Check all fields filled in correctly.
   if(empty($name))
      $error .= "Please enter your name.<br />\n";
   if(!empty($name) and strlen($name) < 2)
      $error .= "The name you entered is too short.<br />\n";
   if(empty($email))
      $error .= "Please enter your email address.<br />\n";
   if(!empty($email) and !preg_match('/^[A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,6}$/', $email)
)
      $error .= "The email address you entered is invalid.<br />\n";
    
   
      // Error if anything filled in incorrectly.
   if( $error )
   {
      echo "<h1 style=\"color: #f00;\">Something went wrong...</h1>\n";
      echo "<p style=\"color: #f00;\">" . $error . "</p>";
   }
      // Start sending message if all correct.
   else
   {
         // Compose message to be sent.
      $send_message = "Holiday building blocks rating
      
From: " . $name . "
Email: " . $email . "
IP: " . $_SERVER['REMOTE_ADDR'] . "
 
Building block ratings:
Kondolovo and Kosti " . $kondolovo . " stars
Strandja's ancient cultures " . $cultures . " stars
Driving tour " . $driving . " stars
Mladezhko and Kovach " . $mladezhko . " stars
Stoilovo " . $stoilovo . " stars
Coastal landscapes Sinemorets " . $sinemorets . " stars
Explore Varvara " . $varvara . " stars
Ropotamo nature reserve " . $ropotamo . " stars
Ancient town Sozopol " . $sozopol . " stars
Burgas Lakes " . $lakes . " stars
 
Message: " . $message . "
 
<!-- s:) --><img src=\"{SMILIES_PATH}/icon_smile.gif\" alt=\":)\" title=\"Smile\" /><!-- s:) -->";
 
      // Send email. 
       
      if (@mail("info@myemail.co.uk",$_POST['v_subject'],$send_message,"From: " . $_POST['v_name'] . " <" . $_POST['v_email'] . ">"))
      {
            // Confirm email has been sent.
         echo "<h1>Sent successfully... Thank you</h1>\n";
         echo "<h2>Your details</h2><p>
                Name: $name<br>
                Email: $email</p>\n";
 
        echo "<h2>Your ratings</h2>
        <table>
        <tr><td>Building block Kondolovo and Kosti</td><td>$kondolovo stars</td></tr>
        <tr><td class='alt'>Building block Strandja's ancient cultures</td><td class='alt'>$cultures stars</td></tr>
        <tr><td>Building block Driving tour</td><td>$driving stars</td></tr>
        <tr><td class='alt'>Building block Mladezhko and Kovach</td><td class='alt'>$mladezhko stars</td></tr>
        <tr><td>Building block Stoilovo</td><td>$stoilovo stars</td></tr>
        <tr><td class='alt'>Building block Coastal landscapes Sinemorets</td><td class='alt'>$sinemorets stars</td></tr>
        <tr><td>Building block Explore Varvara</td><td>$varvara stars</td></tr>
        <tr><td class='alt'>Building block Ropotamo nature reserve</td><td class='alt'>$ropotamo stars</td></tr>
        <tr><td>Building block Ancient town Sozopol</td><td>$sozopol stars</td></tr>
        <tr><td class='alt'>Building block Burgas Lakes</td><td class='alt'>$lakes stars</td></tr>
        </table>\n";
 
        echo "<h2>Your message</h2>
        <p><tt>$message</tt></p>
 
        <p><strong>Thank you! We will get back to you as soon as possible...</strong></p>\n";
        echo "
        <p>Back to <a href='holiday-building-blocks.htm'>holiday building blocks</a> | Find out <a href='your-holiday-helps.htm'>how your holiday helps</a> | <a href='index.htm'>Homepage</a></p>\n";
      }
      else
      {
            // Error-message if email could not be sent.
         echo "<h1 style=\"color: #f00;\">Error</h1>\n";
         echo "<p>Sorry, your message could not be sent. Please try again or email us direct on <a href='mailto:info@myemail.co.uk'>info@myemail.co.uk</a></p>\n";
      }
 
   }
}
   // Display form if anything filled in wrongly.
if(  (!empty($error)) or $_SERVER['REQUEST_METHOD'] != "POST" )
{
 
 
?>
 
<!-- $_SERVER['PHP_SELF'] Same as existing page. (useful if address changes) -->
<form method="post" action="formtest-new.php">
<fieldset>
                            <legend class="hide">Your details</legend>
                                <ol>
                                    <li>
                                      <label for="name">Name: </label>
                                      <input name="name" size="35" value="<?php echo $name; ?>"><sup> *</sup>
                                    </li>
                                    <li>
                                      <label for="email">Email: </label>
                                      <input name="email" size="35" value="<?php echo $email; ?>"><sup> *</sup>
                                    </li>
                                    
                                    <li>
                                      <fieldset>
                                        <legend>Optional message: </legend>
                                        <textarea name="message" rows="4" cols="40"><?php echo $message; ?></textarea>
                                      </fieldset>
                                    </li>
                                    
                            
                                </ol>
                        </fieldset>                     
                        <input id="send_button" type="submit" value="Send">
                        
                        <ul>
                        <li><input name="kondolovo" value="<?php echo $kondolovo; ?>" disabled></li>
                        <li><input name="cultures" value="<?php echo $cultures; ?>" disabled></li>
                        <li><input name="driving" value="<?php echo $driving; ?>" disabled></li>
                        <li><input name="mladezhko" value="<?php echo $mladezhko; ?>" disabled></li>
                        <li><input name="stoilovo" value="<?php echo $stoilovo; ?>" disabled></li>
                        <li><input name="sinemorets" value="<?php echo $sinemorets; ?>" disabled></li>
                        <li><input name="varvara" value="<?php echo $varvara; ?>" disabled></li>
                        <li><input name="ropotamo" value="<?php echo $ropotamo; ?>" disabled></li>
                        <li><input name="sozopol" value="<?php echo $sozopol; ?>" disabled></li>
                        <li><input name="lakes" value="<?php echo $lakes; ?>" disabled></li>
                        </ul>
 
   
</form>
 
<?   
   // End of script
}
?>
 


I hope someone can help.

Thank you very much :)

Re: validation loop interferes with sticky form for star rating

Posted: Mon Nov 09, 2009 4:00 am
by Dvae
That's it, SOLVED! It works perfectly now!

:D


Thank you so much!