Basically I'm wondering if there is a way to send POST data without actually using a form. I ask this because what I want to do is take data from a text area ans seperate it then send the values to a page that currently takes data from seperate form fields.
I only want to do this because I already have the page that gets the results for the request it just currently take data differently. I'm new to this so if I could just use the existing page and feed data into it rather than make a new one it would be great.
Bear Bibeault wrote:I'm not exactly sure what you are trying to accomplish by your description, but be aware that hacking around is likely to create more confusion that just doing things in a straight-forward manner.
That said, the only other way to generate a POST from a browser other than a form is via Ajax.
I understand. What it basically is is that I have a existing ability on my site to do this, but want a user to be able to submit the information in a different way.
Currenty a user can enter a item and a quantity(only 10 of these at the moment each with their own text box), then these get sent to a page that displays the result. What I want to do is let the user enter the information in a text area via comma seperated values (so they can use as many as they want at once) but still come to the same results page. So for that to work I need to parse the data from the text area and then send it with the same POST values as the individual text boxes would have had.
New to this so that seems like the simplest way but perhaps not so much.
It's the simplest way only if you think the users are going to type correctly-formatted data 100% of the time. Which, of course, they aren't. So now you have to write some code to parse the CSV data and deal with the cases where they didn't put in enough fields into a row. Maybe they hit the period instead of the comma, or maybe they accidentally put in two commas together, or put everything into a single line because they didn't understand (or read) the instructions. And so on. Not the simplest way at all.
I think that you may be digging yourself a very deep, very dark, and very dangerous hole.
What is the motivation for this in the first place? Do you have a requirement to allow CSV data entry? I can't imagine any user wanting to enter data in that way -- seems rather silly. But what's the reason for the whole task?
Bear Bibeault wrote:Seems to me that a better solution would be to refactor the original servlet to use a lower-level API that both forms of input could share. How are you planning on validating the CSV?
Well I can't validate the first value in each line other than it being there. The second value had to be a number snd I was hoping I could make sure there were no more than 2 values before the \n if that is possible.
Edit: was going to split the values into and array first and then check every other value for the needed validation.
Vincent Micchia wrote:Well it's a precursor to allowing excel data to be imported. But this is faster and works for the time being. Users have been asking for something like this so yeah here I am.
You might consider skipping over the quick-and-dirty method, then, and going straight to working with Excel uploads. I'm doing that right now, as it happens; extracting data from Excel and validating it in a servlet isn't too bad, but you have to have something of a framework in place if you're going to be dealing with multiple formats. One thing you could try (which I haven't done yet) is to provide empty Excel spreadsheets with macros which control what can be entered where. You still have to do the same validation on the server, but your users will thank you if they can be sure they can just upload their spreadsheet and be sure it contains valid data.
Aslo as a side note. The code that this form data gets submitted to does all the validation and error checking already. For me it's really just getting the data in the correct format (form field post data.)
They weren't very bright, but they were very, very big. Ad contrast:
ScroogeXHTML - small and flexible RTF to HTML converter library