Zen Cart Logo
Forums / General Questions / Make subject field optional on contact_us

Make subject field optional on contact_us

Views: 1,793

Results 1 to 14 of 14
25 Jul 2016, 2:23 PM
#1
gunni avatar

gunni

Zen Follower

Join Date:
Aug 2010
Location:
Israel
Posts:
287
Plugin Contributions:
0

Make subject field optional on contact_us

Hi,
Did not find any solution for making a field - not a required field.
I use the standard Contact us form.
I commented out lines 85-87 @ header_php.php

//if (empty($subject)) {
   //  $messageStack->add('contact', ENTRY_EMAIL_SUBJECT_CHECK_ERROR);
  //  }

but when submitting the form, it does nothing. Not a sent confirmation and not
a failure confirmation.
What did I do wrong ?

25 Jul 2016, 3:51 PM
#2
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,956
Plugin Contributions:
8

Re: Make subject field optional on contact_us

what version of ZC are you running?

at some point, perhaps 1.5.4 or 1.5.5, the logging of failed sending of emails improved dramatically.

are there any logs in your log directory?

25 Jul 2016, 3:56 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,081
Plugin Contributions:
56

Re: Make subject field optional on contact_us

gunni:

Hi,
Did not find any solution for making a field - not a required field.
I use the standard Contact us form.
I commented out lines 85-87 @ header_php.php

//if (empty($subject)) {
// $messageStack->add('contact', ENTRY_EMAIL_SUBJECT_CHECK_ERROR);
// }

> 
> but when submitting the form, it does nothing. Not a sent confirmation and not 
> a failure confirmation.
> What did I do wrong ?
Just a note about the highlighted section in the original post:  The behavior described is not present in the "standard" (i.e. as-shipped Zen Cart) contact_us page's processing.  I've seen that change introduced with some of the picaflor-azul templates, though.
27 Jul 2016, 3:11 PM
#4
gunni avatar

gunni

Zen Follower

Join Date:
Aug 2010
Location:
Israel
Posts:
287
Plugin Contributions:
0

Re: Make subject field optional on contact_us

lat9:

Just a note about the highlighted section in the original post: The behavior described is not present in the "standard" (i.e. as-shipped Zen Cart) contact_us page's processing. I've seen that change introduced with some of the picaflor-azul templates, though.

Sorry. You are right. I use sheffield blue 2 of Picaflor-azul.
Did not know she made some changes in it.
I will ask her about it in her thread.

27 Jul 2016, 3:13 PM
#5
gunni avatar

gunni

Zen Follower

Join Date:
Aug 2010
Location:
Israel
Posts:
287
Plugin Contributions:
0

Re: Make subject field optional on contact_us

carlwhat:

what version of ZC are you running?

at some point, perhaps 1.5.4 or 1.5.5, the logging of failed sending of emails improved dramatically.

are there any logs in your log directory?

I use 1.5.4
Did not check logs because it works well before I changed the code...

27 Jul 2016, 3:19 PM
#6
gunni avatar

gunni

Zen Follower

Join Date:
Aug 2010
Location:
Israel
Posts:
287
Plugin Contributions:
0

Re: Make subject field optional on contact_us

Hi Anne and everybody,
1.5.4 + SB2 (Sheffield Blue 2.0 :smartalec: )

Did not find any solution for making a field to be not a required field in the contact us form.
I commented out lines 85-87 @ header_php.php

//if (empty($subject)) {
   //  $messageStack->add('contact', ENTRY_EMAIL_SUBJECT_CHECK_ERROR);
  //  }

but when submitting the form, it does nothing. Not a sent confirmation and not
a failure confirmation.
What did I do wrong ?

27 Jul 2016, 4:01 PM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Make subject field optional on contact_us

gunni:

Hi Anne and everybody,
1.5.4 + SB2 (Sheffield Blue 2.0 :smartalec: )

Did not find any solution for making a field to be not a required field in the contact us form.
I commented out lines 85-87 @ header_php.php

//if (empty($subject)) {
// $messageStack->add('contact', ENTRY_EMAIL_SUBJECT_CHECK_ERROR);
// }

> but when submitting the form, it does nothing. Not a sent confirmation and not 
> a failure confirmation.
> What did I do wrong ?

I don't have ready access to the fileset, but when looking at the default version of includes/modules/pages/contact_us/header_php.php there is a similar check for empty fields. The information that has been commented out is the "error" message that is presented because an earlier check (presumably !empty($subject)) failed and prevented processing the email.

Because the alert was commented out, this is why you don't see anything related to the message whether an error or success.

Typically just around the check for antispam, is a test for all of the "necessary" values being empty or not. If you are going to allow your customers to submit a form with an empty value, it may be best to check for that empty value and if it is empty to then substitute something applicable instead of the form being submitted without content being present.

Ultimately if you don't want to worry about that extra field, then you would want to completely remove it, that would be to comment it out on the template file and then to also comment out any related logic in the header file... such an action may affect page layout, but at least then it would be omitted.
28 Jul 2016, 1:12 AM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Make subject field optional on contact_us

gunni:

I use 1.5.4
Did not check logs because it works well before I changed the code...

The code "change" simply prevented the display of the fact that the subject was blank. It did not allow the subject to be blank. Code like that is found higher up in an if statement. Something like

 if (!empty($subject) && !empty($body) && etc... ){
 // process code
} else {
 if (empty($subject)) {
 // display empty subject error message
 }
 if (empty($body)) {
 // display empty body error message
 }

While there are differences in that template it would appear that the same logic is applied as the base install. Just has more fields.

28 Jul 2016, 11:02 AM
#9
gunni avatar

gunni

Zen Follower

Join Date:
Aug 2010
Location:
Israel
Posts:
287
Plugin Contributions:
0

Re: Make subject field optional on contact_us

mc12345678:

I don't have ready access to the fileset, but when looking at the default version of includes/modules/pages/contact_us/header_php.php there is a similar check for empty fields. The information that has been commented out is the "error" message that is presented because an earlier check (presumably !empty($subject)) failed and prevented processing the email.

Because the alert was commented out, this is why you don't see anything related to the message whether an error or success.

Typically just around the check for antispam, is a test for all of the "necessary" values being empty or not. If you are going to allow your customers to submit a form with an empty value, it may be best to check for that empty value and if it is empty to then substitute something applicable instead of the form being submitted without content being present.

Ultimately if you don't want to worry about that extra field, then you would want to completely remove it, that would be to comment it out on the template file and then to also comment out any related logic in the header file... such an action may affect page layout, but at least then it would be omitted.

Much thanks for pointing out the things !
According to your suggestion I deleted the previous // and changed the code in the header_php.php as follows:

<?php
/**
 * Contact Us Page
 *
 * @package page
 * @copyright Copyright 2003-2012 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version GIT: $Id: Author: DrByte  Sat Jul 21 16:05:31 2012 -0400 Modified in v1.5.1 $
 * Updated Contact Us Subject for v1.5.1 by Judy Gunderson (stellarweb) 2013-08-16
 */

// This should be first line of the script:
$zco_notifier->notify('NOTIFY_HEADER_START_CONTACT_US');

require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));

$error = false;
if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
  $name = zen_db_prepare_input($_POST['contactname']);
  $email_address = zen_db_prepare_input($_POST['email']);
  $subject = zen_db_prepare_input($_POST['subject']);
  $enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));
  $antiSpam = isset($_POST['should_be_empty']) ? zen_db_prepare_input($_POST['should_be_empty']) : '';
  $zco_notifier->notify('NOTIFY_CONTACT_US_CAPTCHA_CHECK');

  $zc_validate_email = zen_validate_email($email_address);


  //if ($zc_validate_email and !empty($enquiry) and !empty($name) I deleted this==>and !empty($subject) <== && $error == FALSE) {
	  if ($zc_validate_email and !empty($enquiry) and !empty($name) && $error == FALSE) {
    // if anti-spam is not triggered, prepare and send email:
   if ($antiSpam != '') {
      $zco_notifier->notify('NOTIFY_SPAM_DETECTED_USING_CONTACT_US');
   } elseif ($antiSpam == '') {

    // auto complete when logged in
    if($_SESSION['customer_id']) {
      $sql = "SELECT customers_id, customers_firstname, customers_lastname, customers_password, customers_email_address, customers_default_address_id
              FROM " . TABLE_CUSTOMERS . "
              WHERE customers_id = :customersID";

      $sql = $db->bindVars($sql, ':customersID', $_SESSION['customer_id'], 'integer');
      $check_customer = $db->Execute($sql);
      $customer_email= $check_customer->fields['customers_email_address'];
      $customer_name= $check_customer->fields['customers_firstname'] . ' ' . $check_customer->fields['customers_lastname'];
    } else {
      $customer_email = NOT_LOGGED_IN_TEXT;
      $customer_name = NOT_LOGGED_IN_TEXT;
    }

    // use contact us dropdown if defined
    if (CONTACT_US_LIST !=''){
      $send_to_array=explode("," ,CONTACT_US_LIST);
      preg_match('/\<[^>]+\>/', $send_to_array[$_POST['send_to']], $send_email_array);
      $send_to_email= preg_replace ("/>/", "", $send_email_array[0]);
      $send_to_email= trim(preg_replace("/</", "", $send_to_email));
      $send_to_name = trim(preg_replace('/\<[^*]*/', '', $send_to_array[$_POST['send_to']]));
    } else {  //otherwise default to EMAIL_FROM and store name
    $send_to_email = trim(EMAIL_FROM);
    $send_to_name =  trim(STORE_NAME);
    }

    // Prepare extra-info details
    $extra_info = email_collect_extra_info($name, $email_address, $customer_name, $customer_email);
    // Prepare Text-only portion of message
    $text_message = OFFICE_FROM . "\t" . $name . "\n" .
    OFFICE_EMAIL . "\t" . $email_address . "\n\n" .
    '------------------------------------------------------' . "\n\n" .
    strip_tags($_POST['enquiry']) .  "\n\n" .
    '------------------------------------------------------' . "\n\n" .
    $extra_info['TEXT'];
    // Prepare HTML-portion of message
    $html_msg['EMAIL_MESSAGE_HTML'] = strip_tags($_POST['enquiry']);
    $html_msg['CONTACT_US_OFFICE_FROM'] = OFFICE_FROM . ' ' . $name . '<br />' . OFFICE_EMAIL . '(' . $email_address . ')';
    $html_msg['EXTRA_INFO'] = $extra_info['HTML'];
    // Send message
    zen_mail($send_to_name, $send_to_email, $subject, $text_message, $name, $email_address, $html_msg,'contact_us');
   }
    zen_redirect(zen_href_link(FILENAME_CONTACT_US, 'action=success'));
  } else {
    $error = true;
    if (empty($name)) {
      $messageStack->add('contact', ENTRY_EMAIL_NAME_CHECK_ERROR);
    }
	if (empty($subject)) {
     $messageStack->add('contact', ENTRY_EMAIL_SUBJECT_CHECK_ERROR);
    }
    if ($zc_validate_email == false) {
      $messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
    }
    if (empty($enquiry)) {
      $messageStack->add('contact', ENTRY_EMAIL_CONTENT_CHECK_ERROR);
    }
  }
} // end action==send

// default email and name if customer is logged in
if($_SESSION['customer_id']) {
  $sql = "SELECT customers_id, customers_firstname, customers_lastname, customers_password, customers_email_address, customers_default_address_id
          FROM " . TABLE_CUSTOMERS . "
          WHERE customers_id = :customersID";

  $sql = $db->bindVars($sql, ':customersID', $_SESSION['customer_id'], 'integer');
  $check_customer = $db->Execute($sql);
  $email_address = $check_customer->fields['customers_email_address'];
  $name= $check_customer->fields['customers_firstname'] . ' ' . $check_customer->fields['customers_lastname'];
}

$send_to_array = array();
if (CONTACT_US_LIST !=''){
  foreach(explode(",", CONTACT_US_LIST) as $k => $v) {
    $send_to_array[] = array('id' => $k, 'text' => preg_replace('/\<[^*]*/', '', $v));
  }
}

// include template specific file name defines
$define_page = zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/html_includes/', FILENAME_DEFINE_CONTACT_US, 'false');

$breadcrumb->add(NAVBAR_TITLE);

// This should be the last line of the script:
$zco_notifier->notify('NOTIFY_HEADER_END_CONTACT_US');

All of this was made because I wanted to make a telephone field so the customer could write his telephone number when contacting but on the other hand I did not want it to be a must / required field.
(The telephone field is the subject field)
[I explain also to othersss...]

Thanks again Mc8!

28 Jul 2016, 11:39 AM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Make subject field optional on contact_us

Thing is, some servers will treat an email with a blank subject as spam. So should add a check within the modified if statement to see if the subject field is empty and if it is to put something in there. Ideally it would be something about your store or other "unique" information that you could possibly use as an indicator to know that it was left blank.

Ie.

 $subject = empty($subject) ? 'UNIQUE_TEXT' : $subject; 

Where UNIQUE_TEXT is the actual text desired to be used as the subject line if it were left blank.

28 Jul 2016, 2:23 PM
#11
gunni avatar

gunni

Zen Follower

Join Date:
Aug 2010
Location:
Israel
Posts:
287
Plugin Contributions:
0

Re: Make subject field optional on contact_us

mc12345678:

Thing is, some servers will treat an email with a blank subject as spam. So should add a check within the modified if statement to see if the subject field is empty and if it is to put something in there. Ideally it would be something about your store or other "unique" information that you could possibly use as an indicator to know that it was left blank.

Ie.

$subject = empty($subject) ? 'UNIQUE_TEXT' : $subject;

> Where UNIQUE_TEXT is the actual text desired to be used as the subject line if it were left blank.

Did not think about it :ohmy:
Put your code in the header_php.php and waiting to get my message now...
Got it with the 'UNIQUE_TEXT' :clap:
You are very appreciated MC8! !
28 Jul 2016, 3:02 PM
#12
gunni avatar

gunni

Zen Follower

Join Date:
Aug 2010
Location:
Israel
Posts:
287
Plugin Contributions:
0

Re: Make subject field optional on contact_us

Now I needed to remove the * from that line so people will know it is not required.
I thought it will be easy but it took some time.
Any1 who needs it:
/includes/templates/YOur template/templates/tpl_contact_us_default.php
around line #80:

<label class="inputLabel" for="subject"><?php echo ENTRY_EMAIL_SUBJECT; ?></label>
<?php echo zen_draw_input_field('subject', $subject, ' size="40" id="subject"') . '<span class="alert">' . '&nbsp' . '</span>'; ?>
<br class="clearBoth" />

ENTRY_REQUIRED_SYMBOL was removed and replaced by '&nbsp'

28 Jul 2016, 6:33 PM
#13
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Make subject field optional on contact_us

Or remove the whole span tag, since it is not used anymore.

<label class="inputLabel" for="subject"><?php echo ENTRY_EMAIL_SUBJECT; ?></label>
<?php echo zen_draw_input_field('subject', $subject, ' size="40" id="subject"'); ?>
<br class="clearBoth" />
29 Jul 2016, 8:20 AM
#14
gunni avatar

gunni

Zen Follower

Join Date:
Aug 2010
Location:
Israel
Posts:
287
Plugin Contributions:
0

Re: Make subject field optional on contact_us

Thanks :thumbsup: