Persisting form data after post expressjs - javascript

I have an Express.js application and I would like to know how I can persist form data (text area) after a post request without using AJAX.
I hope I am not vague. Thanks in advance.

The default value of a textarea is the child text node inside it. Copy the data into there, and put it in the response you make to the submission request:
<textarea name="foo">HTML escaped copy of the previously submitted foo</textarea>

Related

Post Array using window.location.href in ASP.NET MVC

I need to send data to a Controller to Post data currently I'm not using a form only I need to send an array for parameters, what is the right way to do it ?now I'm using this line of code but I know that it is used for Get method instead of Post method:
window.location.href = "#Url.Action("Edit", "PurchaseOrder")?arr"+urlParams;
the only easy way to post data to a controller is to do it through a form. but that doesnt mean the form needs any text input or stuff like that as long as code the data in and you make it invisible for a user you can just use a button that looks like a normal button but is actually a form in de code.
else if you dont want to use a form to send the data even if the inputs on the form are not visible you could use AJAX to send a post request but i dont think you want to do that.
if you are already getting the data from a different page in my oppinion it would be easier to just use sessions to store the values when you get them for the first time

Is there a way to get the form data easily with JavaScript?

I was looking on how to get values of form data that are passed with POST requests and found this answer.
I know you you can get GET query parameters quite easily in JavaScript doing window.location.search but is there a way to do similar for POST request or document.forms is my only option?
To expand on what RUJordan said:
When you do a POST, the information is sent to the server using an entirely different method and does not show up in the URL or anywhere else that JavaScript can get access to it.
The server, and only the server, can see it.
Now, it is possible to take some of the form data and fill JavaScript variables and/or hidden form fields so the server can pass data back down to the client.
If you need more help, you'd be better off opening another question explaining exactly what problem you are trying to solve.
Do you want javascript to see the data was POSTed to load the current page?
JavaScript does not have access to the request body (where the POST content is) that loaded the page. If you want to be able to interact with the POSTed parameters, the server that received the request would need to respond with the necessary data written back out on the page where javascript can find it. This would be done after the form was submitted, as part of the response to that POST request.
Or do you want to know what your page could POST form the forms that are on it?
Inspecting document.forms will let you see what could be POSTed later if those forms were submitted. This would be done before the form was submitted, without a request being made.

Front end form submission

I've been looking around and haven't been able to find an answer to this.
I have a form that has to be submitted and the data to be processed entirely on the front end(in javascript). Is there a way that I can pass the form data to an action page and not to the same page. Right now I'm just emptying all data in the section and replacing it with the data that is being called; but I would like to do this similar to how a form would interact with php or python.
Thank you
-Art
What you could do is use HTML5 local or session storage to store all of the form values that a user enters and then on the new page use the stored values as you require.
http://diveintohtml5.info/storage.html

Posting data on server using asp.net

I have name and email id fields and want to post data to server to another website (if fields are valid) using form tags but i already have one form tag with runat="server", using second form tag causes second form to not show on page. I have JavaScript code to post data to server on form post. I saw something using action on button click, but how do i post data on button click
P.S I don't want to use iFrame, popup.
To send POST data on a form submit, try to use a submit button like this:
<input type="submit" value="POST_DATA" name="POST_PARAMETER_NAME">
Replace POST_DATA with your data you want to submit and replace POST_PARAMETER_NAME with the parameter name you want to access the data on the server.
If you already have a form on the page that uses asp.net web forms to communicate with the server then you would probably need to make an ajax request if you want to post back different data. This is quite easy these days using jQuery. The link bellow shows you how you may do this and how to create a web forms page that would accept your post. This way your current form and page would not need to change which is what it sounds like you are after.
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

Python - Fill and submit a HTML Form

I would like to fill in and submit a form on a web page using python. The form I want to interact with has several drop down boxes which are filled using JavaScript. I have looked at the mechanize library but it doesn't handle JavaScript. Can you suggest an alternate library/method for interacting with the form?
Cheers,
Pete
Selenium RC or Windmill (http://www.getwindmill.com/)
Examine the form's returned GET or POST values;
use urllib2 to submit synthesized requests directly.
The form effectively sends information back to the server (or maybe somewhere else) after you press the submit button.
I don't know how you would directly interact with the form, but you could just send the information back to the server in the same way as submitting the form would (without actually submitting it or physically pressing on things).
So for example some forms put the parameters specified in the form (and their values) at the end of the url in the HTTP request once submitting the form. Others put the parameters in the body of the HTTP request. In PHP i know that PHP automatically takes these parameters out for you (into a global array).
In this case you would simply put your own version of the parameters (names/values) in the HTTP request, by looking a what names/values there are in the forms source code.
Although the form may send its information to the server using javascript...
Sorry if that made no sense.

Categories

Resources