Adding fields to contact_us.php
-
LeeFoster
- Contributor
- Posts: 263
- Joined: Sun Feb 28, 2021 9:41 pm
- Phoenix Version: v1.0.8.20
- Has thanked: 1 time
- Been thanked: 5 times
Adding fields to contact_us.php
Hi all,
So I know I can add fields to the contact us for and have used the addMaths hook file as a basis. What I don't know is how to then include these in the email that is sent.
Can anyone point me in the right direction?
So I know I can add fields to the contact us for and have used the addMaths hook file as a basis. What I don't know is how to then include these in the email that is sent.
Can anyone point me in the right direction?
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Adding fields to contact_us.php
If you only want to edit one of enquiry, name, or email_address, you could do so with something like Note that some things that you might try to add to the email address might break it. That's also possible with name, although less likely. Adding to the enquiry is much safer.
Code: Select all
class hook_shop_contact_us_add_to_email {
public function listen_injectFormVerify() {
$GLOBALS['enquiry'] .= 'add to enquiry';
$GLOBALS['name'] .= 'add to name'
$GLOBALS['email_address'] .= 'add to email_address';
}
}-
LeeFoster
- Contributor
- Posts: 263
- Joined: Sun Feb 28, 2021 9:41 pm
- Phoenix Version: v1.0.8.20
- Has thanked: 1 time
- Been thanked: 5 times
Re: Adding fields to contact_us.php
Would I be right in assuming that I replaceecartz wrote: ↑Thu Nov 18, 2021 3:25 am If you only want to edit one of enquiry, name, or email_address, you could do so with something likeNote that some things that you might try to add to the email address might break it. That's also possible with name, although less likely. Adding to the enquiry is much safer.Code: Select all
class hook_shop_contact_us_add_to_email { public function listen_injectFormVerify() { $GLOBALS['enquiry'] .= 'add to enquiry'; $GLOBALS['name'] .= 'add to name' $GLOBALS['email_address'] .= 'add to email_address'; } }
with my $_POST data?'add to enquiry'
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Adding fields to contact_us.php
If that's what you want to add there. You could add any string that way. If it happens to come from post input, that's fine. Note that you probably want to do some kind of sanitization, e.g. Text::input.
Code: Select all
$GLOBALS['enquiry'] .= Text::input($_POST['new_field']);-
LeeFoster
- Contributor
- Posts: 263
- Joined: Sun Feb 28, 2021 9:41 pm
- Phoenix Version: v1.0.8.20
- Has thanked: 1 time
- Been thanked: 5 times
Re: Adding fields to contact_us.php
Thanks, I managed to get it to just add a text string to the email so just need to work out adding my form data now instead.ecartz wrote: ↑Thu Nov 18, 2021 8:04 am If that's what you want to add there. You could add any string that way. If it happens to come from post input, that's fine. Note that you probably want to do some kind of sanitization, e.g. Text::input.And you may want to use sprintf or something to give it more context. But if you just want to append, this should do it.Code: Select all
$GLOBALS['enquiry'] .= Text::input($_POST['new_field']);
-
LeeFoster
- Contributor
- Posts: 263
- Joined: Sun Feb 28, 2021 9:41 pm
- Phoenix Version: v1.0.8.20
- Has thanked: 1 time
- Been thanked: 5 times
Re: Adding fields to contact_us.php
Right I managed to get this mostly working for me, just need to work out how to attach images to the email now as well.
@ecartz any miracle suggestion?
@ecartz any miracle suggestion?
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Adding fields to contact_us.php
The easy way is to turn on HTML emails and just add an
If you need to embed the image, you have to override the existing mail call. When you call mail, this happens:
So you need to do something like And then hope it all works, as core doesn't add images, so this isn't tested.
Code: Select all
<img src="https://example.com/path_to_image.png" />Code: Select all
public static function mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
if (SEND_EMAILS !== 'true') {
return false;
}
// Instantiate a new mail object
$message = new email();
$message->add_message($email_text);
$message->build_message();
return $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);
}Code: Select all
class hook_shop_contact_us_zz_add_image {
public function listen_injectFormVerify() {
if (Form::is_valid()) {
Form::block_processing();
$message = new email();
$message->add_message($email_text);
$message->find_html_images(DIR_FS_CATALOG . 'images/');
$message->build_message();
return $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);
}
}
}-
LeeFoster
- Contributor
- Posts: 263
- Joined: Sun Feb 28, 2021 9:41 pm
- Phoenix Version: v1.0.8.20
- Has thanked: 1 time
- Been thanked: 5 times
Re: Adding fields to contact_us.php
OK so here's where I am with this.
I have temporarily modified the tep_mail function in includes\functions\general.php and added in
Uploads being a temp folder for testing and scribe.jpg being an image file contained there.
However this just sends a .dat file with the content being uploads/scribe.jpg
add_html_image & add_attachment do the same.
What am I missing?
* Yes I know this shouldn't be done in core and once it's working I'll move it out.
I have temporarily modified the tep_mail function in includes\functions\general.php and added in
$message->find_html_images('uploads/scribe.jpg')
Uploads being a temp folder for testing and scribe.jpg being an image file contained there.
However this just sends a .dat file with the content being uploads/scribe.jpg
add_html_image & add_attachment do the same.
What am I missing?
* Yes I know this shouldn't be done in core and once it's working I'll move it out.
-
LeeFoster
- Contributor
- Posts: 263
- Joined: Sun Feb 28, 2021 9:41 pm
- Phoenix Version: v1.0.8.20
- Has thanked: 1 time
- Been thanked: 5 times
Re: Adding fields to contact_us.php
Managed to get it to add the image into the HTML using this. Would still prefer it to add as an attachment for ease of saving but this will suffice for now.ecartz wrote: ↑Thu Nov 18, 2021 11:28 pm The easy way is to turn on HTML emails and just add anCode: Select all
<img src="https://example.com/path_to_image.png" />