Sending long text from web form to server - ruby-on-rails

I try to move my text analyzer from console to web form.
I have simple form like this:
<form action="/">
<textarea name="str"></textarea>
<input type="submit">
</form>
Generally I could have very long texts for analysis inside of textarea. When I submit the form I get the following from thin:
Invalid request: Header longer than allowed
So the question is what is the proper approach to send long texts to server? Uploading files or filling links to url are not the option unfortunately.

By default the method of a form is GET, which has a limit on the number of characters allowed. (The limit depends on server and client, see for instance this answer, which specifies that usually it is 8KB).
You should use instead a method POST, which has much larger limit, around 2GB.
<form action="/" method="POST">
<textarea name="str"></textarea>
<input type="submit">
</form>

Related

Posting SVG string to Controller works locally but not on server

I have a form that I'm posting that contains 2 numeric values and a long string containing an SVG (generated using Fabricjs). The controller uploads the SVG and outputs a PDF containing it. The reason I'm using a standard form post instead of Ajax POST is because I understand that ajax cannot return a file download.
I have maxJsonLength, aspnet:MaxJsonDeserializerMembers, and maxRequestLength all set to values much higher than what's involved here (10k of text), and I don't think the json-related ones come into play here anyway since it's a standard form post.
This works perfectly when I run it locally in Visual Studio. Once it's published to the server, it fails. I attached to the process with remote debug, and it's not even hitting the controller. I have a similar controller action that also accepts the same SVG string, and that's not working either.
In the network console, the action returns a 200. When I look at the headers, I can't see any difference between what's posting to the server vs. what I see locally. Elmah is not capturing any error, so I can't even figure out where to go at this point to find out what's wrong.
Here's the form. I added the enctype at the suggestion of another SO post, but that doesn't make a difference.
<form action="/Product/ExportSVG" enctype="application/x-www-form-urlencoded; charset=UTF-8" id="svgForm" method="post">
<input type="hidden" id="svgProjNo" name="svgProjNo" value="1111">
<input type="hidden" id="svgLineID" name="svgLineID" value="">
<input type="hidden" id="svgData" name="svgData" value="">
</form>
The script that posts the form:
var svgtext = canvas.toSVG(null, reviver);
$("#svgLineID").val($("#LineItem_ParentID").val());
$("#svgData").val(svgtext);
$('#svgForm').trigger('submit');
The controller:
[HttpPost]
public ActionResult ExportSVG(decimal svgProjNo, decimal svgLineID, string svgData)
{
...
}
You may need to encode SVG data in base 64 format.

How rewrite URL?

I'm making a single web app.
I have a form with a POST method and an action value equal to "/login".
<form action="/login" method="POST">
<label for="mail">Email</label><input name="log" id="mail" type="text">
<label for="pass">Pass</label><input name="pass" id="pass" type="text">
<input type="submit">
When the submit button is press, server get the form, then return to the index page.
But, in the address bar, I have "local:5050/login" and would have "local:5050".
Can I remove the "login" mention ?
Since you are making a SPA, you will not want to have the POST method of the form actually complete. Generally this is done in dart by attaching a listener on the form element, within that listener you would then do a couple of things:
1) Cancel the default action (Also see: How do I prevent an on.submit event from changing/reloading the page?)
2) Get the values you're interested in from the form (or potentially take the entire form itself)
3) Send the values via an AJAX request to the server and listen for the response from the server to verify it was valid etc.
See the Dart tutorials on forms for more information on accomplishing the other steps.

Rails will_paginate custom renderer manual page number

Hy
What i want to do is to create a custom renderer for will_paginate which renders first, previous, next and last page and a input field where the user can type in the page number manually. I already have the links for first, last etc. but i stuck at the input field. I could create a form in the view but the input field has to be rendered between the previous and next links.
Does anyone know how to do this?
Thanks for your help
You can do this as a separate form (make sure it is a GET). All you
need is the one input element named page. Something as simple as this
should work (not all browsers may like the #). I dropped it into a
site I'm playing with now and it worked. Put it anywhere on your page.
You might have to make something more complicated if you need to
incorporate search terms.
<form action="#" method="get">
Go to page: <input type="text" name="page" value="" size="2"
maxlength="4" />
<input type="submit" name="btnSubmit" />
</form>

Clarifying POST-ing to a site

Say I were to post to a site using www.mysite.com?user=myuser does that simulate the submit button that is associated with that form? If so, what happens if there are a number of submit buttons in the form?
Also, if that button's html is like so <input name="button" class="button" type="button" value="Save" onclick="javascript: submit()" disabled> with the "disabled" attribute, does that mean I can't POST www.mysite.com?user=myuser/won't work?
<form name="Form" method="post" action="/thisAction.do">
<input type="text" name="inquiryNo" maxlength="11" value="" onkeyup="javascript: checkNo()">
<input name="buttonInquire" class="button" value="Inquire" onclick="javascript: submitInquire()" type="button">
<!--Then comes a number of other inputs-->
<input.../>
<input.../>
<input.../>
<input name="modify" class="button" type="button" value="Save"
onclick="javascript: submitModify()" disabled>
</form>
This is some sample code as it's work stuff which I am not allowed to share. So when I use the inquire action a new account successfully loads up and the details are presented on the page. The modify action is meant to 'modify' those details but it just returns the same details displayed on the page. I get no sort of feedback from anything.
You can POST to a URL with a query string (the stuff after the ?), and since you say you're using urllib2 with a data argument, that's what happens. The server can then read both the POST data and the query string and do whatever it wants, though most of the time they're merged together or the query string is ignored entirely.
disabled only stops you from clicking the button in the browser (and even then, you can just un-disable it with a tool like Firebug). You can POST whatever you want to any URL you want; HTML can't stop you, though the server can still give you an error if it wants.
I think your problem is that "inquire" is the default action, and something's wrong with your POST. So no matter what you send, the server isn't recognizing it and is falling back to "inquire".
It looks like the form is intended to send modify=Save. Can you post the Python code you're actually running?
No, what you actually typed in is a GET method.
There are 2 ways of submitting data: POST AND GET.
Post is by submitting data by using a form in a webpage that posts to another on the background, while GET is setting the data in the url itself like user=myuser.
Most of the times using a GET method (url query string) will not work if the web programmer actually is checking for a POST method. The same happens if the programmer is waiting for a GET request and you actually POST it.
However there is a php var called REQUEST which will work with GET and POST.
I'm no professional in PHP but because you had no answers at the moment I tried my best to explain it. Hopefully some expert will come along and explain it properly.
You edited your question while I was replying so you need someone to answer you on your second question.

Add more input to YUI POST CONNECTION

can some one help me please.
how can I add 1 more input to YUI POST CONNECTION
Here is the tutorial: http://developer.yahoo.com/yui/examples/connection/post.html
And the default sample form is: <form><input type="button" value="Send a POST Request" onClick="makeRequest();"></form>
How can I add one more input like that:
<form>
<input type="text" name="username">
<input type="button" value="Send a POST Request" onClick="makeRequest();">
</form>
I want to send username input request too.
Thank you !!
The example you reference builds the POST request body manually. While you can certainly do this, you might find it easier to use the setForm method of the Connection Manager (example here). It will include all the form fields and take care of the URL encoding for you.

Resources