Hi folks,
My ultimate question is how to use the email module to embed the email contact form, but I am also curious as to why the form isn't being rendered in my node when I use this code:
<?php print drupal_get_form('email_mail_page_form'); ?>
I am trying to get the email contact form generated by this module into the node itself. I looked through the module and I narrowed it down to two functions that coudl help me get this accomplished:
function email_mail_page_form()
and/or
function email_mail_page($nid=null, $fieldname=null)
I've used:
<?php print drupal_get_form('email_mail_page_form'); ?>
This does not generate anything on the page. :( I expected this to at least render the form created by this code in the email.module file:
function email_mail_page_form() {
global $user;
if ($user->uid) {
$edit['name'] = $user->name;
$edit['mail'] = $user->mail;
}
$form['#token'] = $user->name . $user->mail;
$form['name'] = array('#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 255,
'#default_value' => $edit['name'],
'#required' => TRUE,
);
$form['mail'] = array('#type' => 'textfield',
'#title' => t('Your e-mail address'),
'#maxlength' => 255,
'#default_value' => $edit['mail'],
'#required' => TRUE,
);
$form['subject'] = array('#type' => 'textfield',
'#title' => t('Subject'),
'#maxlength' => 255,
'#required' => TRUE,
);
$form['message'] = array('#type' => 'textarea',
'#title' => t('Message'),
'#required' => TRUE,
);
$form['submit'] = array('#type' => 'submit',
'#value' => t('Send e-mail'),
);
return $form;
}
I then tried:
<?php print drupal_get_form('email_mail_page', $node->nid, $node->field_business_email); ?>
This returns a Drupal 404 error I suspect due to this code in the email.module file:
if (empty($nid) || empty($fieldname)) {
drupal_not_found();
return;
}
$node = node_load(intval($nid));
if (!$node) {
drupal_not_found();
return;
}
// Validate field name
$types = content_types($node->type);
if (!isset($types['fields'][$fieldname]) ||
$types['fields'][$fieldname]['type'] != 'email' ||
$types['fields'][$fieldname]['widget']['link_type'] != 'form') {
drupal_not_found();
return;
}
$field = $node->$fieldname;
if (empty($field) || empty($field[0]['email'])) {
drupal_not_found();
return;
}
My ultimate question is how to use the email module to embed the email contact form, but I am also curious as to why the form isn't being rendered in my node when I use this code:
<?php print drupal_get_form('email_mail_page_form'); ?>
Thanks kindly for reading.
Comment | File | Size | Author |
---|---|---|---|
#23 | email.patch | 991 bytes | chx |
Comments
Comment #1
worpx CreditAttribution: worpx commentedHi there,
When I invoke
print drupal_get_form('email_mail_page_form');
it works fine for me; it display the default mail form for the site; but in order to get it from your nodeprint drupal_get_form('email_mail_page', $node->nid, $node->field_business_email);
should work (provided that field_business_email is a CONTEMPLATE).Cheers
Comment #2
auctionduke CreditAttribution: auctionduke commentedWhere exactly do you embed this code (which file?):
Thanks
Comment #3
TuWebO CreditAttribution: TuWebO commentedHi all,
Very interesting question!!
I´m new in drupal and I would like also to know how to embed the email form, and some extra thing.. how to fill up the subject field with the title of the node where it is embed? (sorry about my english).
I´m using drupal 6.2 but I think it should be pretty similar to 5.x.
Thanks in advance.
Comment #4
tanyi CreditAttribution: tanyi commentedWere you able to find the answer to your question i.e. how to fill up the subject field with the title of the node? I am trying to do the same thing but unable.
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commented+1
Comment #6
tanyi CreditAttribution: tanyi commentedAny help on the above request please?
Comment #7
GiorgosKTry this approach http://drupal.org/node/335020
its for drupal 6 but should not take much to change for drupal 5
Comment #8
milos.kroulik CreditAttribution: milos.kroulik commented[#1] doesn't work for me. I always got "Page not found". I tried through block and contemplate. I don't think there is any difference.
Comment #9
mjoyce71 CreditAttribution: mjoyce71 commentedI couldn't figure it out and just ended up using a web form to email service:
http://www.formmailhosting.com
Good part is they send you the email of the form results (of course) but they also store the submissions in MS Excel which is a nice feature too.
- Mark
Comment #10
milos.kroulik CreditAttribution: milos.kroulik commentedI sort of solved it. But through such ugly hack (it uses Iframe and hacks Email Field module directly), that I probably shouldn't recommend it to anyone. So I will describe it only briefly. Reply if you're interested.
Of course I am still interested in better solutions.
Comment #11
GiorgosKThe majority of code on this support request still applies to Drupal 5.x
thus changing the version to 5.x otherwise it would be confusing to the people that see this issue in the future
Comment #12
NaX CreditAttribution: NaX commentedThis one threw me for a bit, but this is how I solved the problem without any hacking, please note this is for D6.
Because
email_mail_page()
is not a form function a but normal menu call back. In this function adrupal_get_form
gets called onemail_mail_page_form()
But
email_mail_page()
does a bunch of stuff including checking for flood thresholds.So I could call
drupal_get_form
onemail_mail_page_form
directly but instead I used the code fromemail_mail_page()
and modified it to keep the extra checking.Here is the steps I took.
I created content type called
contact
and added an email field calledfield_contact_email
.I then created a template file for my new content type called
node-contact.tpl.php
and saved it in my theme.I copied the contents of
node.tpl.php
into mynode-contact.tpl.php
.At the end of my new template file I added the following code.
Hope this helps other people.
Comment #13
Summit CreditAttribution: Summit commentedHi,
On which function you added this php-code in template.php please? I have the acquia_slate theme and am not seeing were to add this.
Looking for same sort solution on D6. Can you also add fields to the contactform?
Thanks for your reply in advance!
Greetings, Martijn
Comment #14
NaX CreditAttribution: NaX commentedSorry I was not clear, you add it to your new tpl.php file. Just remember that I called everything
contact
and you will need to change that in the code and file names.EG:
Comment #15
Summit CreditAttribution: Summit commentedHi, will look into it more!
Do you also know how to add a field to the form, say the url of the contact?
greetings,
Martijn
Comment #16
pauldawg CreditAttribution: pauldawg commentedInteresting. I've been looking at doing this as well, and I will probably try out the approach in #12. In looking at the code, although it's not a "hack" per se, it does look like it is copying some basic code from the email contact form module, is that true? If so, might there be some issues maintaining this to stay in sync with updates to that module?
Comment #17
mcurry CreditAttribution: mcurry commentedsubscribing
Comment #18
Einkahumor CreditAttribution: Einkahumor commented#12 works for me. The only thing I had to do was change
$field_name = 'field_contact_email';
to$field_name = 'field_my_field_name';
and hide the standard Email contact form link via css. Thanks a million.Comment #19
alisonThank you, NaX, this was perfect!! You're a lifesaver!
Comment #20
dvasquez CreditAttribution: dvasquez commentedHello...
I'm looking for use this in Panels. But it not work, how can i do, for display the contactform in panels or in a block?
Comment #21
Einkahumor CreditAttribution: Einkahumor commentedI've not tried it but you could try CCK Blocks to show the content of the email field (in this case, the form) in a block. I've no idea if it actually works though but please tell if you try it.
Comment #22
chx CreditAttribution: chx commentedemail_embedded.info:
Be careful with the module, it requires the patch in the next comment as I needed to move flood control into the validate handler.
email_embedded.module:
Note that the page callback can not be reused as it calls drupal_not_found and checks whether the formatter is set to contact so I have copypasted the email_mail_page callback and thrown out the irrelevant checks and replaced the drupal_not_found with an empty return.
Comment #23
chx CreditAttribution: chx commentedAnd here is a small patch which adds the flood control into validate as I always want to show the form or the 'you cant send' will get cached. Not fun.
Comment #24
jason.fisher CreditAttribution: jason.fisher commentedI was using email_mail_page to embed the form, because that is where the flood control is, but I do not display the field in the node teaser or full view, so I get a 404 error.
Here is the troublesome bit:
So my options are to switch to:
and not worry about flood control, or alter the email_mail_page function so it ignores the need for the email field to appear on either the teaser or full view of $node.
Ideally, flood control would be moved into the form itself, or into a validator for the form? (note--I do see the patch from chx, thanks)
The former method, although incorrect in terms of best practices, is a much simpler embed currently, because it accepts a nid and the field as a string -- no need to node_load in the embed or do any of the checking already included in the email_mail_page function.
BTW -- my usage is for embedding into a panel.
Comment #25
johnvDoes the following patch help? #1264210: Add actual contact form display formatter
Comment #26
jason.fisher CreditAttribution: jason.fisher commentedThat is great, I will definitely use/follow that for my D7 projects.
It seems that a simple e-mail contact form on a node with some Rules is a nice simple (but powerful) workflow initiator now.