[google-appengine] Re: how to submit form from static index.html
On Feb 6, 7:58 pm, rakf1 kris...@gmail.com wrote: Is there a way to just send mail and not redirect the page? I'm trying to send mail using a ajax popup window, so I want to submit and write a message in a div, and dont want the page to reload/ redirect. You can write a handler that sends an email, and POSTto it the content of your div using JavaScript. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: how to submit form from static index.html
here is how i have setup the app.yaml, email.py and form.html, let me know whats wrong ??, how should i setup handler for email.py in app.yaml ?? OK, here's how you can do it. app.yaml: - handlers: - url: /send-email script: email.py - url: (.*)/ static_files: static\1/index.html upload: static/index.html - url: / static_dir: static - email.py: from google.appengine.api import mail from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class SendEmail(webapp.RequestHandler): def post(self): user_address = self.request.get('address') if mail.is_email_valid(user_address): sender_address = 'y...@example.com' subject = 'test' body = test email mail.send_mail(sender_address, user_address, subject, body) self.redirect('/form.html') application = webapp.WSGIApplication([('/send-email', SendEmail)], debug=True) def main(): run_wsgi_app(application) if __name__ == __main__: main() form.html: - form action=/send-email method=post Email: input name=address type=text/ input type=submit value=Send/ /form - I didn't test it, let me know if something doesn't work. Regarding this line in your original code: # prompt user to enter a valid address You have quite a few options, the easiest one is probably to redirect to a static page containing an error message and a link back to the email form. Other options will probably involve templates or and/or some javascript. Also note that the sender_address must be the administrator of your app or the currently signed in user: http://code.google.com/appengine/docs/mail/overview.html Hope this helps. -- www.muspy.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: how to submit form from static index.html
thanks Alexander, the setup and code worked, one more help, - how do i unescape string in python that was escaped in javascript and submitted?? I'm submitting html that is escaped from the form - escape(data) How do I unescape the self.request.get('data') in python and then mail it ? javascript: var data = document.getElementById(message).innerHTML; document.getElementById(pop).innerHTML = 'form action=/send-email method=postEmail: input name=address type=text/brinput name=data type=hidden value='+escape(data)+'brinput type=submit value=Send//form'; - email.py: from google.appengine.api import mail from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class SendEmail(webapp.RequestHandler): def post(self): user_address = self.request.get('address') if mail.is_email_valid(user_address): message = mail.EmailMessage(sender=nore...@example.com, subject=test) message.to = user_address message.body = test blah blah message.html = test blah blah + self.request.get('data') message.send() self.response.out.write('Email sent') application = webapp.WSGIApplication([('/send-email', SendEmail)], debug=True) def main(): run_wsgi_app(application) if __name__ == __main__: main() On Dec 16, 12:54 am, Alexander Kojevnikov alexan...@kojevnikov.com wrote: here is how i have setup the app.yaml,email.py and form.html, let me know whats wrong ??, how should i setup handler foremail.py in app.yaml ?? OK, here's how you can do it. app.yaml: - handlers: - url: /send-email script:email.py - url: (.*)/ static_files: static\1/index.html upload: static/index.html - url: / static_dir: static - email.py: from google.appengine.api import mail from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class SendEmail(webapp.RequestHandler): def post(self): user_address = self.request.get('address') if mail.is_email_valid(user_address): sender_address = '@example.com' subject = 'test' body = testemail mail.send_mail(sender_address, user_address, subject, body) self.redirect('/form.html') application = webapp.WSGIApplication([('/send-email', SendEmail)], debug=True) def main(): run_wsgi_app(application) if __name__ == __main__: main() form.html: - form action=/send-email method=postEmail: input name=address type=text/ input type=submit value=Send/ /form - I didn't test it, let me know if something doesn't work. Regarding this line in your original code: # prompt user to enter a valid address You have quite a few options, the easiest one is probably to redirect to a static page containing an error message and a link back to theemailform. Other options will probably involve templates or and/or some javascript. Also note that the sender_address must be the administrator of your app or the currently signed in user:http://code.google.com/appengine/docs/mail/overview.html Hope this helps. --www.muspy.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: how to submit form from static index.html
thanks Alexander, the setup and code worked, one more help, - how do i unescape string in python that was escaped in javascript and submitted?? I'm submitting html that is escaped from the form - escape(data) How do I unescape the self.request.get('data') in python and then mail it ? Python standard library has an escape() function but apparently doesn't have unescape(). You can use this code or google for a better solution: http://blog.modp.com/2008/10/html-unescape-in-python.html By the way, why do you use JavaScript for this? You can try a simple textarea instead: form action=/send-email method=post Email: input name=address type=text/br/ Message:br/ textarea name=data rows=10 cols=20test/textareabr/ input type=submit value=Send/ /form This way you don't need to unescape() the message. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: how to submit form from static index.html
I'm trying to email content that is in a div container on the webpage, so i'm submitting using a hidden input tag with value=escape (div.innerHTML) On Dec 16, 6:18 pm, Alexander Kojevnikov alexan...@kojevnikov.com wrote: thanks Alexander, the setup and code worked, one more help, - how do i unescape string in python that was escaped in javascript and submitted?? I'm submitting html that is escaped from the form - escape(data) How do I unescape the self.request.get('data') in python and then mail it ? Python standard library has an escape() function but apparently doesn't have unescape(). You can use this code or google for a better solution:http://blog.modp.com/2008/10/html-unescape-in-python.html By the way, why do you use JavaScript for this? You can try a simple textarea instead: form action=/send-email method=post Email: input name=address type=text/br/ Message:br/ textarea name=data rows=10 cols=20test/textareabr/ input type=submit value=Send/ /form This way you don't need to unescape() the message. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: how to submit form from static index.html
This is easy to do. See the mail api http://code.google.com/appengine/docs/mail/ for details. On Dec 16, 1:28 pm, rakf1 kris...@gmail.com wrote: I have a app running with static files, i have a form in the index.html which has to be emailed back to me onsubmit. Is there a way to do this? I have no experience with python, can this be done like with php? I was able to find some documentation on sendmail:http://code.google.com/appengine/docs/mail/sendingmail.html, but how do I do this from static index.html. my app.yaml: application: xxx version: 1 runtime: python api_version: 1 handlers: - url: (.*)/ static_files: static\1/index.html upload: static/index.html - url: / static_dir: static --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: how to submit form from static index.html
I'm not starting the page using template.render (), so I cannot implement the way in the tutorials, i'm using static index.html... is it supposed to work if i have the sendmail in form action, like this: ---?? form action=mail.cgi method=POST ... On Dec 15, 7:53 pm, Greg g.fawc...@gmail.com wrote: This is easy to do. See the mail apihttp://code.google.com/appengine/docs/mail/ for details. On Dec 16, 1:28 pm, rakf1 kris...@gmail.com wrote: I have a app running with static files, i have a form in the index.html which has to be emailed back to me onsubmit. Is there a way to do this? I have no experience with python, can this be done like with php? I was able to find some documentation on sendmail:http://code.google.com/appengine/docs/mail/sendingmail.html, but how do I do this from static index.html. my app.yaml: application: xxx version: 1 runtime: python api_version: 1 handlers: - url: (.*)/ static_files: static\1/index.html upload: static/index.html - url: / static_dir: static --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: how to submit form from static index.html
I'm not starting the page using template.render (), so I cannot implement the way in the tutorials, i'm using static index.html... is it supposed to work if i have the sendmail in form action, like this: ---?? form action=mail.cgi method=POST ... No, but you can write your own handler. Use the code from the tutorial as a starting point. In your index.html change the form's action for example to /send- email. Then in your send-email handler, override the post() method, send an email using the appengine mail API, and finally redirect back to the html page with: self.redirect('/your-page.html') Don't be afraid to throw in some Python code, it's really easy. Let us know if you have troubles setting this up. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---
[google-appengine] Re: how to submit form from static index.html
here is how i have setup the app.yaml, email.py and form.html, let me know whats wrong ??, how should i setup handler for email.py in app.yaml ?? app.yaml: - ... ... handlers: - url: (.*)/ static_files: static\1/index.html upload: static/index.html - url: / static_dir: static - email.py: - from google.appengine.api import mail class SendEmail(webapp.RequestHandler): def post(self): user_address = self.request.get(email_address) if not mail.is_email_valid(user_address): # prompt user to enter a valid address else: sender_address = supp...@example.com subject = test body = test email mail.send_mail(sender_address, user_address, subject, body) - form.html: - form action=/SendEmail method=POST Email: input type=email_addressinput type=submit value=Confirm /form - On Dec 15, 10:03 pm, Alexander Kojevnikov alexan...@kojevnikov.com wrote: I'm not starting the page using template.render (), so I cannot implement the way in the tutorials, i'm using static index.html... is it supposed to work if i have the sendmail in form action, like this: ---?? form action=mail.cgi method=POST ... No, but you can write your own handler. Use the code from the tutorial as a starting point. In your index.html change the form's action for example to /send- email. Then in your send-email handler, override the post() method, send an email using the appengine mail API, and finally redirect back to the html page with: self.redirect('/your-page.html') Don't be afraid to throw in some Python code, it's really easy. Let us know if you have troubles setting this up. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google App Engine group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~--~~~~--~~--~--~---