Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Modified Contact page.


Darkayer

Recommended Posts

Hello,

 

I'm currently working on a modified contact form.

This is a pretty large form with some required fields but apperntly I'm doing something wrong because the check isnt working correctly.

 

The thing is when I fill in all fields the form keeps saying I need to fill in some fields :S

 

Maybe you have any idea what is going wrong.

 

Some code

 

Top of contact page

elseif (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {
$_POST['email'] = preg_replace( "/\n/", " ", $_POST['email'] ); 
$_POST['name'] = preg_replace( "/\n/", " ", $_POST['name'] ); 
$_POST['phone'] = preg_replace( "/\n/", " ", $_POST['phone'] ); 
$_POST['email'] = preg_replace( "/\r/", " ", $_POST['email'] ); 
$_POST['name'] = preg_replace( "/\r/", " ", $_POST['name'] ); 
$_POST['phone'] = preg_replace( "/\r/", " ", $_POST['phone'] );
$_POST['email'] = str_replace("Content-Type:","",$_POST['email']); 
$_POST['name'] = str_replace("Content-Type:","",$_POST['name']); 
$_POST['phone'] = str_replace("Content-Type:","",$_POST['phone']); 
$debi = tep_db_prepare_input($_POST['debi']);
$bedrijf = tep_db_prepare_input($_POST['bedrijf']);
$voornaam = tep_db_prepare_input($_POST['voornaam']);
$achternaam = tep_db_prepare_input($POST['achternaam']);
$tussen = tep_db_prepare_input($POST['tussen']);
$straat = tep_db_prepare_input($POST['straat']);
$nummer = tep_db_prepare_input($POST['nummer']);
$toevoeging = tep_db_prepare_input($POST['toevoeging']);
$postcode = tep_db_prepare_input($POST['postcode']);
$plaats = tep_db_prepare_input($POST['plaats']);
$land = tep_db_prepare_input($POST['land']);
$website = tep_db_prepare_input($POST['website']);
$phone = tep_db_prepare_input($HTTP_POST_VARS['phone']);
$gsm = tep_db_prepare_input($HTTP_POST_VARS['gsm']);
$fax = tep_db_prepare_input($HTTP_POST_VARS['fax']);
$btw = tep_db_prepare_input($HTTP_POST_VARS['btw']);
$kvk = tep_db_prepare_input($HTTP_POST_VARS['kvk']);
$email_address = tep_db_prepare_input($_POST['email']);
$enquiry = tep_db_prepare_input($_POST['enquiry']);
$enquiry = tep_db_prepare_input($enquiry . "\n\n IP: " . $_SERVER['REMOTE_ADDR']);

 

   if (tep_validate_email(!empty($email_address)&&(!empty($bedrijf)&&(!empty($voornaam)&&(!empty($achternaam)&&(!empty($straat)&&(!empty($nummer)&&(!empty($postcode)&&(!empty($plaats)&&(!empty($land))))))))))) {
     tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, "Debiteurcode: " ,  $debi , "\n" , "Bedrijfsnaam: " ,  $bedrijf 
     , "\n" , "Voornaam:" , $voornaam , "\n" , "Achternaam: " ,  $achternaam , "\n" , "Tussenvoegsel: " ,  $tussen , "\n" , "Straat: " ,  $straat
      , "\n" , "Huisnummer: " ,  $nummer , "\n" , "Huisnummer toevoeging: " , $toevoeging , "\n" , "Postcode: " , $postcode , "\n" , "Plaats: " , $plaats 
, "\n" , "Land: " , $land , "\n" , "Website: " , $website , "\n" , "Email-adres: " , $email_address , "\n" , "Telefoonnummer: " , $phone , "\n" , "GSM nummer: " , $gsm ,
"\n" , "Fax: " , $fax , "\n" , "BTW Nummer: " , $btw , "\n" , "KVK Nummer: " , $kvk ); 

 

   } else {
     $error = true;
if(!tep_validate_email($email_address))
     $messageStack->add('contact', ENTRY_EADRES_TEXT_ERROR);
if(empty($bedrijf))
   $messageStack->add('contact' , ENTRY_BEDRIJFSNAAM_TEXT_ERROR);    
if(empty($voornaam))
$messageStack->add('contact' , ENTRY_VOORNAAM_TEXT_ERROR);
if(empty($achternaam))
$messageStack->add('contact' , ENTRY_ACHTER_TEXT_ERROR);
if(empty($straat))
$messageStack->add('contact' , ENTRY_STRAAT_TEXT_ERROR);
if(empty($nummer))
$messageStack->add('contact' , ENTRY_NUMMER_TEXT_ERROR);
if(empty($postcode))
$messageStack->add('contact', ENTRY_POSTCODE_TEXT_ERROR);
if(empty($plaats))
$messageStack->add('contact', ENTRY_PLAATS_TEXT_ERROR);
if(empty($land))
$messageStack->add('contact', ENTRY_LAND_TEXT_ERROR);   
    }
 }

 

One entry field

           <tr>
               <td class="main"><?php echo ENTRY_ACHTERNAAM; ?></td>
             </tr>
             <tr>
               <td class="main"><?php echo tep_draw_input_field('achternaam') . ' ' . (tep_not_null(ENTRY_ACHTER_TEXT) ? '<span class="inputRequirement">' . ENTRY_ACHTER_TEXT . '</span>': ''); ?></td>
             </tr>  

Link to comment
Share on other sites

Changed the top bit to look like this.

 

elseif (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {
$_POST['email'] = preg_replace( "/\n/", " ", $_POST['email'] ); 
$_POST['name'] = preg_replace( "/\n/", " ", $_POST['name'] ); 
$_POST['phone'] = preg_replace( "/\n/", " ", $_POST['phone'] ); 
$_POST['email'] = preg_replace( "/\r/", " ", $_POST['email'] ); 
$_POST['name'] = preg_replace( "/\r/", " ", $_POST['name'] ); 
$_POST['phone'] = preg_replace( "/\r/", " ", $_POST['phone'] );
$_POST['email'] = str_replace("Content-Type:","",$_POST['email']); 
$_POST['name'] = str_replace("Content-Type:","",$_POST['name']); 
$_POST['phone'] = str_replace("Content-Type:","",$_POST['phone']); 
$debi = tep_db_prepare_input($_POST['debi']);
$bedrijf = tep_db_prepare_input($_POST['bedrijf']);
$voornaam = tep_db_prepare_input($_POST['voornaam']);
$achternaam = tep_db_prepare_input($_POST['achternaam']);
$tussen = tep_db_prepare_input($_POST['tussen']);
$straat = tep_db_prepare_input($_POST['straat']);
$nummer = tep_db_prepare_input($_POST['nummer']);
$toevoeging = tep_db_prepare_input($_POST['toevoeging']);
$postcode = tep_db_prepare_input($_POST['postcode']);
$plaats = tep_db_prepare_input($_POST['plaats']);
$land = tep_db_prepare_input($_POST['land']);
$website = tep_db_prepare_input($_POST['website']);
$phone = tep_db_prepare_input($_POST['phone']);
$gsm = tep_db_prepare_input($_POST['gsm']);
$fax = tep_db_prepare_input($_POST['fax']);
$btw = tep_db_prepare_input($_POST['btw']);
$kvk = tep_db_prepare_input($_POST['kvk']);
$email_address = tep_db_prepare_input($_POST['email']);
$enquiry = tep_db_prepare_input($_POST['enquiry']);
$enquiry = tep_db_prepare_input($enquiry . "\n\n IP: " . $_SERVER['REMOTE_ADDR']);

 

That kind fixxed the problem with field not being seen as filled in.

Now the second problem is that the form will not send.

 

If I click the send button it just refreshes the page and nothing happens.

The filled in information remains in the fields.

 

Help please :)

Link to comment
Share on other sites

 

1 st check your getting data into all the form fields, do this by examining the post vars, ie:

 

 

print_r(array_values($_POST));

 

 

Your validation is limited & wont stop all hacks (& fail a PCI check), I would use an allowed list in preferance, ie:

 

// clean posted vars
reset($_POST);
         while (list($key, $value) = each($_POST)) {
              	if (!is_array($_POST[$key])) {
                     $_POST[$key] = preg_replace("/[^\p{L}\p{M}\w@ :{}_.-]/i", "", urldecode($vars));
           	} else { unset($_POST[$key]); } // no arrays expected 
         }

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

But this doesnt show me why nothing is getting send when I push the send button right?

 

 

No, it tells you what is getting sent, so you can examine your form to see why if not all there or if all the fields are getting sent then examine your code to see why its not passing.

 

 

Did you need that spelt out??

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

But this doesnt show me why nothing is getting send when I push the send button right?

 

 

No, it tells you what is getting sent, so you can examine your form to see why if not all there or if all the fields are getting sent then examine your code to see why its not passing.

 

 

Did you need that spelt out??

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Sorry I missunderstood. smile.gif

 

Can you please give me an example how to put this in my code so I can get the output?

 

 

If you add that line at the start of the file after your

elseif (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {

you will see the array contents, though the display may cause a following headers already sent error.

 

If you see nothing (say array is empty!!) add immediatly after

tep_top();

that will cause a fatal error immediatly after the array display, so you can see whats there, or not.

 

 

If nothing changes, you have another error stopping your line above getting past.

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Well I tried it. But it seems everyfield gets what I put in them.

 

Array ( [0] => Test0 [1] => Test1 [2] => Test2 [3] => Test3 [4] => Test4 [5] => Test5 [6] => Test6 [7] => Test7 [8] => Test8 [9] => Test9 [10] => Test10 [11] => Test11 [12] => [email protected] [13] => Test13 [14] => Test14 [15] => Test15 [16] => Test16 [17] => Test17 [18] => 105 [19] => 14 ) 

 

So I still cant find why I get no succes page and no mail in my inbox :(

Link to comment
Share on other sites

 

Ok, now you know you have data you know its your code checks thats wrong.

 

You are mixing $_POST & $HTTP_POST_VARS that causes issues on some servers, at the start of your code add:

 

$HTTP_POST_VARS =&  $_POST;

 

 

this line is wrong

 

if (tep_validate_email(!empty($email_address)&&(!empty($bedrijf)&&(!empty($voornaam)&&(!empty($achternaam)&&(!empty($straat)&&(!empty($nummer)&&(!empty($postcode)&&(!empty($plaats)&&(!empty($land))))))))))) {

 

 

for one email check should be tep_validate_email($email_address); You don't need all those !empty just the var on is own is fine, as if empty doing if ($nummer) will return false , but there is a better way, if no fields may be empty, check with my code

 

 

$error = false;
reset($_POST);
while (list($key, $value) = each($_POST)) {
if (!is_array($_POST[$key])) {
  	$_POST[$key] = preg_replace("/[^\p{L}\p{M}\w@ :{}_.-]/i", "", urldecode($vars));
  	if (!$_POST[$key]) $error = true;
} else { unset($_POST[$key]); } // no arrays expected 
}

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

I had a similar problem with a checke for information page unlimited. I think it was after a security addon and sanitazing / changing to $_POST

 

I had to use $_get[action] insted of $action

 

try to change to this may help......

if (tep_validate_email(!empty($_GET[email_address])&&(!

Link to comment
Share on other sites

Sam,

 

Thank you for your help so far.

I've got a feeling i'm getting somewhere now ;)

 

I got rid of the dirty !empty check stuff. And implemented some contrib I found to check for required fields.

It seems to work so far.

 

I changed some lines

 if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {

$debi = tep_db_prepare_input($HTTP_POST_VARS['debi']);
$bedrijf = tep_db_prepare_input($HTTP_POST_VARS['bedrijf']);
$voornaam = tep_db_prepare_input($HTTP_POST_VARS['voornaam']);
$achternaam = tep_db_prepare_input($HTTP_POST_VARS['achternaam']);
$tussen = tep_db_prepare_input($HTTP_POST_VARS['tussen']);
$straat = tep_db_prepare_input($HTTP_POST_VARS['straat']);
$nummer = tep_db_prepare_input($HTTP_POST_VARS['nummer']);
$toevoeging = tep_db_prepare_input($HTTP_POST_VARS['toevoeging']);
$postcode = tep_db_prepare_input($HTTP_POST_VARS['postcode']);
$plaats = tep_db_prepare_input($HTTP_POST_VARS['plaats']);
$land = tep_db_prepare_input($HTTP_POST_VARS['land']);
$website = tep_db_prepare_input($HTTP_POST_VARS['website']);
$phone = tep_db_prepare_input($HTTP_POST_VARS['phone']);
$gsm = tep_db_prepare_input($HTTP_POST_VARS['gsm']);
$fax = tep_db_prepare_input($HTTP_POST_VARS['fax']);
$btw = tep_db_prepare_input($HTTP_POST_VARS['btw']);
$kvk = tep_db_prepare_input($HTTP_POST_VARS['kvk']);
$email_address = tep_db_prepare_input($HTTP_POST_VARS['email']);
$enquiry = tep_db_prepare_input($HTTP_POST_VARS['enquiry']);


   if (tep_validate_email($email_address)) {      
   	tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $enquiry, $bedrijf, $email_address); 

 

The thing is now.. I'm getting a nice mail in my mailbox with nothing in it. Only the data I put in field $enquiry gets in the mail.

pretty obvious though.

 

But when I add , $debi , $bedrijf ......... it doesnt put it in the mail..

Link to comment
Share on other sites

You have only $enquiry in the tep_mail function and this is also one of your input fields

 

Make a $email_body (or whatever) and add to it all the stuff you want to be send + some text etc, similar to this

	$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 ;

 

Then replace $enquiry with $email_body in your tep_mail

Link to comment
Share on other sites

You have only $enquiry in the tep_mail function and this is also one of your input fields

 

Make a $email_body (or whatever) and add to it all the stuff you want to be send + some text etc, similar to this

	$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 ;

 

Then replace $enquiry with $email_body in your tep_mail

 

Thank you for helping with this.

 

I changed the code arround like you said but still nothing in my mail.

   if (tep_validate_email($email_address)) {      
   	tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $email_body, $email_address); 

   	$email_body = ENTRY_DEBI . ' ' . $debi . "\r\n" . ENTRY_BEDRIJF . ' ' .  $bedrijf . "\r\n" . ENTRY_VOORNAAM . ' ' . $voornaam . "\r\n" . ENTRY_ACHTERNAAM. ' ' . $achternaam . "\r\n";

 

BTW I'm using

$debi = tep_db_prepare_input($HTTP_POST_VARS['debi']);
$bedrijf = tep_db_prepare_input($HTTP_POST_VARS['bedrijf']);
$voornaam = tep_db_prepare_input($HTTP_POST_VARS['voornaam']);
$achternaam = tep_db_prepare_input($HTTP_POST_VARS['achternaam']);

now should I change HTTP_POST_VARS back to _POST or is this the good way to do it?

Link to comment
Share on other sites

Well, you need to say what $email_body is before the tep_mail, if you say it after, how will tep_mail know what you mean?

 

How silly of me :) fixxed it!

 

It seems to work now! Thank you very very much!!

Link to comment
Share on other sites

I've got another question about my mail form.

 

Currently I'm putting in a option selection field.

How can I make this field a required one?

 

			<td class="main"><?php echo ENTRY_REASON; ?></td>
			<td class="main"><select name="reason">
						<?php echo '<option value="' . REASONS1 . '">' . REASONS1 . '</option>' . ' ' . (tep_not_null(ENTRY_REASON_TEXT) ? '<span class="inputRequirement">' . ENTRY_REASON_TEXT . '</span>': ''); ?>
					<?php echo '<option value="' . REASONS2 . '">' . REASONS2 . '</option>'; ?>
					<?php echo '<option value="' . REASONS2 . '">' . REASONS3 . '</option>'; ?>
				</select></td>
		</tr>

 

Doesnt seem to do it.

Link to comment
Share on other sites

 

 

Have you defined ENTRY_REASON_TEXT ?

 

This thread details the correct method for drop downs.

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...