Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Create form to email and post to database for Dataset

Community Beginner ,
Jul 01, 2010 Jul 01, 2010

Copy link to clipboard

Copied

#1 I'm trying to adapt my email form to post to my database after all checks are cleared, but am not sure where to post the Insert Record server behavior.

#2 I plan on using YUI Calendar with a Spry Dataset, so I'm trying to figure out how to create the dates to post in the correct date/text format so it would be compatible with the YUI Calendar. An image of my dbase table is attached.2010-07-01_085433.jpg

This the PHP processing code:

<?php
// set flag to indicate whether mail has been sent
$mailSent = false;
if (array_key_exists('scQuestion', $_POST)) {

// mail processing script
     // remove escape characters from POST array
     if (get_magic_quotes_gpc()) {
     function stripslashes_deep($value) {
    $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
    return $value;
    }
       $_POST = array_map('stripslashes_deep', $_POST);
       }
     
      // validate the input, beginning with name
     $name = trim($_POST['name']);
     if (empty($name)) {
          $error['name'] = 'Please enter your name';
          }
     $email = $_POST['email'];
     $phone = trim($_POST['phone']);
     if (empty($phone)) {
          $error['phone'] = 'Please enter your phone in the format (XXX) XXX-XXXX';
     }
     $month = $_POST['month'];
     $date = $_POST['date'];
     $year = $_POST['year'];
     $month2 = $_POST['month2'];
     $date2 = $_POST['date2'];
     $year2 = $_POST['year2'];
     
     // check for valid email address
     $pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
     if (!preg_match($pattern, trim($email))) {
     $error['email'] = 'Please enter a valid email address';
     }

     // check the content of the text area
     $eventtypeBody = trim($_POST['eventtype']);
     if (empty($eventtypeBody)) {
          $error['eventtype'] = 'Please enter the type of event your wish to reserve';
          }
     $comments = trim($_POST['comments']);
     
     include_once $_SERVER['DOCUMENT_ROOT'] . '/CVHistoricEstates/securimage/securimage.php'; // add /cvh/

     $securimage = new Securimage();
     if ($securimage->check($_POST['captcha_code']) == false) {
  // the code was incorrect
  // handle the error accordingly with your other error checking

  // or you can do something really basic like this
  die('The code you entered was incorrect.  Please go back and try again.');
}          
     // initialize variables
     $to = 'me@me.com';
     $subject = 'Reservation Request';

$SpamErrorMessage = "No URLs permitted";
     if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();}
     if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();}
     if (preg_match("/http/i", "$eventtypeBody")) {echo "$SpamErrorMessage"; exit();}
     if (preg_match("/http/i", "$phone")) {echo "$SpamErrorMessage"; exit();}
     if (preg_match("/http/i", "$comments")) {echo "$SpamErrorMessage"; exit();}
     
     // build the eventtype
     $message = date('l F j, Y');
     $message .= "\r\n\r\n$name would like to make a reservation with CVHE for a $eventtypeBody on ";
     $message .= date('F', strtotime("$month"));
     $message .= " $date, $year. $name can be contacted at $phone or at $email.\r\n\r\n$name's alternative date choice: ";
     $message .= date('F', strtotime("$month"));
     $message .= " $date, $year.\r\n\r\n";
     $message .= "Comments:\r\n$comments";
     
     //build the additional headers
     $additionalHeaders = "From: CVHE Reservations Request System <webmaster@me.com>\r\n";
     $additionalHeaders .= "Reply-To: $email";
     
//send the email if there are not errors
     if (!isset($error)) {
     $mailSent = mail($to, $subject, $message, $additionalHeaders);
     // check that the mail was sent successfully
     if (!$mailSent) {
          $error['notSent'] = 'We\'re sorry, there was a problem sending your mail. Please make another attempt to send your inquiry again. If this problem continues, please contact us at XXX.XXX.XXXX for further assistance.';
          }
     }
}
?>

Form:

<body id="reservations">
<div id="bkgrd">
<div id="body-center" class="group">
<div id="bg-header">
<div id="cv-body">
<div id="bread">
<ul>
<li><a href="index.php">Home ></a></li>
<li>Request Reservations</li>
</ul></div>
<div id="header">
     <?php include('incs/header_2nd.php'); ?>
</div>
<div id="column-left">
<?php include('left_navmenu.php'); ?>
</div>
<div id="column-right">
     <div class="right-padd">
<h1>Request Reservations</h1>
<div class="conpadd">
<?php if (isset($error['notSent'])) { ?>
<h2>Server Error</h2>
<p class="warning"><?php echo $error['notSent']; ?></p>
<?php } elseif ($mailSent) { ?>
<h2>Thank You</h2>
<p>Thank you for reserving your event with Central Valley Historic Estates. We appreciate your patience as we review your information and will respond in a timely manner.</p>
<?php } else { ?>
<p>Please fill out the form below to make reservations with Central Valley Historic Estates.<span style="float: right;"><span class="warning">*</span> Denotes required field</span></p>
<?php } ?>
<?php if (!$mailSent) { ?>
<form method="POST" name="contactForm" id="contactForm">
<fieldset>
<label for="name">Full Name: 
<?php if (isset($error['name'])) { ?>
<span class="warning"><?php echo $error['name']; ?></span>
<?php } ?></label>
<input value="<?php if (isset($_POST['name'])) { echo htmlentities($_POST['name'], ENT_COMPAT, 'UTF-8');} ?>" name="name" type="text" id="name" tabindex="1" size="30" maxlength="30" <?php if(isset($error)) {echo "value='$name'";} ?> /> <abbr class="warning" title="Required field">*</abbr>
</fieldset>
<fieldset>
<label for="email">Email: <?php if (isset($error['email'])) { ?>
<span class="warning"><?php echo $error['email']; ?></span>
<?php } ?></label>
<input value="<?php if (isset($_POST['email'])) { echo htmlentities($_POST['email'], ENT_COMPAT, 'UTF-8');} ?>" name="email" type="text" id="email" tabindex="2" size="30" maxlength="30" <?php if(isset($error)) {echo "value='$email'";} ?> /> <abbr class="warning" title="Required field">*</abbr>
</fieldset>
<fieldset>
<label for="phone">Phone: <?php if (isset($error['phone'])) { ?>
<span class="warning"><?php echo $error['phone']; ?></span>
<?php } ?></label>
<input value="<?php if (isset($_POST['phone'])) { echo htmlentities($_POST['phone'], ENT_COMPAT, 'UTF-8');} ?>" name="phone" type="text" id="phone" tabindex="2" size="30" maxlength="30" <?php if(isset($error)) {echo "value='$phone'";} ?> /> <abbr class="warning" title="Required field">*</abbr>
</fieldset>
<fieldset>
<label for="eventtype">Event Type: 
<?php if (isset($error['eventtype'])) { ?>
<span class="warning"><?php echo $error['eventtype']; ?></span>
<?php } ?></label>
<input name="eventtype" type="text" id="eventtype" tabindex="3" value="<?php if (isset($_POST['eventtype'])) { echo htmlentities($_POST['eventtype'], ENT_COMPAT, 'UTF-8');}  ?><?php if(isset($error)) {echo $eventtypeBody;} ?>" size="30" />
<abbr  class="warning" title="Required field">*</abbr>
</fieldset>
<fieldset style="overflow: hidden;">
<h3>Event Date First Option:</h3>
<span style="float: left; margin-right: 1em;"><label for="month">Month:</label>
    <select name="month" id="month">
<?php
for($m = 1;$m <= 12; $m++){
$month = date("F", mktime(0, 0, 0, $m));
echo "<option value = '$m'>$month</option>";
}
?>
</select></span>
<span style="float: left; margin-right: 1em;">
<label for="date">Date:</label>
    <select name="date" id="date">
    <?php
    for ($x = 1; $x <= 31; $x++) {
            echo "<option value = $x>$x</option>";
    }
    ?>
    </select></span>
    <label for="year">Year:</label>
    <select name="year" id="year">
                    <?php
                    $y = intval(date("Y"));
                    for ($i = $y; $i <= $y + 3; $i++) {
                         print "<option value=\"$i\">$i</option>\n";
                         }
                         ?>
     </select>
    </fieldset>
    <fieldset style="overflow: hidden;">
    <h3>Event Date Second Option:</h3>
<span style="float: left; margin-right: 1em;">
<label for="month2">Month:</label>
    <select name="month2" id="month2">
    <option value = "None">None</option>
<?php
for($mb = 1;$mb <= 12; $mb++){
$month2 = date("F", mktime(0, 0, 0, $mb));
echo "<option value = '$mb'>$month2</option>";
}
?>
</select></span>
<span style="float: left; margin-right: 1em;">
<label for="date2">Date:</label>
    <select name="date2" id="date2">
    <option value="None">None</option>
                    <?php
    for ($xb = 1; $xb <= 31; $xb++) {
            echo "<option value = $xb>$xb</option>";
    }
    ?>
    </select></span>
    <label for="year2">Year:</label>
    <select name="year2" id="year2">
                    <option value="None">None</option>
                    <?php
                    $y = intval(date("Y"));
                    for ($i = $y; $i <= $y + 3; $i++) {
                         print "<option value=\"$i\">$i</option>\n";
                         }
                         ?>
     </select>
    </fieldset>
<fieldset>
<label for="comments">Comments: 
<?php if (isset($error['comments'])) { ?>
<span class="warning"><?php echo $error['comments']; ?></span>
<?php } ?></label>
<textarea name="comments" cols="40" rows="5" id="comments" tabindex="3"><?php if (isset($_POST['comments'])) { echo htmlentities($_POST['comments'], ENT_COMPAT, 'UTF-8');}  ?>
</textarea>
</fieldset>
<fieldset>
<img src="securimage/securimage_show.php" alt="CAPTCHA Image" name="captcha" id="captcha" />
<a class="click" href="#" onclick="document.getElementById('captcha').src = 'securimage/securimage_show.php?' + Math.random(); return false">Reload Image</a>
<p>Please type in the above image letters and numbers code in the text box below.<br /><span style="font-size: 11px;">(We understand that this may be an inconvenience, but we appreciate your patience.)</span></p>
<input type="text" name="captcha_code" size="10" maxlength="6" class="captinp" />
<input class="btn" name="scQuestion" type="submit" id="scQuestion" tabindex="4" value="Send" />
</fieldset>
<input name="created" type="hidden" value="NOW()" />
</form>     
<?php } ?></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<?php include('footer.php'); ?>
</div>
</body>
</html>
<?php
function getDims($image,$folder) {
  if (!empty($folder)) {
    if (strrpos($folder, '/') != strlen($folder)-1) {
      $folder .= '/';
      }
    }
  if(!empty($image) && file_exists($folder.$image)) {
    $image_info = getimagesize($folder.$image);
    }
  $retVal = isset($image_info) ? $image_info[3] : '';
  return $retVal;
  }
?>

Thanks for your help!

TOPICS
Server side applications

Views

1.0K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2010 Jul 01, 2010

Copy link to clipboard

Copied

#1 I'm trying to adapt my email form to post to my database after all checks are cleared, but am not sure where to post the Insert Record server behavior.

This can best be done after the form has been emailed within the following if statement

<?php } elseif ($mailSent) { ?>
<h2>Thank You</h2>
<p>Thank you for reserving your event with Central Valley Historic Estates. We appreciate your patience as we review your information and will respond in a timely manner.</p>
<?php } else { ?>
<p>Please fill out the form below to make reservations with Central Valley Historic Estates.<span style="float: right;"><span class="warning">*</span> Denotes required field</span></p>
<?php } ?>

#2 I plan on using YUI Calendar with a Spry Dataset, so I'm trying to figure out how to create the dates to post in the correct date/text format so it would be compatible with the YUI Calendar. An image of my dbase table is attached.

The dates should be correct (yyyy-mm-dd)  for insertion into the database and can be converted to suit the calendar

I hope this helps.

Ben

Wappler, the only real Dreamweaver alternative.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 03, 2010 Jul 03, 2010

Copy link to clipboard

Copied

LATEST

Great! Thanks! I'll give that a try!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines