Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Custom Order Form w/ Photo Upload (HELP!)


Guest

Recommended Posts

Alright you PHP coders.....Perhaps someone call help me with this contribution. Here is what works and what doesnt. I need to get this working by tomorrow. :(

 

1) Form field error checking DOES work

2) File upload NOT working, file size and type NOT working

3) Mail is NOT sending

4) Redirect DOES work

5) Session register DOES work

6) Database complains about Customer_id key insertion ==> 1062 - Duplicate entry '0' for key 1

 

 

<?php

 

require('includes/application_top.php');

 

//needs to be included earlier to set the success message in the messageStack

//require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CREATE_ACCOUNT);

 

// restore cart contents

 

$cart->restore_contents();

 

 

// set process switch

 

$process = false;

 

// check for form call

 

if (isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process')) {

 

// setup switches if form is called

 

$process = true;

$error = false;

 

 

// prepare data input

 

$firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']);

$lastname = tep_db_prepare_input($HTTP_POST_VARS['lastname']);

$telephone = tep_db_prepare_input($HTTP_POST_VARS['telephone']);

$email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);

$comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);

 

 

// register session info

 

tep_session_register('firstname');

tep_session_register('lastname');

tep_session_register('telephone');

tep_session_register('email_address');

tep_session_register('comments');

tep_session_register('infile_name');

 

 

// error checking and validation

 

if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {

$error = true;

 

$messageStack->add('custom_order', ENTRY_FIRST_NAME_ERROR);

 

}

 

if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {

$error = true;

 

$messageStack->add('custom_order', ENTRY_LAST_NAME_ERROR);

 

}

 

if (strlen($email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {

$error = true;

 

$messageStack->add('custom_order', ENTRY_EMAIL_ADDRESS_ERROR);

 

} elseif (tep_validate_email($email_address) == false) {

$error = true;

 

$messageStack->add('custom_order', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);

 

}

 

if (strlen($telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {

$error = true;

 

$messageStack->add('custom_order', ENTRY_TELEPHONE_NUMBER_ERROR);

 

}

 

 

if (strlen($comments) > 255) {

$error = true;

 

$messageStack->add('custom_order', ENTRY_CUSTOM_COMMENTS_ERROR);

 

}

 

 

 

// check for photo attachment

 

if($infile) {

 

// check for photo file size, max size allowed is 50k

 

$imagestats=getImageSize($infile);

$customer_id = tep_db_insert_id();

 

if ($infile_size > 50000) {

 

$msg = 'File Name:' . $infile_name . ' is ' . $infile_size . ' bytes in size.';

$error = true;

 

}

 

 

// check for photo file types and upload to server, assign photo url

 

 

 

if ($imagestats[2]=1) {

 

copy ($infile, 'customer/images/user' . $customer_id . '.gif');

$photo_url = 'customer/images/user' . $customer_id . '.gif';

 

} elseif ($imagestats[2]=2) {

 

copy ($infile, 'customer/images/user' . $customer_id . '.jpg');

$photo_url = 'customer/images/user' . $customer_id . '.jpg';

 

} elseif ($imagestats[2]=3) {

 

copy ($infile, 'customer/images/user' . $customer_id . '.png');

$photo_url = 'customer/images/user' . $customer_id . '.png';

 

} elseif ($imagestats[2]=6) {

 

copy ($infile, 'customer/images/user' . $customer_id . '.bmp');

$photo_url = 'customer/images/user' . $customer_id . '.bmp';

 

} else {

 

$msg = 'Sorry, the supplied file ' . $infile_name . ' is not a supported image type!';

$error = true;

 

}

}

 

if (!isset($infile)) {

 

$photo_status = 0;

 

} else {

 

$photo_status = 1;

 

}

 

if ($error == false) {

 

// execute database calls

 

$customer_id = tep_db_insert_id();

tep_db_query("insert into customers (customers_id, customers_firstname, customers_lastname, customers_email_address, customers_telephone) values ('" . (int)$customer_id . "', '" . $firstname . "', '" . $lastname . "', '" . $email_address . "', '" . $telephone . "')");

 

tep_db_query("insert into custom_order (custom_order_id, custom_order_comments) values ('" . (int)$customer_id . "', '" . $comments . "')");

 

 

// generate e-mail

 

$name = $firstname . ' ' . $lastname;

 

$email_text = '----------------------';

$email_text .= 'Customer Order Inquiry';

$email_text .= '----------------------';

$email_text .= $name . 'has submitted a customer order inquiry';

$email_text .= 'FirstName:' . $firstname;

$email_text .= 'LastName:' . $lastname;

$email_text .= 'Telephone:' . $telephone;

$email_text .= 'Email Address:' . $email_address;

$email_text .= 'Comments:' . $comments;

 

// check photo status and disclose photo information

 

if ($photo_status == 1) {

 

$email_text .= 'Photo Location: http://www.xxxxxxxxx.com/' . $photo_url;

$email_text .= 'Login with username (xxxxx) and password (xxxxxx). This is a secure area!';

 

} else {

 

$email_text .= 'Note:' . $firstname . 'did not upload a photo.';

 

}

 

// continue generating e-mail

 

$email_subject = 'Custom Order Submission (#' . $customer_id . ')';

$store_owner_email_address = '[email protected]';

 

// send email

 

tep_mail($name, $email_address, $email_subject, $email_text, STORE_OWNER, $store_owner_email_address);

 

// redirect page

 

tep_redirect(tep_href_link(custom_orders_success . '.' . php, '', 'SSL'));

}

}

 

 

$breadcrumb->add(NAVBAR_TITLE, tep_href_link(custom_orders.php, '', 'SSL'));

?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...