Zen Cart Logo
Forums / General Questions / Adding Multiple Images to Custom form To be sent to Admin Email

Adding Multiple Images to Custom form To be sent to Admin Email

Views: 7,069

Results 1 to 20 of 57
15 Jan 2013, 1:11 AM
#1
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Adding Multiple Images to Custom form To be sent to Admin Email

I have most of my custom form created, now i'm running into some problems allowing multiple image uploads into form. Then have these images attached to the email. I have search for information, but not getting nowhere. This custom form is based off of DrByte's contribution band-signup (which didn't include any image support). The form is at http://qualityautowi.com/index.php?main_page=vehicle_tradein any help would be greatly appreciated.

15 Jan 2013, 11:54 PM
#2
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

ok I have worked out how to get the multiple images button on my custom form. Now I have a piece of code that would take those images and attach them in a email. I'm just not sure how to implement this code to work in the header.php file. If you have any other ways to go about doing this would be greatly appreciated.

<?php
	// did files get sent
	if(isset($_FILES) && (bool) $_FILES) {
	
		// define allowed extensions
		$allowedExtensions = array("pdf","doc","docx","gif","jpeg","jpg","png","rtf","txt");
		$files = array();
			
		// loop through all the files
		foreach($_FILES as $name=>$file) {
		
			// define some variables
			$file_name = $file['name']; 
			$temp_name = $file['tmp_name'];
			
			// check if this file type is allowed
			$path_parts = pathinfo($file_name);
			$ext = $path_parts['extension'];
			if(!in_array($ext,$allowedExtensions)) {
				die("extension not allowed");
			}
			
			// move this file to the server YOU HAVE TO DO THIS
			$server_file = "/var/www/uploads/$path_parts[basename]";
			move_uploaded_file($temp_name,$server_file);
			
			// add this file to the array of files
			array_push($files,$server_file);
		}	
			
		// define some mail variables
		$to = "seanclarkg######################";
		$from = "[email protected]"; 
		$subject ="test attachment"; 
		$msg = "here ya go";
		$headers = "From: $from";
		
		// define our boundary
		$semi_rand = md5(time()); 
		$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
		
		// tell the header about the boundary
		$headers .= "\nMIME-Version: 1.0\n";
		$headers .= "Content-Type: multipart/mixed;\n";
		$headers .= " boundary=\"{$mime_boundary}\""; 
		
		// part 1: define the plain text email
		$message ="\n\n--{$mime_boundary}\n";
		$message .="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
		$message .="Content-Transfer-Encoding: 7bit\n\n" . $msg . "\n\n";
		$message .= "--{$mime_boundary}\n";
		
		// part 2: loop and define mail attachments
		foreach($files as $file) {
			$aFile = fopen($file,"rb");
			$data = fread($aFile,filesize($file));
			fclose($aFile);
			$data = chunk_split(base64_encode($data));
			$message .= "Content-Type: {\"application/octet-stream\"};\n";
			$message .= " name=\"$file\"\n";
			$message .= "Content-Disposition: attachment;\n";
			$message .= " filename=\"$file\"\n";
			$message .= "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
			$message .= "--{$mime_boundary}\n";
		}
	
		// send the email
		$ok = mail($to, $subject, $message, $headers); 
		if ($ok) { 
			echo "<p>mail sent to $to!</p>"; 
		} else { 
			echo "<p>mail could not be sent!</p>"; 
		}
		die();
	}
?>

and this is the header.php file

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | [email protected] so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: header_php.php,v 1.3 2007/06/07 00:00:00 DrByteZen Exp $
//
  require(DIR_WS_MODULES . 'require_languages.php');
  $breadcrumb->add(NAVBAR_TITLE);
  


  $error = false;
  $first_name = '';
  $last_name = '';
  $phone_number = '';
  $email_address = '';
  $mailing_city = '';
  $vehicle_year = '';
  $vehicle_make = '';
  $vehicle_model = '';
  $vehicle_mileage = '';
  $comments = '';


  if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
    $first_name = zen_db_prepare_input($_POST['first_name']);
    $last_name = zen_db_prepare_input($_POST['last_name']);
    $phone_number = zen_db_prepare_input($_POST['phone_number']);
    $email_address = zen_db_prepare_input($_POST['email_address']);
    $mailing_city = zen_db_prepare_input($_POST['mailing_city']);
    $vehicle_year = zen_db_prepare_input($_POST['vehicle_year']);
    $vehicle_make = zen_db_prepare_input($_POST['vehicle_make']);
    $vehicle_model = zen_db_prepare_input($_POST['vehicle_model']);
    $vehicle_mileage = zen_db_prepare_input($_POST['vehicle_mileage']);
    $comments = zen_db_prepare_input(strip_tags($_POST['comments']));

    if (!zen_validate_email($email_address))  {
      $error = true;
      $messageStack->add('email_address', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
      }
    if (!zen_not_null($first_name))  {
      $error = true;
      $messageStack->add('first_name', 'Please fill in the first_name');
      }
    if (!zen_not_null($last_name))  {
      $error = true;
      $messageStack->add('last_name', 'Please fill in the last_name');
      }
    if (!zen_not_null($phone_number))  {
      $error = true;
      $messageStack->add('phone_number', 'Please fill in the phone_number');
      }
    if (!zen_not_null($email_address))  {
      $error = true;
      $messageStack->add('email_address', 'Please fill in the email_address');
      }
    if (!zen_not_null($mailing_city))  {
      $error = true;
      $messageStack->add('mailing_city', 'Please fill in the mailing_city');
      }
/*
    if (!zen_not_null($contact2_firstname))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_firstname');
      }
    if (!zen_not_null($contact2_lastname))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_lastname');
      }
    if (!zen_not_null($contact2_phone))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_phone');
      }
    if (!zen_not_null($contact2_email))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_email');
      }
*/
    if (!zen_not_null($vehicle_year))  {
      $error = true;
      $messageStack->add('vehicle_year', 'Please fill in the vehicle_year');
      }
    if (!zen_not_null($vehicle_make))  {
      $error = true;
      $messageStack->add('vehicle_make', 'Please fill in the vehicle_make');
      }
    if (!zen_not_null($vehicle_model))  {
      $error = true;
      $messageStack->add('vehicle_model', 'Please fill in the vehicle_model');
      }
    if (!zen_not_null($vehicle_mileage))  {
      $error = true;
      $messageStack->add('vehicle_mileage', 'Please fill in the vehicle_mileage');
      }

   if ($error == false) {

// grab some customer info if logged in
      if(isset($_SESSION['customer_id'])) {
        $check_customer = $db->Execute("select first_name, last_name, email_address from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
        $email_address = $check_customer->fields['email_address'];
        $customer_name = $check_customer->fields['first_name'] . ' ' . $check_customer->fields['last_name'];
      } else {
        $email_address = 'Not logged in';
        $customer_name = 'Not logged in';
      }

//assemble the email contents:
      $email_text = 'Vehicle Data Submission: ' . "\n" .
        '------------------------------------------------------' . "\n" .
        'first_name:' . "\t" . $first_name . "\n" .
        'last_name:' . "\t" . $last_name . "\n" .
        'phone_number:' . "\t" . $phone_number . "\n" .
        'email_address:' . "\t" . $email_address . "\n" .
        'mailing_city:' . "\t" . $mailing_city. "\n" .
        'vehicle_year:' . "\t" . $vehicle_year . "\n" .
        'vehicle_make:' . "\t" . $vehicle_make . "\n" .
        'vehicle_model:' . "\t" . $vehicle_model . "\n" .
        'vehicle_mileage:' . "\t" . $vehicle_mileage . "\n" .
        'comments:' . "\t" . $comments . "\n\n" .
        '------------------------------------------------------' . "\n" .
        OFFICE_USE . "\t" . "\n" .
        OFFICE_LOGIN_NAME . "\t" . $customer_name . "\n" .
        OFFICE_LOGIN_EMAIL . "\t" . $customer_email . "\n" .
        OFFICE_IP_ADDRESS . "\t" . $_SERVER['REMOTE_ADDR'] . "\n" .
        OFFICE_HOST_ADDRESS . "\t" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n" .
        OFFICE_DATE_TIME . "\t" . date("D M j Y G:i:s T") . "\n" .
        '------------------------------------------------------' . "\n\n" .
      $email_text = zen_output_string_protected($email_text);
      $email_html = nl2br("\n" . $email_text);
	  
	 
	  
//send the email
      zen_mail(STORE_NAME, SEND_TO_ADDRESS, EMAIL_SUBJECT, $email_text, $first_name . ' ' . $last_name, $email_address, array('EMAIL_MESSAGE_HTML' => $email_html), 'band_signup');

      zen_redirect(zen_href_link(FILENAME_BAND_SIGNUP, 'action=success'));
      } //endif $error=false

  } // endif action

// default email and name if customer is logged in
  if(isset($_SESSION['customer_id'])) {
      $check_customer = $db->Execute("select first_name, last_name, email_address from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
      if ($email_address == '') $email_address = $check_customer->fields['email_address'];
      if ($first_name == '') $first_name = $check_customer->fields['first_name'];
      if ($last_name == '') $last_name = $check_customer->fields['last_name'];
  }

?>

Also I have found another solution that may work, but not sure how to go about doing this. The solution is at http://stackoverflow.com/questions/6804579/how-can-i-easily-allow-users-to-upload-multiple-files This solution says to use phpmailer. Don't know if this would work.

16 Jan 2013, 6:38 PM
#4
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

I really appreciate your help dw08gm. I have read through the entire forum and not really finding out the information that is needed to attach the uploaded files to the email. I know zen cart uses a function called phpmailer which will allow attaching the uploaded files to the email, but not really sure how to go about doing that.

16 Jan 2013, 9:02 PM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding Multiple Images to Custom form To be sent to Admin Email

The concept is:

  1. Create an array with your file attachment data:
$att_array = array('file' => $attachment_file, 'name' => basename($attachment_file), 'mime_type'=>$attachment_filetype);

Of course, substituting the correct information for each of those $attachment_xxxxxx variables:
$attachment_file is the actual complete physical path (on the server) to the file being attached -- that is, wherever you moved the files to during your upload
$attachment_filetype is the MIME type for that file. If you skip the 'mime_type' part of this array, it will use application/octet-stream as a safe fallback.
If you need to handle submitting multiple files, you can make it a nested array.

  1. Then include that array in your email data:
      zen_mail(STORE_NAME, SEND_TO_ADDRESS, EMAIL_SUBJECT, $email_text, $first_name . ' ' . $last_name, $email_address, array('EMAIL_MESSAGE_HTML' => $email_html), 'band_signup'[B], $att_array[/B]); 
  1. MIME-HTML must be enabled in your Admin->Configuration->Email Options settings.
17 Jan 2013, 12:24 AM
#6
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

Thank you DrByte for responding i'm not an expert is php. I'm not quite sure where the files are being uploaded. I have a folder in my directory images/uploads/ and that is where I want these files to go. Here is the bit of jscript that makes the image upload work.

function addElement()
        {
            var ni = document.getElementById('org_div1');
            var numi = document.getElementById('theValue');
            var num = (document.getElementById('theValue').value -1)+ 2;
            numi.value = num;
            var newDiv = document.createElement('div');
            var divIdName = num;  newDiv.setAttribute('id',divIdName);

            newDiv.innerHTML = '<input type="file"  class="fileupload" size="80" name="file' + (num) + '" onchange="addElement()"/> <a class="removelink" onclick=\'removeElement(' + divIdName + ')\'>Remove This File</a>';

            // add the newly created element and it's content into the DOM
            ni.appendChild(newDiv);
        }

        function removeElement(divNum)
        {
            var d = document.getElementById('org_div1');
            var olddiv = document.getElementById(divNum);

            d.removeChild(olddiv);
        }

Also i'm not familiar with creating arrays, but i'm guessing that would go into the header.php file. If you could provide me with the code need to add that would be greatly appreciated.

17 Jan 2013, 4:11 AM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding Multiple Images to Custom form To be sent to Admin Email

GodfatherAntiques:

I'm not quite sure where the files are being uploaded.
Your previous post contained this:

            // move this file to the server YOU HAVE TO DO THIS
            $server_file = "/var/www/uploads/$path_parts[basename]";
            move_uploaded_file($temp_name,$server_file); 
```You would need to use the same path.

It might possibly be a bit simpler if you used the built-in upload class. You'll find examples of its use in /includes/classes/shopping_cart.php and /admin/includes/modules/new_product_preview.php
17 Jan 2013, 10:37 PM
#8
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

ok i'm having some success, but the images are not showing in the attachment in email. Not sure what I'm doing wrong. here is the new code for my header.php file

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | [email protected] so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: header_php.php,v 1.3 2007/06/07 00:00:00 DrByteZen Exp $
//
  require(DIR_WS_MODULES . 'require_languages.php');
  $breadcrumb->add(NAVBAR_TITLE);
  

  $error = false;
  $first_name = '';
  $last_name = '';
  $phone_number = '';
  $email_address = '';
  $mailing_city = '';
  $vehicle_year = '';
  $vehicle_make = '';
  $vehicle_model = '';
  $vehicle_mileage = '';
  $comments = '';


  if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
    $first_name = zen_db_prepare_input($_POST['first_name']);
    $last_name = zen_db_prepare_input($_POST['last_name']);
    $phone_number = zen_db_prepare_input($_POST['phone_number']);
    $email_address = zen_db_prepare_input($_POST['email_address']);
    $mailing_city = zen_db_prepare_input($_POST['mailing_city']);
    $vehicle_year = zen_db_prepare_input($_POST['vehicle_year']);
    $vehicle_make = zen_db_prepare_input($_POST['vehicle_make']);
    $vehicle_model = zen_db_prepare_input($_POST['vehicle_model']);
    $vehicle_mileage = zen_db_prepare_input($_POST['vehicle_mileage']);
    $comments = zen_db_prepare_input(strip_tags($_POST['comments']));
	$att_array = array('file' => $path1, 'name' => basename($path1), 'mime_type'=>$attachment_filetype);
	$att_array = array('file' => $path2, 'name' => basename($path2), 'mime_type'=>$attachment_filetype);
	

    if (!zen_validate_email($email_address))  {
      $error = true;
      $messageStack->add('email address', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
      }
    if (!zen_not_null($first_name))  {
      $error = true;
      $messageStack->add('first name', 'Please fill in the first_name');
      }
    if (!zen_not_null($last_name))  {
      $error = true;
      $messageStack->add('last name', 'Please fill in the last_name');
      }
    if (!zen_not_null($phone_number))  {
      $error = true;
      $messageStack->add('phone number', 'Please fill in the phone_number');
      }
    if (!zen_not_null($email_address))  {
      $error = true;
      $messageStack->add('email address', 'Please fill in the email_address');
      }
    if (!zen_not_null($mailing_city))  {
      $error = true;
      $messageStack->add('mailing city', 'Please fill in the mailing_city');
      }
/*
    if (!zen_not_null($contact2_firstname))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_firstname');
      }
    if (!zen_not_null($contact2_lastname))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_lastname');
      }
    if (!zen_not_null($contact2_phone))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_phone');
      }
    if (!zen_not_null($contact2_email))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_email');
      }
*/
    if (!zen_not_null($vehicle_year))  {
      $error = true;
      $messageStack->add('vehicle year', 'Please fill in the vehicle_year');
      }
    if (!zen_not_null($vehicle_make))  {
      $error = true;
      $messageStack->add('vehicle make', 'Please fill in the vehicle_make');
      }
    if (!zen_not_null($vehicle_model))  {
      $error = true;
      $messageStack->add('vehicle model', 'Please fill in the vehicle_model');
      }
    if (!zen_not_null($vehicle_mileage))  {
      $error = true;
      $messageStack->add('vehicle mileage', 'Please fill in the vehicle_mileage');
      }

   if ($error == false) {

// grab some customer info if logged in
      if(isset($_SESSION['customer_id'])) {
        $check_customer = $db->Execute("select first_name, last_name, email_address from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
        $email_address = $check_customer->fields['email_address'];
        $customer_name = $check_customer->fields['first_name'] . ' ' . $check_customer->fields['last_name'];
      } else {
        $email_address = 'Not logged in';
        $customer_name = 'Not logged in';
      }


//assemble the email contents:
      $email_text = 'Vehicle Data Submission: ' . "\n" .
        '------------------------------------------------------' . "\n" .
        'First Name:' . "\t" . $first_name . "\n" .
        'Last Name:' . "\t" . $last_name . "\n" .
        'Phone Number:' . "\t" . $phone_number . "\n" .
        'Email Address:' . "\t" . $email_address . "\n" .
        'Mailing City:' . "\t" . $mailing_city. "\n" .
        'Vehicle Year:' . "\t" . $vehicle_year . "\n" .
        'Vehicle Make:' . "\t" . $vehicle_make . "\n" .
        'Vehicle Model:' . "\t" . $vehicle_model . "\n" .
        'Vehicle Mileage:' . "\t" . $vehicle_mileage . "\n" .
        'Comments:' . "\t" . $comments . "\n\n" .
        '------------------------------------------------------' . "\n" .
        OFFICE_USE . "\t" . "\n" .
        OFFICE_LOGIN_NAME . "\t" . $customer_name . "\n" .
        OFFICE_LOGIN_EMAIL . "\t" . $customer_email . "\n" .
        OFFICE_IP_ADDRESS . "\t" . $_SERVER['REMOTE_ADDR'] . "\n" .
        OFFICE_HOST_ADDRESS . "\t" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n" .
        OFFICE_DATE_TIME . "\t" . date("D M j Y G:i:s T") . "\n" .
        '------------------------------------------------------' . "\n\n" .
      $email_text = zen_output_string_protected($email_text);
      $email_html = nl2br("\n" . $email_text);
	  
	
    
	  
//send the email
      zen_mail(STORE_NAME, SEND_TO_ADDRESS, EMAIL_SUBJECT, $email_text, $first_name . ' ' . $last_name, $email_address, array('EMAIL_MESSAGE_HTML' => $email_html), 'vehicle_tradein', $att_array);

      zen_redirect(zen_href_link(FILENAME_VEHICLE_TRADEIN, 'action=success'));
      } //endif $error=false

  } // endif action

// default email and name if customer is logged in
  if(isset($_SESSION['customer_id'])) {
      $check_customer = $db->Execute("select first_name, last_name, email_address from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
      if ($email_address == '') $email_address = $check_customer->fields['email_address'];
      if ($first_name == '') $first_name = $check_customer->fields['first_name'];
      if ($last_name == '') $last_name = $check_customer->fields['last_name'];
  }

?>

and this is the code to my tpl.vehicle.tradein.default.php file

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | [email protected] so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: tpl_band_signup_default.php,v 1.3 2007/06/07 00:00:00 DrByteZen Exp $
//
?>
<div class="centerColumn" id="bandSignupDefault">

<h1 id="bandSignupDefaultHeading"><?php echo HEADING_TITLE; ?></h1>


<?php if ($messageStack->size('vehicle_tradein') > 0) echo $messageStack->output('vehicle_tradein'); ?>

<?php
  if (isset($_GET['action']) && ($_GET['action'] == 'success')) {
?>
<div class="mainContent success"><?php echo TEXT_SUCCESS; ?></div>

<div class="buttonRow"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_BACK, BUTTON_BACK_ALT) . '</a>'; ?></div>

<?php
  } else {
?>
<?php echo zen_draw_form('vehicle_tradein', zen_href_link(FILENAME_VEHICLE_TRADEIN, 'action=send')); ?>

<div id="bandSignupContent" class="content">
<fieldset id="bandSignup-Info">
<legend>Contact Information</legend>
<div class="alert forward"><?php echo FORM_REQUIRED_INFORMATION; ?></div>
<br class="clearBoth" />

<label class="inputLabel" for="first_name">First Name:</label>
<?php echo zen_draw_input_field('first_name', zen_output_string_protected($first_name), ' size="70" id="first_name"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

<label class="inputLabel" for="last_name">Last Name:</label>
<?php echo zen_draw_input_field('last_name', zen_output_string_protected($last_name), ' size="70" id="last_name"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

<label class="inputLabel" for="phone_number">Phone Number:</label>
<?php echo zen_draw_input_field('phone_number', zen_output_string_protected($phone_number), ' size="70" id="phone_number"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

<label class="inputLabel" for="email_address">Email Address:</label>
<?php echo zen_draw_input_field('email_address', zen_output_string_protected($email_address), ' size="70" id="email_address"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

<label class="inputLabel" for="mailing_city">City:</label>
<?php echo zen_draw_input_field('mailing_city', zen_output_string_protected($mailing_city), ' size="70" id="mailing_city"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>
</fieldset>

<fieldset id="bandSignup-Payment">
<legend>Vehicle Information</legend>

<label class="inputLabel" for="vehicle_year">Vehicle Year:</label>
<?php echo zen_draw_input_field('vehicle_year', zen_output_string_protected($vehcile_year), ' size="70" id="vehicle_year"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

<label class="inputLabel" for="vehicle_make">Vehicle Make:</label>
<?php echo zen_draw_input_field('vehicle_make', zen_output_string_protected($vehicle_make), ' size="70" id="vehicle_make"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

<label class="inputLabel" for="vehicle_model">Vehicle Model:</label>
<?php echo zen_draw_input_field('vehicle_model', zen_output_string_protected($vehicle_model), ' size="70" id="vehicle_model"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

<label class="inputLabel" for="vehicle_mileage">Vehicle Mileage:</label>
<?php echo zen_draw_input_field('vehicle_mileage', zen_output_string_protected($vehicle_mileage), ' size="70" id="vehicle_mileage"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

<br class="clearBoth" />
</fieldset>

<fieldset id="bandSignup-Payment">
<legend>Additional Comments</legend>
<?php echo zen_draw_textarea_field('comments', 30, 4, zen_output_string_protected($comments), 'id="comments"'); ?>
</fieldset>

<fieldset id="bandSignup-Payment">
<legend>Vehicle Images</legend>
<label class="inputLabel" for="image1"><?php echo 'Image 1' ?></label> 
<?php echo zen_draw_file_field('ufile[]'); ?> 
<br class="clearBoth" /> 
<label class="inputLabel" for="image2"><?php echo 'Image 2' ?></label> 
<?php echo zen_draw_file_field('ufile[]'); ?> 
<br class="clearBoth" /> 
</fieldset>






<div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_SEND, BUTTON_SEND_ALT); ?></div>



<br class="clearBoth" />
</div>
</form>

<?php
  }
?>
</div>

A little more imput would be greatly appreciate. Thank you Drbyte

17 Jan 2013, 10:45 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding Multiple Images to Custom form To be sent to Admin Email

You need to do something in your code to set $path1, $path2, $attachment_filetype, etc, such as by processing the uploaded data in the $_FILES array
General information about uploading files via PHP can be found on the PHP documentation site at http://php.net/manual/en/features.file-upload.post-method.php

17 Jan 2013, 11:16 PM
#10
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

I'm not quite sure what else to add...I do understand what you are saying. What other code would I need to add to make this work. I'm just learning how to use php. I know i'm almost there...thanks to your contribution.

17 Jan 2013, 11:25 PM
#11
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

ok I found this code that will process that data with the $_FILES array, but not sure if this is correct or if I need to add any more information.

// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
18 Jan 2013, 12:44 AM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding Multiple Images to Custom form To be sent to Admin Email

  1. To do uploads, you need to change the form attributes:```
<?php echo zen_draw_form('vehicle_tradein', zen_href_link(FILENAME_VEHICLE_TRADEIN, 'action=send')); ?>

must change to:

<?php echo zen_draw_form('vehicle_tradein', zen_href_link(FILENAME_VEHICLE_TRADEIN, 'action=send')[B], 'POST', 'enctype="multipart/form-data"'[/B]); ?>

2. Adding this in place of your $att_array lines might do the job:```
$att_array = array();
include(DIR_WS_CLASSES . 'upload.php');
foreach($_FILES as $key => $file) {
  if (zen_not_null($_FILES[$key]['tmp_name'])) {
    if ($upload = new upload($key, DIR_FS_UPLOADS)) {
        $att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
    }
  }
}
18 Jan 2013, 1:14 AM
#13
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

ok when I added these lines i'm getting a red rectangle on the form success page that says warning no file uploaded.

18 Jan 2013, 1:18 AM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding Multiple Images to Custom form To be sent to Admin Email

Then you'll need to do some debugging to find out what's failing where and why.
It could be permissions problems.
It could be form problems.
It could be a logic error.
etc.

I don't have this code installed on any sites. I spent an hour to research existing Zen Cart code and wrote my post based on things already working in regular Zen Cart.
My code could be wrong.

18 Jan 2013, 1:22 AM
#15
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

I'm not getting any debug errors in the cache folder, and I have the images/uploads/ set to 777. So not really not sure what might be causing this problem.

18 Jan 2013, 7:00 PM
#16
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

Thank you drbyte for your help....I finally got it working. With your help and the help of reasearch I was able to figure it out. I really appreciate the contribution you provide the Zen Cart community. I will post updated information later about how I got it working....so other's can benefit from this forum.

18 Feb 2013, 11:35 PM
#17
mutinyzoo avatar

mutinyzoo

New Zenner

Join Date:
Mar 2011
Location:
Pensacola, FL
Posts:
88
Plugin Contributions:
2

Re: Adding Multiple Images to Custom form To be sent to Admin Email

GodfatherAntiques:

Thank you drbyte for your help....I finally got it working. With your help and the help of reasearch I was able to figure it out. I really appreciate the contribution you provide the Zen Cart community. I will post updated information later about how I got it working....so other's can benefit from this forum.

Here's one zenner who would definitely appreciate your updates, GF. I'm hoping to do the same thing. - mike

6 Mar 2013, 5:31 PM
#18
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

1st you have to create /includes/extra_datafiles/your_custom_file_name.php

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | [email protected] so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+


  define('FILENAME_VEHICLE_TRADEIN', 'vehicle_tradein');
6 Mar 2013, 5:33 PM
#19
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

2nd you need to create /includes/languages/english/your_custom_file_name.php

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | [email protected] so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: band_signup.php,v 1.3 2007/06/07 00:00:00 DrByteZen Exp $
//

define('HEADING_TITLE', 'Vehicle Trade-In Appraisal');
define('NAVBAR_TITLE', 'Vehicle Trade In');
define('TEXT_SUCCESS', 'Thank you for your enquiry, we will contact you shortly.');
define('EMAIL_SUBJECT', 'Site Vehicle Trade-In Form');

define('ENTRY_NAME', 'Full Name:');
define('ENTRY_EMAIL', 'E-Mail Address:');
define('ENTRY_ENQUIRY', 'Message:');

define('SEND_TO_ADDRESS', STORE_OWNER_EMAIL_ADDRESS);
define('SIGN_US_UP','SIGN US UP!');
6 Mar 2013, 5:34 PM
#20
godfatherantiques avatar

godfatherantiques

Zen Follower

Join Date:
Nov 2010
Posts:
101
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

3rd you have to create /includes/modules/pages/your_custom_folder_name/header_php.php

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | [email protected] so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: header_php.php,v 1.3 2007/06/07 00:00:00 DrByteZen Exp $
//
  require(DIR_WS_MODULES . 'require_languages.php');
  include(DIR_WS_CLASSES . 'upload.php');
  $breadcrumb->add(NAVBAR_TITLE);
  

  $error = false;
  $first_name = '';
  $last_name = '';
  $phone_number = '';
  $email_address = '';
  $mailing_city = '';
  $vehicle_year = '';
  $vehicle_make = '';
  $vehicle_model = '';
  $vehicle_mileage = '';
  $comments = '';


  if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
    $first_name = zen_db_prepare_input($_POST['first_name']);
    $last_name = zen_db_prepare_input($_POST['last_name']);
    $phone_number = zen_db_prepare_input($_POST['phone_number']);
    $email_address = zen_db_prepare_input($_POST['email_address']);
    $mailing_city = zen_db_prepare_input($_POST['mailing_city']);
    $vehicle_year = zen_db_prepare_input($_POST['vehicle_year']);
    $vehicle_make = zen_db_prepare_input($_POST['vehicle_make']);
    $vehicle_model = zen_db_prepare_input($_POST['vehicle_model']);
    $vehicle_mileage = zen_db_prepare_input($_POST['vehicle_mileage']);
    $comments = zen_db_prepare_input(strip_tags($_POST['comments']));
	$att_array = array();
	foreach($_FILES as $key => $file) {
  if (zen_not_null($_FILES[$key]['tmp_name'])) {
    if ($upload = new upload($key, DIR_FS_UPLOADS)) {
        $att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
    }
  }
}
	//Get the uploaded file information
	$name_of_uploaded_file =    basename($_FILES['uploaded_file']['name']); 
	//get the file extension of the file
	$type_of_uploaded_file =    substr($name_of_uploaded_file,   
	strrpos($name_of_uploaded_file, '.') + 1); $size_of_uploaded_file =    $_FILES["uploaded_file"]["size"]/1024;//size in KBs
	
	$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
	$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
	if(is_uploaded_file($tmp_path))
	{  
	if(!copy($tmp_path,$path_of_uploaded_file))  {    $errors .= '\n error while copying the uploaded file';  }}
	
	

    if (!zen_validate_email($email_address))  {
      $error = true;
      $messageStack->add('email address', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
      }
    if (!zen_not_null($first_name))  {
      $error = true;
      $messageStack->add('first name', 'Please fill in the first_name');
      }
    if (!zen_not_null($last_name))  {
      $error = true;
      $messageStack->add('last name', 'Please fill in the last_name');
      }
    if (!zen_not_null($phone_number))  {
      $error = true;
      $messageStack->add('phone number', 'Please fill in the phone_number');
      }
    if (!zen_not_null($email_address))  {
      $error = true;
      $messageStack->add('email address', 'Please fill in the email_address');
      }
    if (!zen_not_null($mailing_city))  {
      $error = true;
      $messageStack->add('mailing city', 'Please fill in the mailing_city');
      }
/*
    if (!zen_not_null($contact2_firstname))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_firstname');
      }
    if (!zen_not_null($contact2_lastname))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_lastname');
      }
    if (!zen_not_null($contact2_phone))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_phone');
      }
    if (!zen_not_null($contact2_email))  {
      $error = true;
      $messageStack->add('band_signup', 'Please fill in the contact2_email');
      }
*/
    if (!zen_not_null($vehicle_year))  {
      $error = true;
      $messageStack->add('vehicle year', 'Please fill in the vehicle_year');
      }
    if (!zen_not_null($vehicle_make))  {
      $error = true;
      $messageStack->add('vehicle make', 'Please fill in the vehicle_make');
      }
    if (!zen_not_null($vehicle_model))  {
      $error = true;
      $messageStack->add('vehicle model', 'Please fill in the vehicle_model');
      }
    if (!zen_not_null($vehicle_mileage))  {
      $error = true;
      $messageStack->add('vehicle mileage', 'Please fill in the vehicle_mileage');
      }

   if ($error == false) {




//assemble the email contents:
      $email_text = 'Vehicle Data Submission: ' . "\n" .
        '------------------------------------------------------' . "\n" .
        'First Name:' . "\t" . $first_name . "\n" .
        'Last Name:' . "\t" . $last_name . "\n" .
        'Phone Number:' . "\t" . $phone_number . "\n" .
        'Email Address:' . "\t" . $email_address . "\n" .
        'Mailing City:' . "\t" . $mailing_city. "\n" .
        'Vehicle Year:' . "\t" . $vehicle_year . "\n" .
        'Vehicle Make:' . "\t" . $vehicle_make . "\n" .
        'Vehicle Model:' . "\t" . $vehicle_model . "\n" .
        'Vehicle Mileage:' . "\t" . $vehicle_mileage . "\n" .
        'Comments:' . "\t" . $comments . "\n\n" .
        '------------------------------------------------------' . "\n" .
        OFFICE_USE . "\t" . "\n" .
        OFFICE_LOGIN_NAME . "\t" . $customer_name . "\n" .
        OFFICE_LOGIN_EMAIL . "\t" . $customer_email . "\n" .
        OFFICE_IP_ADDRESS . "\t" . $_SERVER['REMOTE_ADDR'] . "\n" .
        OFFICE_HOST_ADDRESS . "\t" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n" .
        OFFICE_DATE_TIME . "\t" . date("D M j Y G:i:s T") . "\n" .
        '------------------------------------------------------' . "\n\n" .
      $email_text = zen_output_string_protected($email_text);
      $email_html = nl2br("\n" . $email_text);
	  
	  
	
    
	  
//send the email
      zen_mail(STORE_NAME, SEND_TO_ADDRESS, EMAIL_SUBJECT, $email_text, $first_name . ' ' . $last_name, $email_address, array('EMAIL_MESSAGE_HTML' => $email_html), 'vehicle_tradein', $att_array);

      zen_redirect(zen_href_link(FILENAME_VEHICLE_TRADEIN, 'action=success'));
      } //endif $error=false

  } // endif action



?>