Combining Email Contact & addForm.php... a few bugs

By Rusty - January 28, 2011 - edited: January 28, 2011

So I'm trying to combine a PHP contact form (being used as an "order request" submission form, and I'm trying to incorporate addForm.php into it. This way when someone submits an order the business gets an email, AND there is a record created listing what was requested.

So right now I have two problems.
  • The Quantity isn't being properly passed into the DB

  • My new line commands aren't working


Here's the code
<form name="form" id="form" class="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validate(this)"
method="post">
<?php foreach ($favoriteRecords as $record): ?>
<!--Quantity -->
<td><input type="text" id="<?php echo $record['form_number'] ?>_qty" name="<?php echo $record['form_number'] ?>_qty"
maxlength="4" size="4" tabindex="1" value="1"/></td>
<?php endforeach?>
<h4><button id="submit" type="submit" value="Submit Order" tabindex="5" class="submit" name="submit" style="height:36px;
padding-bottom:2px; margin-left:6px; background-color:#C00; color:#FFF; margin-right:20px;" >Submit Order</button>Please
review your order, enter your desired quantities, and click Submit when complete</h4>


</form>
<?php }else{ ?>
<!-- START SEND MAIL SCRIPT -->
<div id="done">
<h2>Order Successfully Submitted!</h2>
<p>Your order has been placed.<br/ >
Thank you for your business, should you have any questions please call us at 800-555-1212.</p>
</div>
<?php

error_reporting( E_ALL & ~E_NOTICE );


$mail = $_POST['email'];


$to = "rusty@website.com";
$subject = "New Order from Website";
$headers = "From: Website <noreply@website.com>";
$message = "Sent from the Website\n";

$message .= "Company: " . $accountsRecord['company'] . "\n";
$message .= "Address: " . $accountsRecord['street_address'] . "\n";
$message .= $accountsRecord['city'] . ", " . $accountsRecord['state'] . " " . $accountsRecord['zip_code'] . "\n";
$message .= "\n";
$message .= "\nHas Ordered the Following:";
This is the foreach to match the foreach above .
This was done to create unique names for each input field
This portion works on its on (the send email bit works great}
foreach ($favoriteRecords as $record) {
$message .= "\n________________________________________________________________";
$qty_string = $record['form_number'] . "_qty";
$message .= "\nQuantity:" . $_POST[$qty_string];
$message .= "\nItem Number:" . $record['form_number'];
$message .= "\nDescription:" . $record['title'];
}

$message .= "\n________________________________________________________________";

$message .= "\nOrder was placed by business: " . $accountsRecord['company'] . "on 01/27/2011";
$message .= "\nOrder was placed by user: " . $_POST['contactname'];

//Receive Variable
$sentOk = mail($to,$subject,$message,$headers);

This is where I added the addForm.php portions
The issue is that the quantity that IS properly working above
isn't properly working below, I get a default 1 value.
And the other thing, my \n New Lines aren't coming through at all.

Any suggestions?

//Begin Submission of Order to Order History DB
if (@$_REQUEST['submit']) {

// turn off strict mysql error checking for: STRICT_ALL_TABLES
mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later)

// add record
//if (!@$errorsAndAlerts) {
foreach ($favoriteRecords as $record) {
$order .= "\n________________________________________________________________";
$qty_string = $record['form_number'] . "_qty";
$order .= "\nQuantity:" . $_POST[$qty_string];
$order .= "\nItem Number:" . $record['form_number'];
$order .= "\nDescription:" . $record['title'];

}


mysql_query("INSERT INTO `{$TABLE_PREFIX}order_history` SET
title = '".mysql_real_escape_string( $accountsRecord['company'] )."',
I removed the real escape string thinking it might have been stripping the \n
content = '". $order ."',

createdDate = NOW(),
updatedDate = NOW(),
createdByUserNum = '0',
updatedByUserNum = '0'")
or die("MySQL Error Creating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
$recordNum = mysql_insert_id();

// display thanks message and clear form
$errorsAndAlerts = "Thanks, we've added that record!";
$_REQUEST = array();
//}

}
}
?>


Like I said, it submits the text data, pulled from stored CMSBuilder values for the item description, however the Quantity and new lines aren't going through.
Rusty

Re: [Rusty] Combining Email Contact & addForm.php... a few bugs

By Jason - January 31, 2011

Hi Rusty,

Could you please attach the .php file you're working with so I can see all your code. It looks like this code is part of an "if-else" statement, but I can't see the initial "if"

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Rusty] Combining Email Contact & addForm.php... a few bugs

By Jason - February 1, 2011

Hi Rusty,

Thanks for posting. I'm glad to hear everything is working for you now.

The answer to your question would be yes. If you're storing the record numbers of the items previously purchased and your favorites list represents your current order, then you could have your "Add to Order" link beside each product. &lt; is just the HTML code representing "<". Where are you seeing this appearing?

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/