Refresh browser without "Confirm Form Resubmission" in perl - html

I have a perl script that prints out HTML code and runs actions based on user input in the HTML page. I would like to be able to disable the "Confirm Form Resubmission" warning and prevent the users from repeating the last command ran. I saw some posts that solve this issue in php, but not sure how I would do it with perl.
Thanks!

The usual technique for preventing this is the Post/Get Redirect pattern.
This doesn't stop browsers from behaving as they do, but it redirects users to a new page after a successful POST, so that if they refresh they are not repeating the POST, but repeating the GET instead, which doesn't cause a warning.
Here is an example of the flow:
GET "Products/Create"
User types in some information
POST "Products/Create"
Validation fails, re-display the form with warnings - user corrects the input
POST "Products/Create"
Validation passes, item is saved redirect, using a GET to "Products/View/5"
User refreshes the page, this results in a harmless GET "Products/View/5"
To issue a redirect, you can use:
use CGI;
my $query=new CGI;
print $query->redirect('http://www.example.com/newpage');

Related

Yii2. Built-in client-side allowed HTML-tags validator?

When a user submits a certain form, I remove all of the forbidden HTML-tags from one of its fields before the whole form is validated, so here is a problem: when a user sends nothing, but forbidden HTML-tags in the field, the field will be totally empty, thus, my site will think it is originally so, and it warn the user that it shouldn't be empty.
To prevent that, I have to check the field's contents before submitting it on the client side to ensure that it has no forbidden HTML-tags and I wonder if there is such a feature built-in in Yii2? If not, is there a JavaScript interface to show any sort of warnings for the field the same way Yii2's validation shows them when something is wrong about the form's contents?
Maybe you should check JavaScript validation at: https://yii2-cookbook.readthedocs.io/forms-activeform-js/#working-with-activeform-via-javascript

Is there a way to not show parameters in url

Is there a way to only show a clean url when doing a get request?
i.e. someone is send to a page:
http://domain.com/?param1=1&param2=2
And the user only sees :
http://domain.com
I tried it with a post-request but then you get these annoying pop-ups when someone refreshes the page or hits the back button.
Doing a post-redirect-get is also not possible since this increases the response time to much and the page is generated dynamically so it needs the parameters.
You could use URL rewriting when you are using Apache.
Or similar functionalities in other web servers.
There are 3 ways to pass parameters from a client to a server:
GET request; which you don't want to use
POST body (includes post-redirect-get); you don't wan to use POST
request header
The way to have a client pass arbitrary parameters in a request header is cookies.

Embedded processor web server; passing information from browwer to server

I have a simple web server going on an Atmel embedded processor. It's a Cortex M4 and it's only running FreeRTOS as an OS; this is not a high powered processor.
I can have it [the Atmel processor] serve up a page by typing in Firefox:
192.168.0.200
This renders a page with drop down boxes and a submit button that enables me to pass data back to the server to control the hardware.
I am using the follwing kind of HTML. Please note, it looks slightly odd because it's in a C string:
"<form> \
<select name=\"group\"> \
<option value=\"10\">10</option> \
<option value=\"11\">11</option> \
<option value=\"12\">12</option> \
<option value=\"Broadcast\">255</option> \
</select> \
<input type=\"submit\" value=\"Submit\"> \
</form>"
You can see that, in its address bar, the browser then has something like:
192.168.0.200/?group=4
When the web server on the emebedded processor gets that message in, I can happily parse the line, extract a group number and act on it.
However, I have to send back another page to the browser when I get the
192.168.0.200/?group=4
message into the Atmel processor. Otherwise I get a timeout message. I can happily send the original page back again and it essentially works, but sending the page back resets the values of what the drop down boxes have changed to.
Is there a way of making the browser send a message that the server can parse, but not have to send out the full page again? I guess I'm needing to use something like a POST command, but I don't know how to do that from a web page. I should say that I am experienced in C, but have no HTML knowledge other than what I have learnt in the last few days, so it may be something easy that it completely eluding me from cramming in all this learning this week!
I don't want to/assume I can't use Javascript, because I have such a simple server I need to keep it as simple as possible.
Thanks!
Is there a way of making the browser send a message that the server can parse, but not have to send out the full page again?
Forget about the browser.
Have the server respond with a 204 No Content response instead of a 200 OK response.
If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.
I don't want to/assume I can't use Javascript, because I have such a simple server I need to keep it as simple as possible.
JavaScript runs client side. You don't need the server to do anything complicated to serve JS. You can even embed it in the HTML document.
You could use Ajax to solve your problem instead of a No Content response.

Prettyfaces/Primefaces Addressbar URL refresh

I am a beginner of Prettyfaces, so please forgive me if I missed something really basic.
My url-mapping contains a EL-injected path parameter. The parameter value could be changed by user through selecting a drop down list item.
My question is: since it's an ajax call, the view id didn't change, so if I bookmark the url, the value still contains the original parameter value instead of the user update one. How do I get the browser addressbar url updated based on user's action?
There are two solutions here. You can respond to the AJAX request with a 302 Temporary Redirect, e.g: response.sendRedirect("/new/location") - usually done through JSF navigation.
Or, when the AJAX response comes back, you can use the JavaScript HTML5 push-state history API (if the browser supports it) to update the address directly: Good tutorial for using HTML5 History API (Pushstate?)

Django Form POST with Back button.

I am submitting a form using Django. All things went well until I hit back button.
This is the time IE displays "The wab page has expired. "
I have searched a lot, but can not find the exact concept to do it right.
Open page with get request . /user/search/
Post request with form data on the same page /user/search/
[Optional] Either change params and POST
Hit back button.
In both cases you will get webpage Expired. Please guide me how to make this work & avoid the error message?
You shouldn't be using POST for search forms. POST is for actions that change data on the server. Use GET and you won't have this problem.