Jump to content


  • Content count

  • Joined

  • Last visited

Profile Information

  • Real Name
    Mike Brant
  1. mikebrant

    Super Contact us enhancement 1.0

    Sorry, I just saw your posted code. I am glad you got it worked out anyway. Mike
  2. mikebrant

    Super Contact us enhancement 1.0

    mojon, I had this problem for a while. What I found the issue was is that in the contribution documentation, they tell you to change a few lines of code where you reload the page (tep_redirect function) to pass or detect (isset) the parameter action="success" when it really does not need to be changed. I messed around with this for several hours before finally figuring out that you pretty much need to leave the code as it was. What happens is that you end up changing the email validation warning to appear on action=success when that should not be happening. Take a look at the complete contact_us.php code I posted just before your message to get a better idea of which isset and tep_redirect lines should should have send vs. success as the action parameter (you can ignore the other modifications I made to this file if you don't need that functionality, the redirect and isset lines were not altered by my modifications other than to change them back to where they work). Note that I also added a component to many of the "isset" lines to check whether the $error flag was set to 1 as well. Mike
  3. mikebrant

    Super Contact us enhancement 1.0

    The next functionality item I wanted to add, was to upload customer names, email address, and newsletter option into the database when the contact us form is submitted. Sorry if my message above about the newsletter was unclear - the code listed there simply adds a checkbox to page and inserts a line into email message if the user elects to join the maling list. The code in this post actually writes the newsletter selection to the database along with other variables. This code is inserted directly after the lines where the email address is validated and the message is sent. Please note that there are a couple of differences here from the standard Super Contact Us code. the first is that the tep_mail line uses some variables instead of constants for the email recipient name and address. This is due to some code I have above these lines (not shown) where I select the recipient based on the indicated email reason. You can simply use the regular Super Contact Us code with the constants and this will function exactly the same. Also note that there is a second tep_mail line that is part of a different contribution (Admin Edit Email) which allows functionality to send a copy of the email back to user. This code should be omitted if you don't use use this contribution (the code is denoted by comments). One thing I will be adding shortly is the ability to populate the address_book table with the first and last names of the user if they are not already populated. This is actually a pretty simple task that would be achived in much the same way that I update the customer table. I will post the modified code when completed. As of right now, I do not overwrite any existing customer name data in the database. This code only populates these values if they are empty. Certainly if one wanted to, they could add some sort of functionality to compare and evaluate which data to keep, but I figure it is best to leave overwriting that sort of data to the account modification scripts. if (tep_validate_email($email_address)) { // original code: tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $enquiry, $name, $email_address); tep_mail($email_recipient, $recipient_address, $emailsubject, $enquiry, $name, $email_address); // replacement code for Super Contact Us enhancement 1.41. Note: first two variables are derived from custom code above. // lines added for Admin_Edit_Email functionality. This allows for an automatic response to be sent to those sending a Contact_Us message. if(SEND_CONTACT_US_RESPONSE=='true') { tep_mail($name, $email_address, CONTACT_US_RESPONSE_EMAIL_SUBJECT, CONTACT_US_RESPONSE_EMAIL_TEXT."\n\n-------------------------Your Message:\n".$enquiry, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); } // end Admin_Edit_Email addition // custom code to seperate first name and last name (ignores middle names if provided) $namearray = explode(' ',$name); $namecount = sizeof($namearray)-1; $firstname = $namearray[0]; $lastname = $namearray[$namecount]; //custom code end // custom code to check for newsletter checkbox setting if (isset($HTTP_POST_VARS['newsletter']) && ($HTTP_POST_VARS['newsletter'] == 1)) { $newsletter = tep_db_prepare_input($HTTP_POST_VARS['newsletter']); } else { $newsletter = false; } // end custom code // add custom code to add user information from contact us fields into database - modeled after code on create_account.php page // note $email_address variable has already been prepared for database input above // check to see if email address already exists in database $check_email_query = tep_db_query("select count(*) as total from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'"); $check_email = tep_db_fetch_array($check_email_query); if ($check_email['total'] > 0) { // email address already exists in database, so we query other related data for customer table $customer_table_query = tep_db_query("SELECT customers_id, customers_default_address_id, customers_firstname, customers_lastname, customers_newsletter FROM " . TABLE_CUSTOMERS . " WHERE customers_email_address = '" . tep_db_input($email_address) . "'"); $customer_table_data = tep_db_fetch_array($customer_table_query); $customer_id = $customer_table_data['customers_id']; // zero out key variables $address_id = 0; $update_needed = 0; $sql_data_array = array(); $inserttoggle = 0; // end variable reset // check related customer info and address book tables to verify that there are corresponding row entries for this customer id. If not they are added. $customer_info_table_query = tep_db_query("SELECT count(*) as total from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . tep_db_input($customer_id) . "'"); $customer_info_table_data_check = tep_db_fetch_array($customer_info_table_query); if ($customer_info_table_data_check['total'] == 0) { tep_db_query("INSERT INTO " . TABLE_CUSTOMERS_INFO . " (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created) values ('" . (int)$customer_id . "', '0', now())"); } $address_book_table_query = tep_db_query("SELECT count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . tep_db_input($customer_id) . "'"); $address_book_table_data_check = tep_db_fetch_array($address_book_table_query); if ($address_book_table_data_check['total'] == 0) { tep_db_query("INSERT INTO " . TABLE_ADDRESS_BOOK . " SET customers_id = '" . (int)$customer_id . "'"); $address_id = tep_db_insert_id(); } // end check of related tables $check_customers_default_address_id = isset($customer_table_data['customers_default_address_id']); $check_customers_firstname = isset($customer_table_data['customers_firstname']); $check_customers_lastname = isset($customer_table_data['customers_lastname']); $check_customers_newsletter = isset($customer_table_data['customers_newsletter']); // build customer table update query based on comparison of already existing values to values entered in form $customer_table_update_query = "UPDATE " . TABLE_CUSTOMERS . " SET "; if ($check_customers_default_address_id === false) { $customer_table_update_query .= "customers_default_address_id = '" . $address_id . "' "; $update_needed = 1; } if ($check_customers_firstname === false) { $customer_table_update_query .= "customers_firstname = '" . $firstname . "' "; $update_needed = 1; } if ($check_customers_lastname === false) { $customer_table_update_query .= "customers_lastname = '" . $lastname . "' "; $update_needed = 1; } if ($check_customers_newsletter === false) { $customer_table_update_query .= "customers_newsletter = '" . $newsletter . "' "; $update_needed = 1; } elseif ($customer_table_data['newsletter'] == false && $newsletter == 1) { $customer_table_update_query .= "customers_newsletter = '" . $newsletter . "' "; $update_needed = 1; } $customer_table_update_query .= "WHERE customers_id = '" . (int)$customer_id . "'"; if ($update_needed == 1) tep_db_query($customer_table_update_query); // update customer table if needed } else { // used when no existing email address exists in database $sql_data_array = array(); // create array for uploading to customer table and upload $sql_data_array = array('customers_firstname' => $firstname, 'customers_lastname' => $lastname, 'customers_email_address' => $email_address, 'customers_newsletter' => $newsletter); tep_db_perform(TABLE_CUSTOMERS, $sql_data_array); $customer_id = tep_db_insert_id(); // modify array and add to address book $sql_data_array = array('customers_id' => $customer_id, 'entry_firstname' => $firstname_for_db, 'entry_lastname' => $lastname_for_db); tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array); $address_id = tep_db_insert_id(); // further modify customer and customer info tables tep_db_query("update " . TABLE_CUSTOMERS . " set customers_default_address_id = '" . (int)$address_id . "' where customers_id = '" . (int)$customer_id . "'"); tep_db_query("insert into " . TABLE_CUSTOMERS_INFO . " (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created) values ('" . (int)$customer_id . "', '0', now())"); }
  4. mikebrant

    Super Contact us enhancement 1.0

    I have been doing some more tinkering to add some more functionality to the contact_us page. Again I figured I would post to see if this helps anyone or to see if anyone can detect errors in the coding. There are a couple of additional functinality items I wanted to add to the contact_us page when using this contribution. The first was to add a simple checkbox that would allow that user to sign up for a newsletter/mailing list and populate the existing 'customers_newsletter' field in the customer table. This is very similar to what is done on the create_account page, but figured it would be nice to be able to to do this without forcing the user to create a full-fledged acount profile. I did this by inserting the following code (I placed mine under the main message text field, but you can insert whever you like): <?php // custom code to add "join mailing list" checkbox echo tep_draw_checkbox_field('newsletter', '1', true) . ' ' . JOIN_NEWSLETTER_TEXT; // end custom code ?> Note, that I also defined the JOIN_NEWSLETTER_TEXT constant in the contact us langauge file, but I will omit this code here. I then addded a short bit of code near the top of the file where the email message body is compiled as shown (note I have kept in a few rows before and after for context). This again involved defining the NEWSLETTER_OPT_IN_MESSAGE constant in the contact us language script. }else{ $enquiry = tep_db_prepare_input($HTTP_POST_VARS['enquiry']); // original code line which is now an else condition } // custom code to add newsletter subscription notification into email if (isset($HTTP_POST_VARS['newsletter']) && ($HTTP_POST_VARS['newsletter'] == 1)) { $enquiry .= "\n\n" . NEWSLETTER_OPT_IN_MESSAGE; } // end custom code $emailsubject = tep_db_prepare_input($HTTP_POST_VARS['reason']) . ' ' . EMAIL_SUBJECT; The next functionality add I will post in a seperate post below to allow for seperate replies.
  5. mikebrant

    Super Contact us enhancement 1.0

    Thanks to all who have worked on this contribution. After spending some time integrating and customizing this solution for my store, I figured I would post some code that I added to fix one minor issue with the way the form is populated for cases when the user enters an invalid email address. Hopefully others will find this useful. Currently, all the fields except the contact reason drop-down menu are automatically re-populated when the user gets the "invalid email" warning (I honestly don't use the CONTACT_US_LIST radio/drop-down field as I prefer to route my customer messages based on the reason for contact, so I don't know if this field re-populates). This is obviously good, such that the user doesn't have to re-type everything they had previously entered. I added one line of code to the Contact_Us language file (English language only, but the fix is the same for other languages) and a section to the Contact_Us.php page to address this problem. This also prevents the need to modify the Contact_US.php page if you change the number of "reasons" in the language file". The new line is at the bottom of this code (obviously my contact reasons are not the defaults,but this doesn't matter): define('REASONS1', ' Merchandise Question'); define('REASONS2', ' Order-related Question'); define('REASONS3', ' Store Information Request'); define('REASONS4', ' General Comments'); define('REASONS5', ' Business-related Question'); define('REASONS6', ' Website Questions'); $contact_reason_array = array(REASONS1, REASONS2, REASONS3, REASONS4, REASONS5, REASONS6); // custom add to automate drop-down box population. To create additional reasons, add Define statement above and add defined constant to array. This contact reason array is then used in the main Contact_Us.php file as shown below. Please note that I retained a few lines before and after this drop-down box section so you can see the context. All my additions are noted with comments, as are the replaced default code lines. <?php echo ENTRY_REASON; ?><br> <select name="reason"> <?php // custom code added to pre-select drop-down list value if it was previously selected but page was reloaded due to invalid email address $select_toggle = array(); if (isset($HTTP_POST_VARS['reason'])) { $reason_to_select = $HTTP_POST_VARS['reason']; foreach ($contact_reason_array as $reason) { $select_toggle[$reason] = ""; $key = $reason; if ($key == $reason_to_select) { $select_toggle[$reason] = " selected=\"selected\""; } } } else { $i = 0; foreach ($contact_reason_array as $reason) { if ($i == 0) { $select_toggle[$reason] = " selected=\"selected\""; } else { $select_toggle[$reason] = ""; } $i++; } } foreach ($select_toggle as $reason => $toggle) { echo '<option value="' . $reason . '"' . $toggle. '>' . $reason . '</option>'; } // end custom code /* original code which has been replaced <?php echo '<option value="' . REASONS1 . '">' . REASONS1 . '</option>'; ?> <?php echo '<option value="' . REASONS2 . '">' . REASONS2 . '</option>'; ?> <?php echo '<option value="' . REASONS3 . '">' . REASONS3 . '</option>'; ?> <?php echo '<option value="' . REASONS4 . '">' . REASONS4 . '</option>'; ?> <?php echo '<option value="' . REASONS5 . '">' . REASONS5 . '</option>'; ?> <?php echo '<option value="' . REASONS6 . '">' . REASONS6 . '</option>'; ?> */ ?> </select><br /> <?php echo ENTRY_ENQUIRY; ?><BR> Note that the "else" portion of my added code serves to generate the default drop-down box when the page is first visited (i.e. before there is an invalid email error). I have my code set to have my first reason as the pre-selected value in this case, but you can easily adjust which reason you want pre-selected by adjusting the value condition in if($i == 0) statement. Mike