Form action relative URL - html

I have html file like this:
<!DOCTYPE html>
<html>
<head>
<title>HTML Form</title>
</head>
<body>
</body>
</html>
<FORM action="/wsd/html_form_check" method="post">
<P>
//INPUTS AND LABES AND THINGS
<INPUT type="submit" value="Send">
</P>
</FORM>
Now I get an error saying
AssertionError: Invalid form action.
I suppose it has something to do with the
<FORM action="/wsd/html_form_check" method="post">
I was told that the HTTP request should look like this:
POST /wsd/html_form_check HTTP/1.1
Host: 127.0.0.1
So what am I doing wrong? Any help is appreciated!
Thanks!

A bit late, but I had to deal with the same issue.
Consider the following piece of HTML code:
<form id="file_uploader" action="/Home/Upload" class="dropzone">
<div class="fallback">
<input name="file" type="file" multiple />
</div>
</form>
In the development environment it runs fine. However, deploying it to IIS anywhere else but the root website will cause the action URL to become invalid. For instance, if it were deployed to https://example.com/deployed_app, then the actual action URL that the form will call is https://example.com/Home/Upload, which is invalid.
The solution is to change the action URL to this:
<form id="file_uploader" action="~/Home/Upload" class="dropzone">

If you're trying to send the data entered in the form to "html_form_check" you haven't used the file extension such as .php or .js. Try adding the file extension and see if that helps !

Related

Simple form submission redirect to wrong page, why?

I can't understand this behaviour in Google App Script, can someone explain?
This is a very simple script bound to a Sheet. Code:
Code.js
function doGet() {
return HtmlService.createHtmlOutputFromFile("index.html");
}
function doPost() {
return HtmlService.createHtmlOutputFromFile("index.html");
}
index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form id="form" name="form" action="" method="POST">
<input type="submit" id="submit" name="submit" value="submit">
</form>
</body>
</html>
Looks simple enough right? Well when you click the submit button, the page redirect to a blank page.
I already know how to work around this behavior (by using script.run or even hackier by querying for the page's URL), but what I want is to know WHY things go wrong here, because what's the point of the doPost method if you can't even use it.
This is because your page is served from another url *.googleusercontent.com for security reasons. The point of doPost method is you can post to the published url from your client(say, local Python script/nodeJs) anywhere on any server as long as you know the published url.

how can i res.send() to a specific id of an html tag? - Node js

I have search.html with this form:
<form class="myform" action="/classi" autocomplete="on">
<input type="text" name="search" >
<button type="submit" ></button>
when i press the button:
index.js:
router.get('/classi',function(req,res,next){
res.send("ciaoo")
});
I want to send the text "ciaoo" to a specific id of my html tag in another page html "classi.html".
classi.html
<head>
<body>
<h1 id="ciao"></h1>
</body>
</head>
How can I do? Thanks
For that, you have to add a script in your HTML file and then you can communicate through ajax call and modify your HTML through the script.
Make a JS file and include the file in HTML and follow these steps -
Make an AJAX call(GET ..../classi) to your server using XMLHttpRequest.
Get response in callback (or in then if using promise).
Modify the HTML with the response.

HTML File Upload issue

possibly a stupid question but how do I upload files to a server using the browser ?
I'm sure I've used this before ! But when I run it nothing appears to happen.
No errors are shown and nothing is logged in the error_log
<?php
var_dump($_FILES);
echo $_FILES['uploadFile']['tmp_name'];
?>
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>
<form action="test.php" method="post"><br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="submit" value="Upload File">
</form>
</body>
</html>
What am I doing wrong ?
When you submit a form, the data you are sending to be encoded somehow to be put in the HTTP request.
By default, this uses the application/x-www-form-urlencoded algorithm which does not support file uploads. You need to use multipart/form-data instead.
<form action="test.php" method="post" enctype="multipart/form-data">
Try to correct you form declaration attribute and always when you need to upload files include "enctype". If not file input element is in form, the default enctype is "application/x-www-form-urlencoded":
<form action="test.php" method="post" enctype="multipart/form-data">
FORM in HTML

HTML Form does not submit with forward slash

I was developing a simple HTML form and I couldn't figure out why the following code works on Chrome but not in Firefox.
<!DOCTYPE html>
<html>
<body>
<form action="/hello.html" method="get">
<input type="submit" value="Submit">
</form>
</body>
</html>
After a while I figured out that the issue is the slash in the action url.
When the form action starts with a forward slash ('/'), the form is not submitted in firefox.
Without '/' from the action tag, pressing the 'submit' button results in a redirect to the hello.html page.
For me this behaviour is weird. I think it is valid to start a (relative) URL in the action attribute of a form tag with a forward slash.
Do you have some explanation for this behaviour?
It works in Google Chrome because Chrome is forgiving (or smart). What you actually mean is either:
<form action="hello.html" method="get">
or
<form action="./hello.html" method="get">
What's the difference to /hello.html?
Let's assume the URI of your file is file:///c:/somedir/index.html
./hello.html and hello.html both resolve to file:///c:/somedir/hello.html since they refer to the current directory.
But /hello.html resolves to file:///c:/hello.html because according to http://www.ietf.org/rfc/rfc2396.txt (page 16)
A relative reference beginning with a single slash character is termed
an absolute-path reference ...
The following example works. I am not sure why your code doesn't work.
<html>
<body>
<form action="/my-handling-form-page" method="post">
<div>
<label for="name">StackOverflow name:</label>
<input type="text" id="name" />
</div>
<label for="mail">Email:</label>
<input type="email" id="mail" />
</div>
</form>
</body>
</html>
However, when I removed <!DOCTYPE html> from your code, it started working too.

working with forms in HTML 5

i have tried the following code while trying to learn html forms:
<head>
<title>Example</title>
</head>
<body>
<form method="post" action="http://titan:8080/form">
<input name="fave"/>
<input name="name"/>
<button>Submit Vote</button>
</form>
</body>
but its not working the webpage shows this message: "Oops! Google Chrome could not find titan:8080"
The action attribute must contain a valid URL. In this case, the server part of the URL is not valid, since titan is not a valid domain name. It should be something like titan.example or titan.foobar.example.com (naturally, you need to use the real, working domain name; the names I used are guaranteed to not work, i.e. for use as dummy examples only).
Alternatively, if you are running a local HTTP server, at port 8080, in the computer where you use the HTML page, use the reserved name localhost as in action="http://localhost:8080/form">.
The url you have provided http://titan:8080/form is timing out ensure you have the correct url or that the page is live.
<title>Example</title>
<form method="post" action="#a">
<input name="fave"/>
<input name="name"/>
<button>Submit Vote</button>
</form>