• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to connect and send data to FormMail?

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am writing an application that has a JDialog which allows the user to send me their requests for new features.

I have created the JDialog and the required fields etc but I do not understand how I can connect to a copy of formmail and send it the data for processing.

I understand the formmail side of things. Can anyone help?

I have supplied the 'Send' JButton ActionListener code as this is where I intend implementing this functionality. I suspect that this connection > data send > disconnection event maybe needs to run within its own thread but I am unsure if this is wise?



Not strictly on topic but... you will notice a chain of getParent() calls. This works but can't be right. How do I find the root parent?

Thank you for reading this.
[ January 17, 2006: Message edited by: D R Wilkinson ]
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I googled for "formmail", it appears there are several products of that name, but they all convert HTML forms into e-mail in some way. Or maybe those are all versions of the same thing, I couldn't really tell.

Anyway, if it's a URL where you post a form to, then you create a URL object and connect to it. Here's a tutorial about how to do that:

http://java.sun.com/docs/books/tutorial/networking/
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for your other question, to get the Container of a Component, use javax.swing.SwingUtilities.getRoot() or javax.swing.SwingUtilities.getWindowAncestor().
 
D R Wilkinson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both for your help.

I will post the thread or not in the Thread forum.
 
D R Wilkinson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again - thanks for your help.

I have read the suggested tutorial and I have set up a free formmail account at FormMail.

I have written the following code and I get an 'ok' response but no email with the form data. I have posted a request for support at FormMail but I thought someone here may know where I am going wrong.



Note : I have changed some of the FormMail account specific information and email addresses to bogus values to protect the account and my email addresses. I know the real values are correct. I suspect the fault lies within my code.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a quick look through their (tiny) FAQ. It doesn't answer your question specifically but it does have an example where it mentions that you should connect to their service using the POST method. You don't seem to be doing that. Check out the setRequestMethod() method of HttpURLConnection.
 
D R Wilkinson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I received this from Matt at FormMail


Hi Darren,

We're not too familiar with Java here, but there is no reason that if you can
make a web request and submit a form, that it shouldn't work for you. Can
you retrieve the response from formmail.com and see what error it is giving
you? Are you posting to the correct URL and submitting the necessary hidden
fields?

Matt Wright
FormMail.com



I have used the following to try to get a response from the server and 'ok' and 'null' are returned.



I would like to be able to explain precisely what the out.println() statements are sending to the FormMail server but I am not sure.

I think they are sending Strings one after another...

"type=hidden"
"name=_pid"
"value=74639"

... and so on.

Maybe this is the problem? How can I explain to Matt ( not a java progger ) what is being sent to his server by my code so that he can tell me if I am sending the correct information in the correct way?

Thanks for your help so far.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a lot to understand and correct in your code. First, it may be instructive for you to read the InputStream from the HttpURLConnection after you send your data. HTTP is a request-response protocol, so reading the response is fulfilling part of the contract, not to mention you may get useful information, like error messages, from the response.
Second, you are sending a lot of unnecessary information. The format of an input field on an HTML page (i.e. <input type=hidden name="subject" value="Your Subject"> ) contains a lot of information about how to display (or not to display) fields to the user. This information does not get passed back in the POST request. Only a series of name-value pairs get passed back (i.e. subject=Your Subject). The name-value pairs are seperated by '&'. Have a look at this example from the Java Almanac.
Third, note in the above example that the value part of the name-value pairs can contain characters which are recognized as HTTP control characters (i.e. space, '=' and so on), so they need to be encoded using URLEncoder.
Those changes should get you a little closer to your goal.
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic