You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lenya.apache.org by Milan Jezdik <xj...@seznam.cz> on 2007/06/06 14:33:33 UTC

How to get GET parameter in .js script

Hi,
First of all what is my goal: I have simple input box (aka search site 
box) where user can put its email address. The point is to send an email 
containing its email address to some system account.

I am using simple usecase which calls .js script. You can see all 
related files bellow.

My problem is, how to get the user email (value from the input box) in 
my .js script??? I've tried something like cocoon.getRequest but no luck.

Many thanks,
Milan

ps: to whom want to use this: you have to copy mail jar file to your lib 
dir. have a look here - http://solprovider.com/lenya/flowemail


On main page:
=============
<form>
   <strong>Subscribe:</strong>:
   <input type="text" name="email" class="formfield"/>
   <input type="hidden" name="lenya.usecase" value="subscribe"/>
   <input type="hidden" name="language" value="en"/>
</form>

usecase-subscribe.xmap:
=======================
<?xml version="1.0" encoding="UTF-8"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
   <map:flow language="javascript">
     <map:script src="flow/subscribe.js"/>
   </map:flow>
   <map:pipelines>
     <map:pipeline>
       <map:match pattern="**.html">
         <map:call function="subscribe_mail"/>
       </map:match>
       <map:match pattern="subscribe-success">
         <map:redirect-to uri="/"/>
       </map:match>
     </map:pipeline>
   </map:pipelines>
</map:sitemap>

and finaly the script flow/subscribe.js:
========================================
function subscribe_mail() {
   var properties = new Packages.java.util.Properties();
   properties.setProperty("protocol", "smtp");
   properties.setProperty("type", "transport");
   properties.setProperty("class", "com.sun.mail.smtp.SMTPTransport");
   properties.setProperty("mail.smtp.host", "localhost")

   var session = new Packages.javax.mail.Session.getInstance(properties);
   var message = new Packages.com.sun.mail.smtp.SMTPMessage(session);
   var address = new Packages.javax.mail.internet.InternetAddress();


   message.setSubject("Test JavaMail");
   message.setText("Mail: " + usermail, "UTF-8");
   address.setAddress("XXXX");
   message.setFrom(address);
   address.setAddress("XXXXX");
   message.addRecipient(Packages.javax.mail.Message.RecipientType.TO, 
address);

   var urlname = new Packages.javax.mail.URLName("smtp://localhost")
   var transport = new Packages.com.sun.mail.smtp.SMTPTransport(session, 
urlname);
   transport.send(message);
   cocoon.sendPage("subscribe-success");
}


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org


Re: How to get GET parameter in .js script

Posted by Milan Jezdik <xj...@seznam.cz>.
THANK YOU !!!

Works perfectly. I had to overlook that article.

Once again, thank you!

Andreas Hartmann wrote:
> Milan Jezdik schrieb:
>> Hi,
>> First of all what is my goal: I have simple input box (aka search site
>> box) where user can put its email address. The point is to send an email
>> containing its email address to some system account.
>>
>> I am using simple usecase which calls .js script. You can see all
>> related files bellow.
>>
>> My problem is, how to get the user email (value from the input box) in
>> my .js script??? I've tried something like cocoon.getRequest but no luck.
> 
> http://cocoon.apache.org/2.1/userdocs/flow/api.html
> 
> var email = cocoon.request.getParameter("email");
> 
> HTH,
> 
> -- Andreas
> 
> 
> 
>> Many thanks,
>> Milan
>>
>> ps: to whom want to use this: you have to copy mail jar file to your lib
>> dir. have a look here - http://solprovider.com/lenya/flowemail
>>
>>
>> On main page:
>> =============
>> <form>
>>   <strong>Subscribe:</strong>:
>>   <input type="text" name="email" class="formfield"/>
>>   <input type="hidden" name="lenya.usecase" value="subscribe"/>
>>   <input type="hidden" name="language" value="en"/>
>> </form>
>>
>> usecase-subscribe.xmap:
>> =======================
>> <?xml version="1.0" encoding="UTF-8"?>
>> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
>>   <map:flow language="javascript">
>>     <map:script src="flow/subscribe.js"/>
>>   </map:flow>
>>   <map:pipelines>
>>     <map:pipeline>
>>       <map:match pattern="**.html">
>>         <map:call function="subscribe_mail"/>
>>       </map:match>
>>       <map:match pattern="subscribe-success">
>>         <map:redirect-to uri="/"/>
>>       </map:match>
>>     </map:pipeline>
>>   </map:pipelines>
>> </map:sitemap>
>>
>> and finaly the script flow/subscribe.js:
>> ========================================
>> function subscribe_mail() {
>>   var properties = new Packages.java.util.Properties();
>>   properties.setProperty("protocol", "smtp");
>>   properties.setProperty("type", "transport");
>>   properties.setProperty("class", "com.sun.mail.smtp.SMTPTransport");
>>   properties.setProperty("mail.smtp.host", "localhost")
>>
>>   var session = new Packages.javax.mail.Session.getInstance(properties);
>>   var message = new Packages.com.sun.mail.smtp.SMTPMessage(session);
>>   var address = new Packages.javax.mail.internet.InternetAddress();
>>
>>
>>   message.setSubject("Test JavaMail");
>>   message.setText("Mail: " + usermail, "UTF-8");
>>   address.setAddress("XXXX");
>>   message.setFrom(address);
>>   address.setAddress("XXXXX");
>>   message.addRecipient(Packages.javax.mail.Message.RecipientType.TO,
>> address);
>>
>>   var urlname = new Packages.javax.mail.URLName("smtp://localhost")
>>   var transport = new Packages.com.sun.mail.smtp.SMTPTransport(session,
>> urlname);
>>   transport.send(message);
>>   cocoon.sendPage("subscribe-success");
>> }
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org


Re: How to get GET parameter in .js script

Posted by Andreas Hartmann <an...@apache.org>.
Milan Jezdik schrieb:
> Hi,
> First of all what is my goal: I have simple input box (aka search site
> box) where user can put its email address. The point is to send an email
> containing its email address to some system account.
> 
> I am using simple usecase which calls .js script. You can see all
> related files bellow.
> 
> My problem is, how to get the user email (value from the input box) in
> my .js script??? I've tried something like cocoon.getRequest but no luck.

http://cocoon.apache.org/2.1/userdocs/flow/api.html

var email = cocoon.request.getParameter("email");

HTH,

-- Andreas



> 
> Many thanks,
> Milan
> 
> ps: to whom want to use this: you have to copy mail jar file to your lib
> dir. have a look here - http://solprovider.com/lenya/flowemail
> 
> 
> On main page:
> =============
> <form>
>   <strong>Subscribe:</strong>:
>   <input type="text" name="email" class="formfield"/>
>   <input type="hidden" name="lenya.usecase" value="subscribe"/>
>   <input type="hidden" name="language" value="en"/>
> </form>
> 
> usecase-subscribe.xmap:
> =======================
> <?xml version="1.0" encoding="UTF-8"?>
> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
>   <map:flow language="javascript">
>     <map:script src="flow/subscribe.js"/>
>   </map:flow>
>   <map:pipelines>
>     <map:pipeline>
>       <map:match pattern="**.html">
>         <map:call function="subscribe_mail"/>
>       </map:match>
>       <map:match pattern="subscribe-success">
>         <map:redirect-to uri="/"/>
>       </map:match>
>     </map:pipeline>
>   </map:pipelines>
> </map:sitemap>
> 
> and finaly the script flow/subscribe.js:
> ========================================
> function subscribe_mail() {
>   var properties = new Packages.java.util.Properties();
>   properties.setProperty("protocol", "smtp");
>   properties.setProperty("type", "transport");
>   properties.setProperty("class", "com.sun.mail.smtp.SMTPTransport");
>   properties.setProperty("mail.smtp.host", "localhost")
> 
>   var session = new Packages.javax.mail.Session.getInstance(properties);
>   var message = new Packages.com.sun.mail.smtp.SMTPMessage(session);
>   var address = new Packages.javax.mail.internet.InternetAddress();
> 
> 
>   message.setSubject("Test JavaMail");
>   message.setText("Mail: " + usermail, "UTF-8");
>   address.setAddress("XXXX");
>   message.setFrom(address);
>   address.setAddress("XXXXX");
>   message.addRecipient(Packages.javax.mail.Message.RecipientType.TO,
> address);
> 
>   var urlname = new Packages.javax.mail.URLName("smtp://localhost")
>   var transport = new Packages.com.sun.mail.smtp.SMTPTransport(session,
> urlname);
>   transport.send(message);
>   cocoon.sendPage("subscribe-success");
> }


-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org