0

I've implemented hook_menu and in page callback there is a function in my module which retrieves some records randomly and theme them with theme_table. Now I want a button on the page for sending this page exactly as it is to a predefined email address without refreshing the page because of randomly selected records.

I placed a button through simple HTML code but don't know how I can implement it's onClick function. Or is there any better way to do that? Thanks

0

It is simple javascript... The returned value can easilly be sent through ajax (there are good tutorials on sending mails with ajax).

<button onClick="alert(document.getElementsByTagName('body').innerHTML())" value="serialize">

You might run into trouble though, at first email clients can have trouble accessing images from remote locations (eg. from your own url). So you might have to attach them to the mail.

Also most email clients are very picky when it comes to css. They refuse to load a remote sytlesheet. You will have to hardcode all css classes in the respective elements, the old fashioned way... By using the object style attribute.

<body style="background: red; font-size: 9pt;">

So as you see it is harder then just sending the HTML to an email receipient. In fact you might want to have a look at HTML2Canvas (or other alternatives) to make a 'screenshot' of a webpage and just send one image.

  • 2
    Note, in Drupal 7, a link with a CSS class 'use-ajax' ( perhaps themed like a button ) will submit via Ajax automatically. – David Thomas Jan 7 '13 at 0:17
  • @David, Can you please give me a simple example for how to do that via AJAX? – developer Jan 12 '13 at 8:10
  • Add a class 'use-ajax' to the link. i.e <a href="/my/callback" class="use-ajax">My callback</a> – David Thomas Jan 12 '13 at 8:43
  • OK, but I just found a module mimemail drupal.org/project/mimemail, which I think will solve my problem in an easy way. Please suggest? – developer Jan 15 '13 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.