Page 1 of 1

Drop-down country list in Contac Us

Posted: Mon Jun 13, 2022 5:16 am
by Tanya
I would like to add drop-down country list in Contact Us page. Not sure how to do that.

Now, I have copied contact_us.php in to templates/override and copy Full Name div and changed to Country. So I only have input field for Country not dropdown.

Re: Drop-down country list in Contac Us

Posted: Mon Jun 13, 2022 5:37 am
by ecartz
You can see an example with a dropdown at https://github.com/CE-PhoenixCart/Phoen ... L182..L187

Code: Select all

$input = new Select($name, array_merge(
  [['id' => '', 'text' => PULL_DOWN_DEFAULT]],
  $GLOBALS['db']->fetch_all("SELECT countries_id AS id, countries_name AS text FROM countries")
));

Re: Drop-down country list in Contac Us

Posted: Mon Jun 13, 2022 3:03 pm
by Tanya
@ecartz Thank you very much. I can add drop-down country list in Contac Us and also include country name in email which send from contact_us.php

For email which send from contact_us.php.
According to https://github.com/CE-PhoenixCart/Phoen ... y-to-email, I have set E-Mail From: noreply@mysite.com. And in email.php I have added my email in Reply-To. So Reply-To have 2 email addresses, my email and customer email

How to set send the mail to 2 email addresses, my email and customer email.

Re: Drop-down country list in Contac Us

Posted: Mon Jun 13, 2022 3:32 pm
by burt
You may have been able to do this with a Hook (rather than using a template file).

I'll try to make such a hook as it'll be good to see how it could (in theory) be done (obviously if it does then work, the hook could be replicated to add in other data to the contact_us form).

If I make it, I'll upload it to this thread for testing.

Re: Drop-down country list in Contac Us

Posted: Mon Jun 13, 2022 3:35 pm
by burt
Tanya wrote: Mon Jun 13, 2022 3:03 pm How to set send the mail to 2 email addresses, my email and customer email.
Add similar after this piece:

// to store owner from customer
Notifications::mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, sprintf(EMAIL_SUBJECT, STORE_NAME), $enquiry, $name, $email_address);

as so:

// to customer from store owner
Notifications::mail($name, $email_address, sprintf(EMAIL_SUBJECT, STORE_NAME), $enquiry, $name, $email_address, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

I don't quite see why the customer would need to have an email sent to them containing the data they just gave you, as they probably know what they wrote :D But, it's your shop and your needs...the above is how I may do it.

Re: Drop-down country list in Contact Us

Posted: Mon Jun 13, 2022 3:39 pm
by ecartz
Tanya wrote: Mon Jun 13, 2022 3:03 pm How to set send the mail to 2 email addresses, my email and customer email.
The easiest way is to send two copies of the email, like checkout and newsletters do.

But it's a bad idea to set up your Contact Us form to send emails to an email address entered in the form. Because that means that a spammer can use your form to send emails as if they were from you. It works during checkout because

1. The prospective spammer can't enter arbitrary content.
2. It requires a payment. And a spammer won't want to waste a perfectly good stolen credit card on sending a single spam email.

The Contact Us form does accept arbitrary content and doesn't require registration much less an order payment. It should not send to the customer (except possibly a form email like "Thank you for submitting a message.").

Re: Drop-down country list in Contac Us

Posted: Mon Jun 13, 2022 3:42 pm
by burt
Hook, completely untested, but looks like it should work to add the "Customer Location" to the email.
includes.zip
Note:
I am not saying this is the right way or the best way to add in extra data to the email.
It is simply a way that you may or may not have thought of.

Re: Drop-down country list in Contac Us

Posted: Mon Jun 13, 2022 8:33 pm
by Tanya
But it's a bad idea to set up your Contact Us form to send emails to an email address entered in the form. Because that means that a spammer can use your form to send emails as if they were from you.
@ecartz Thank you very much for your explanation. I haven't thought about it.


Hook, completely untested, but looks like it should work to add the "Customer Location" to the email.
@burt It worked like a charm! I never thought to use a hook this way.

In email the "Customer Location" show under the enquiry, is it possible to move it up to show before enquiry.

Re: Drop-down country list in Contac Us

Posted: Mon Jun 13, 2022 9:16 pm
by ecartz
Tanya wrote: Mon Jun 13, 2022 8:33 pm In email the "Customer Location" show under the enquiry, is it possible to move it up to show before enquiry.
Change to

Code: Select all

    return $GLOBALS['enquiry'] = sprintf(CUSTOMERS_LOCATION, Country::fetch_name(Text::input($_POST['country']))) . $GLOBALS['enquiry'];
Alternately, change to

Code: Select all

    return $GLOBALS['enquiry'] = sprintf(CUSTOMERS_LOCATION, $GLOBALS['enquiry'], Country::fetch_name(Text::input($_POST['country'])));
and change the language constant appropriately. E.g.

Code: Select all

const CUSTOMERS_LOCATION = "Customers Location: %2$s\n\n%1$s";