Submit information to url, but also open PDF

Go To StackoverFlow.com

1

EDIT: This privately published page is what I need to work with. Password: stackOF

My client desires is to have her Wordpress blog show a MailChimp form on her home page as a gateway to a .pdf. I need the following behavior to occur when the user clicks "Submit":

  1. execute the included MailChimp's javascript file; this ensures the form was properly filled, and then performs the sign-up to the newsletter list (don't need help with this part)
  2. then show the user an informational PDF for download or viewing EDIT: The logical order was flipped from when I originally posted this. The script should execute, and only if the script gets executed properly should the PDF show to the user

Note:

  • My experience level with HTML and PHP is 3/4, and with JS I am 2/4 EDIT: (seems more like 1/4 at this point lol). If my research is correct, PHP (server-side language) would be used to do that which the client wants.
  • Additional validation is not necessary beyond what MailChimp's script provides (it ensures that user has submitted a completed form) in this case (the client says it's ok if the e-mail isn't valid at all).
  • The .pdf URL and content is static, and simply needs to be shown, not generated.

----RESEARCH---- I know that the Mailchimp form uses the following line to actually submit the information, but I want to do the action mentioned below, as well as open the aforementioned .pdf:

<form action="http://*BLAH*.us2.list-manage.com/subscribe/post?u=*BLAHBLAH*&amp;id=*BLAHBLAHBLAH*" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank">

I am reading on other sites that I can conceivably point "action" to a .php file, but if there is a way to do this with javascript - since its using the .js file that I created for that already anyways, then I would be most happy. Barring that, I'll take what I can get..

2012-04-05 02:43
by Mad Ducky Digital Branding
Maybe this is a stupid question, but have you tried to use PHP's PDFlib? http://www.devshed.com/c/a/PHP/PDF-Generation-With-PHP - theJollySin 2012-04-05 02:46
You're making a POST request to something with GET variables. Are you aware of this - Incognito 2012-04-05 02:50
@theJollySin Thanks for your response; however I already said I do not need help with PDF generation - unless the reason for that post was something els - Mad Ducky Digital Branding 2012-04-05 06:23
@Incognito I edited the original post to include the page as it looks now - Mad Ducky Digital Branding 2012-04-05 19:32
... that doesn't answer my concern here at all. You're using GET query string parameters for a URL being sent to a POST request - Incognito 2012-04-06 01:22
@incognito I guess that's because I could not tell if you were understanding that is not the part with which I need help. The MailChimp script is handling the queries, validation, variable passing, etc and is doing a fine job at it. If I missed your point I might need more detail (maybe an example of how a correct usage should appear). Thanks for your respons - Mad Ducky Digital Branding 2012-04-08 00:16


1

You can try the following:

add an onsubmit handler on the mailchimp form like below:

<form onsubmit="runMyStuff(this)" action="http://*BLAH*.us2.list-manage.com/subscribe/post?u=*BLAHBLAH*&amp;id=*BLAHBLAHBLAH*" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank">

Your javascript function:

function runMyStuff( o ) {
    // open the pdf file in a separate window
    window.open( PATH_TO_YOUR_PDF_URL );

   // now, submit the form
   o.submit();
}

Hope this helps.

2012-04-05 08:10
by web-nomad
While I do not need validation of the user's entry of a valid e-mail address, I do want the user to have to fill out the form at least. Without the "onsubmit", the MailChimp js kicks errors out on the form if required fields are left blank. With the "onsubmit" line, clicking submit when the form is empty opens the pdf, and doesn't show the errors anymore.

Methinks I have more to learn about JS than I initially thought - Mad Ducky Digital Branding 2012-04-05 17:06

I added a preview of what the page looks like with your suggestion. Password: stackOF

Where do I go from here - Mad Ducky Digital Branding 2012-04-05 18:46

do you need to open the pdf in an iframe...just asking because if not you can just open it in a new tab/window, and let the form process as usual - web-nomad 2012-04-05 18:51
sorry, just saw your edited requirements...if you want to show the pdf after you submit the form and do all the related processing, then it will have to be on the back end, when the form posts to http://careerchoiceswithlaura.us2.list-manage.com/subscribe/post?u=31b9cd9a27e00ab826a9049ff&id=15cd56bcda, validate and then show the pdf to the user if everything is ok - web-nomad 2012-04-05 18:55
Yea ill take a crack at finding the correct line to do it later tonight. Thanks for clearing up whether I should be in the js or not - Mad Ducky Digital Branding 2012-04-08 00:17


1

You might possibly create a page that includes your script and have an iframe that points to the URL of the PDF.

2012-04-05 02:57
by Steve H.
That sounds like a good solution. The MailChimp JS creates a new window already, so in this case I would just edit that JS to create the iframe then right? (similar to what is shown here? - Mad Ducky Digital Branding 2012-04-05 17:34
I'm not familiar with MailChimp, but it sounds reasonable.. - Steve H. 2012-04-06 21:58
Ads