7

Add customers phone to the contact us form in osCommerce

multimixer | learn | Friday November 26 2010

Do you need your clients phone?

The “contact us” form consist in osCommerce of 3 fields: name, email and enquiry. What if you need for example your visitors phone number, so you can call them back?

The default contact us form in osCommerce

Let’s add one more field to the contact us form. I’ll explain here how to do it for a phone number, you can do it for virtually any additional information you need.

Since we talk about the “contact us” form, the closest file to look at is of course the file catalog/contact_us.php. There is no real difference between RC2a and v2.3. LIne numbers in this post refer to v2.3

We’re going to add the input field for the phone number right under the email address field. The lines we need are

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

That’s the creation of the input field for the email. We just copy it, make it to be an input field for the phone number and add our new code just after

      <tr>
        <td class="fieldKey"><?php echo ENTRY_PHONE; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('phone'); ?></td>
      </tr>

Next thing is to include the phone number into the email. The section of the file that do this is here

    $name = tep_db_prepare_input($HTTP_POST_VARS['name']);
    $email_address = tep_db_prepare_input($HTTP_POST_VARS['email']);
    $enquiry = tep_db_prepare_input($HTTP_POST_VARS['enquiry']);

Here we define 2 new variables $phone and $email_body by adding this just after

	// add phone 26 11 10
	$phone = tep_db_prepare_input($HTTP_POST_VARS['phone']);
	// add email body 26 11 10
	$email_body = EMAIL_TEXT_CUSTOMER_NAME . ' ' . $name . "\r\n" . EMAIL_TEXT_CUSTOMER_EMAIL . ' ' .  $email_address . "\r\n" . EMAIL_TEXT_CUSTOMER_PHONE . ' ' . $phone . "\r\n" . EMAIL_TEXT_CUSTOMER_MESSAGE . ' ' . $enquiry;

To $email_body we added the existing $name, $email_address and $enquiry. It’s much more handy that way, because we can add to it any new field we need anytime

Next thing is to include our new created $email_body into the mail function. So we replace in the existing function

      tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $enquiry, $name, $email_address);

the $enquiry with $email_body, so it looks like this

      tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $email_body, $name, $email_address);

Last thing is to define what the text entries, like “ENTRY_PHONE” are.. If we don’t do it we will see the words “ENTRY_PHONE” printed on our screen. To do this, we need to go to file catalog/includes/languages/english/contact_us.php and add following definitions to the end of the file, before the last ?>

define('EMAIL_TEXT_CUSTOMER_NAME', 'Name:');
define('EMAIL_TEXT_CUSTOMER_EMAIL', 'email:');
define('EMAIL_TEXT_CUSTOMER_PHONE', 'Phone:');
define('EMAIL_TEXT_CUSTOMER_MESSAGE', 'Message:');
define('ENTRY_PHONE', 'Your phone number:');

That’s it. Now we can take a look at our contact us page

Phone number input field added

In the same way you can create input field for any type of information, a new second text-area, a checkbox, a drop-down or radio buttons. There are pre-defined functions in osCommerce that make it easy

Enjoy

Click +1 to recommend this to your friends when they search.

multimixer

follow multimixer on Twitter

Follow me on twitter. I'm not tweeting all day long and guaranteed no spam and no advertising.

If you like what you read and if you think it will help you in your online business, then please consider a donation.

There is no obligation to do so and all information provided here is free to use.

It will however help to keep this blog alive, free of advertising and full of content.

  • Ipod Cases 23/04/2011 at 06:56

    I am not a PHP programmer and I appreciate the TUT’s! I think you may have an error in the last part of your tutorial here. The line:

    define(‘EMAIL_TEXT_CUSTOMER_MESSAGE’, ‘Message:’);

    Was listed twice so I think you may have meant to add:

    define(‘ENTRY_PHONE’, ‘Your Phone Number:’);

    instead.

    Thanks again for the TUT’s!

    • multimixer 27/04/2011 at 09:55

      You are right, that was a mistake from my side, thanks for pointing that out. It’s corrected now

  • jeovanni 26/04/2011 at 18:28

    i didadd the file as exlained but i stiil see ENTRY_PHONE on my screen.

    thank for the Help!!!!

    really apreciaed

    • multimixer 27/04/2011 at 09:58

      There was a small mistake from my side, as pointed out in the comment above.

      Following was listed twice and wrong:
      define(‘EMAIL_TEXT_CUSTOMER_MESSAGE’, ‘Your Phone Number:’);

      Delete the above line and replace it with:
      define(‘ENTRY_PHONE’, ‘Your Phone Number:’);

      The post is corrected now, so you can take the relevant code from there and copy it into your file

  • stefan 17/06/2011 at 21:53

    Hi. Can you show us please how to add a drop down list to a field in this form?
    Thx!

    • stefan 19/06/2011 at 08:12

      Did it. If anyone is intrested:

      ’6′, ‘text’ => ‘Bentley’);
      $model[] = array(‘id’ => ’7′, ‘text’ => ‘BMW’);
      $model[] = array(‘id’ => ’8′, ‘text’ => ‘Bugatti’);
      $model[] = array(‘id’ => ’9′, ‘text’ => ‘Buick’);
      ?>

      and all the other lines Multimixer said.
      Hope this help.

  • Alain 11/07/2011 at 19:53

    Hi,
    I’m trying to add informations on the contact page under the contact form.
    I’d like to add adress, phone etc. and also a script from googlemaps.

    I have version 2.3.1

    thanks for help.

Leave a Reply