Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

3bsstudio

Adding a telephone field to the contact form

Recommended Posts

Hi

First off, I know I'm running osCommerce 2.2-MS2 - please don't mock me for it - we have no choice but will be changing it in the future!

In the meantime I'm having trouble adding a telephone field to the main contact form.

Got it to show OK on the page by adding:
<tr>
                <td class="main"><?php echo ENTRY_TELEPHONE_NUMBER; ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('telephone'); ?></td>
              </tr>
to the contact_us.php

Also added:
define('ENTRY_TELEPHONE_NUMBER', 'Telephone Number:');
to includes/languages/english/contact_us.php

but when the form is sent the telephone number doesn't appear in the email message.

Any ideas why - can't seem to find what I'm missing?
 

Thanks in advance

contact-form.jpg

Share this post


Link to post
Share on other sites
    $name = tep_db_prepare_input(ucwords($_POST['name']));
    $email_address = tep_db_prepare_input($_POST['email']);
    $phone = tep_db_prepare_input($_POST['phone']);
    $subject = tep_db_prepare_input(ucwords($_POST['subject']));
    $enquiry = tep_db_prepare_input(ucwords($_POST['enquiry']));

 

        $text = ENTRY_NAME . ' ' . $name
           . "\n" . ENTRY_TELEPHONE_NUMBER . ' ' . $phone
           . "\n" . ENTRY_EMAIL . ' ' . $email_address
           . "\n\n" . BOX_HEADING_SUBJECT . ' ' . $subject
           . "\n" . ENTRY_ENQUIRY . "\n" . $enquiry;

 

    tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $text, $name, STORE_OWNER_EMAIL_ADDRESS, $phone);

 

<tr>
                <td class="main"><?php echo ENTRY_TELEPHONE_NUMBER; ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('phone'); ?></td>
              </tr>

 

Edited by YePix

Share this post


Link to post
Share on other sites

Hi

Thanks for the reply. Working my way through seems OK until this bit:

<tr>
        <td class="fieldKey"><?php echo ENTRY_NAME; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('name'); ?></td>
      </tr>
      <tr>
        <td class="fieldKey"><?php echo ENTRY_EMAIL; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('email'); ?></td>
      </tr>

My code is different and looks like this:
<tr>
                <td class="main"><?php echo ENTRY_NAME; ?></td></tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('name'); ?></td></tr>
              <tr>
                <td class="main"><?php echo ENTRY_TELEPHONE_NUMBER; ?></td> </tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('telephone'); ?></td></tr>
              <tr>
                <td class="main"><?php echo ENTRY_EMAIL; ?></td></tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('email'); ?></td></tr>
              <tr>
                <td class="main"><?php echo ENTRY_ENQUIRY; ?></td></tr>
              <tr>
                <td><?php echo tep_draw_textarea_field('enquiry', 'soft', 50, 15); ?></td>
              </tr>

 

Website URL: https://gasbottlesdirect.co.uk/contact_us.php

Edited by 3bsstudio
Add website URL

Share this post


Link to post
Share on other sites
vor 1 Stunde schrieb 3bsstudio:

Hi

Thanks for the reply. Working my way through seems OK until this bit:

<tr>
        <td class="fieldKey"><?php echo ENTRY_NAME; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('name'); ?></td>
      </tr>
      <tr>
        <td class="fieldKey"><?php echo ENTRY_EMAIL; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('email'); ?></td>
      </tr>

My code is different and looks like this:
<tr>
                <td class="main"><?php echo ENTRY_NAME; ?></td></tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('name'); ?></td></tr>
              <tr>
                <td class="main"><?php echo ENTRY_TELEPHONE_NUMBER; ?></td> </tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('telephone'); ?></td></tr>
              <tr>
                <td class="main"><?php echo ENTRY_EMAIL; ?></td></tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('email'); ?></td></tr>
              <tr>
                <td class="main"><?php echo ENTRY_ENQUIRY; ?></td></tr>
              <tr>
                <td><?php echo tep_draw_textarea_field('enquiry', 'soft', 50, 15); ?></td>
              </tr>

 

Website URL: https://gasbottlesdirect.co.uk/contact_us.php

Change telephone to phone or vice versa and everything will work. It is important that the variables match

or send me the complete contact_us.php. I don't think you'll get any support here for 2.2.

Edited by YePix

Share this post


Link to post
Share on other sites

Potential spam : be careful, remove your email adress (sales@...)  in your last message.

You have a typo error in this line :

<td class="main"><?php echo tep_draw_input_field(‘telephone’); ?></td>

you should use apostrophes like this:

<td class="main"><?php echo tep_draw_input_field('telephone'); ?></td>

 


with OsC 2.2 since 2006 ...

Share this post


Link to post
Share on other sites

Try this

<?php
/*
  $Id: contact_us.php,v 1.42 2003/06/12 12:17:07 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

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

  $error = false;
  if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {
        $secret = '6LfjSr4UAAAAAKlThMtas78PrxscmSpZoHeRcs_D';
        $ch = curl_init();        
        curl_setopt_array($ch, array(
                CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
                CURLOPT_POST => true,
                CURLOPT_POSTFIELDS => array(
                        'secret' => $secret,
                        'response' => $HTTP_POST_VARS['g-recaptcha-response'],
                        'remoteip' => $_SERVER['REMOTE_ADDR']
                ), 
                CURLOPT_RETURNTRANSFER => true
        ));
        $verifyResponse = curl_exec($ch);
        curl_close($ch);
        $responseData = json_decode($verifyResponse);  
        if($responseData->success){
      
    $name = tep_db_prepare_input(ucwords($_POST['name']));
    $email_address = tep_db_prepare_input($_POST['email']);
    $phone = tep_db_prepare_input($_POST['phone']);
    $subject = tep_db_prepare_input(ucwords($_POST['subject']));
    $enquiry = tep_db_prepare_input(ucwords($_POST['enquiry']));

        $text = ENTRY_NAME . ' ' . $name
           . "\n" . ENTRY_TELEPHONE_NUMBER . ' ' . $phone
           . "\n" . ENTRY_EMAIL . ' ' . $email_address
           . "\n" . ENTRY_ENQUIRY . "\n" . $enquiry;

                if (tep_validate_email($email_address)) {

                if (strpos($enquiry, "href") > 1) {
                }else {
                      tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $text, $name, STORE_OWNER_EMAIL_ADDRESS, $phone);
                }
                      tep_redirect(tep_href_link(FILENAME_CONTACT_US, 'action=success'));
                    } else {
                      $error = true;

                      $messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
                    }
            }else{
                    $error = true;
                    $messageStack->add('contact', 'Robot verification failed, please try again.');
            }
  }

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_CONTACT_US));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">

</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">

<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<style type="text/javascript">
.terms-conditions{font-size: 13px;}
</style>
<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><?php echo tep_draw_form('contact_us', tep_href_link(FILENAME_CONTACT_US, 'action=send')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php
  if ($messageStack->size('contact') > 0) {
?>
      <tr>
        <td><?php echo $messageStack->output('contact'); ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php
  }

  if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'success')) {
?>
      <tr>
        <td class="main" align="left"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_wave.gif', HEADING_TITLE, '0', '0', 'align="left"') . TEXT_SUCCESS; ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
<?php
  } else {
?>
<!-- start mod anagram -->
      <tr>
        <td class="main"><STRONG><?php echo nl2br(STORE_NAME_ADDRESS); ?></STRONG><br><br></td>
      </tr>
<!-- end mod anagram -->
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
 
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
               <tr>
                <td class="main"><?php echo ENTRY_NAME; ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('name'); ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo ENTRY_TELEPHONE_NUMBER; ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('phone'); ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo ENTRY_EMAIL; ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo tep_draw_input_field('email'); ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo ENTRY_ENQUIRY; ?></td>
              </tr>
              <tr>
                <td><?php echo tep_draw_textarea_field('enquiry', 'soft', 50, 15); ?></td>
              </tr>
              
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
	   <tr>
			<td class="terms-conditions">
				
				<p style="font-size:12px"> <input type="checkbox" id="privacypolicy" /> Please confirm you consent to the storage and handling of your data by this website in order to answer your enquiry or to supply you with the information you require.</p>
				<p style="font-size:12px">If you don't wish to give consent then please call us on 01903 700778 with your query.</p>
				<p style="font-size:12px">We won't receive this form unless you give consent.</p>
				<p style="font-size:12px">Please see our <a href="/privacy.php" style="color: red; text-decoration: none; font-weight: bold;" target="_blank">Privacy and Data Policy</a> for details of what we do with your supplied infomation.</p>
                                <style> 
                                    .required{
                                        color:red;
                                    }
                                    .g-recaptcha div {
                                        margin: auto;
                                    }
                                </style>
                                <script type="text/javascript" src='https://www.google.com/recaptcha/api.js'></script>
                               
                                <div id="g-recaptcha" class="g-recaptcha" data-sitekey="6LfjSr4UAAAAAMuhHo-vC9tx0TVUn68igMlQpzyc"></div>
                                <div id="msgcaptcha" class="g-recaptcha error" style="color: red;"></div>
				<br/>
			</td>
		  </tr>
                  
      <tr>
          
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td align="right ">
                    <img   style="float: right;" src="/includes/languages/english/images/buttons/button_continue.gif"  onclick="myFunction()" />
                    <input style="display:none"  id="myDIV" style="float: right;" src="includes/languages/english/images/buttons/button_continue.gif" alt="Continue"  title=" Continue " type="image" border="0">
                    <?php //echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
            </table></td>
          </tr>
		 
        </table></td>
      </tr>
	  <script type="text/javascript">
	  function myFunction() 
	  {
		  if (document.getElementById("privacypolicy").checked == true) {
				var x = document.getElementsByName("contact_us");
                                var recaptcha = document.getElementById("g-recaptcha-response").value;
                                    if (recaptcha === "") {
                                        document.getElementById("msgcaptcha").innerHTML = "Please check the recaptcha";
                                        return false;
                                    }
					x[0].submit();
			}
			else
			{
				alert("Please confirm you consent to the storage and handling of your data by this website in order to answer your enquiry or to supply you with the information you require.");
			}
		}
</script>
<?php
  }
?>
    </table></form></td>


<!-- body_text_eof //-->
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
    </table></td>
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>

</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

 

Share this post


Link to post
Share on other sites

Thank you bonbec - who'd have thought a wrong style quotes would make such a difference. Amended those and the telephone comes through fine.

Thanks YePix but that would still have been wrong...

I just needed to change: $text, $name, STORE_OWNER_EMAIL_ADDRESS, $phone); to
$text, $name, $email_address, $phone);
so now the form comes through with the correct reply email.

Thanks for all your help it is now all sorted.

Share this post


Link to post
Share on other sites

As I said it works great now. The only issue - the telephone number is not currently a required field. How do I change it to a required field?

TIA.

Share this post


Link to post
Share on other sites

maybe that's it

 

  if (empty($_POST["phone"])) {
    phoneErr = "phone is required";
  } else {
    $phone = tep_db_prepare_input($_POST['phone']);
  }

<td class="main"><?php echo tep_draw_input_field('phone '); ?><?php echo phoneErr;?></td>

 

Share this post


Link to post
Share on other sites

try it like this

catalog/includes/form_check.js.php

Finde:
Find:

  check_input("email_address", <?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>, "<?php echo ENTRY_EMAIL_ADDRESS_ERROR; ?>");

Füge danach inzu:
Add after:

  check_input("phone", <?php echo ENTRY_PHONE_MIN_LENGTH; ?>, "<?php echo ENTRY_PHONE_ERROR; ?>");
 
catalog/includes/languages/"your_language_file".php

Finde:
Find:

  define('ENTRY_EMAIL_ADDRESS_ERROR', 'Your E-Mail Address must contain a minimum of ' . ENTRY_EMAIL_ADDRESS_MIN_LENGTH . ' characters.');

Füge danach inzu:
Add after:

  define('ENTRY_PHONE_MIN_LENGTH', '5');
  define('ENTRY_PHONE_ERROR', 'Your phonenumber must contain a minimum of ' . ENTRY_PHONE_MIN_LENGTH . ' characters.');

 

Share this post


Link to post
Share on other sites

Thanks YePix but that is already there.

I'm thinking the verify telephone has to go in here (see below) from contact_us.php as the email verification is here.
I tried adding: if (tep_validate_telephone($telephone)) {  after the email line but it blew the page. Any ideas?

    $text = ENTRY_NAME . ' ' . $name
           . "\n" . ENTRY_TELEPHONE_NUMBER . ' ' . $telephone
           . "\n" . ENTRY_EMAIL . ' ' . $email_address
           . "\n" . ENTRY_ENQUIRY . "\n" . $enquiry;

                if (tep_validate_email($email_address)) {


                if (strpos($enquiry, "href") > 1) {
                }else {
                      tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $text, $name, $email_address, $telephone);
                }
                      tep_redirect(tep_href_link(FILENAME_CONTACT_US, 'action=success'));
                    } else {
                      $error = true;

                      $messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
                    }
            }else{
                    $error = true;
                    $messageStack->add('contact', 'Robot verification failed, please try again.');
            }
  }

Share this post


Link to post
Share on other sites

if (tep_validate_email($email_address)) {
Checks whether the specified email address was entered correctly.

You find this in:
catalog/includes/functions/validations.php

try it with that:

  if (empty($_POST[" telephone "])) {
    phoneErr = "phone is required";
  } else {
    $ telephone = tep_db_prepare_input($_POST[' telephone ']);
  }

Share this post


Link to post
Share on other sites

I was right where it goes. Correct version is this under email verification:

if (!tep_validate_email($email_address)) {     
                          $error = true;
                          $messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
                      } 

                      if($telephone==''){
                          $error = true;
                          $messageStack->add('contact', ENTRY_TELEPHONE_CHECK_ERROR);
                      } 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×