HtmlInputFile through post action - html

I have a web page which have 3 controls:
form using the post command.
in the form i have an input file control named "myFile".
a button
the upload process works just fine, until I'm trying to post the form and handle the upload in another form.
Request["myFile"] and request.Params["myFile"] gave me nothing

It's the Request.Files collection you need - look it up in the .NET Framework docs:
Request.Files["myFile"]
Also make sure that the enctype attribute of your upload form is set correctly - it should be "multipart/form-data" if the form contains file inputs.

Maybe this will help
<input type="file" size="50" id="ipFile" runat="server"/>
runat="server" gives you access tot the HtmlInputFile structure

Related

Primefaces File Upload - Make sure user uploads files before leaving page

I am using PrimeFaces File Upload with mode="advanced" and multiple="true" just like the demo shows here https://www.primefaces.org/showcase/ui/file/upload/multiple.xhtml?jfwid=50dd6
In this case, the user uploads multiple files and is shown the files to edit the list. The user must then click "upload" to upload the files. If they fail to click upload and submit the form on the page, the files don't get uploaded. I know about the auto="true" option, but we want to keep the ability to edit the list.
How can I prevent form submission if the user has pending file uploads?
You can block the submit button by checking the number of files in the onclick attribute:
<h:form>
<p:fileUpload widgetVar="upload" .../>
<p:commandButton onclick="return PF('upload').files.length===0" .../>
</h:form>
Of course it would be better to extend this check and show a message to the user if they forgot to upload any files. For example by adding a message to a p:growl component:
PF('growl').add({detail:'Please upload files first',severity:'warn'});
See also:
Add message to p:growl using Javascript
Well I don't know if you are using some other "dirty" form logic but can't you just set your dirty flag in the onAdd JS function of the FileUploader?
onAdd="setDirty(true);"
Then you can use onBeforeUnload to display the dirty dialog like in this post: What is the easiest way to detect if at least one field has been changed on an HTML form?

HTML form with GET method to PDF file ignores query string

I have this simple web form which has just a single button so the user can open a static PDF file when they click it.
Now that I've updated the PDF file, I updated the query string timestamp cache-busting parameter so they see a new version of the file.
<form action="Path/To/My/PDF Document.pdf?v=1234" target="_blank">
<button>Get your PDF here!</button>
</form>
Well, the PDF opens up alright, but the querystring is automatically reduced to just the question mark.
What opens up is: Path/To/My/PDF Document.pdf?
This shows the original version and not the new one, and I'm wondering what is the matter with this process?
*I know method="GET" is not in my example, but it does the same with or without it.
Give this a go:
<form
action="Path/To/My/PDF Document.pdf"
method="GET">
<input type="hidden" name="v" value="1234" />
<button>Get your PDF here!</button>
</form>
Key points:
specify the method as GET
provide the query-string parameter as a hidden input, with the name set to the name of the query-string
The reason this works is because of how forms process input data.
Demo: https://jsfiddle.net/1tszbe5o/
Recommended reading for WHY this works: https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_and_retrieving_form_data
TLDR: when you use the GET method, any form data provided with form inputs will be included in the query-string of the HTTP request resulting from the form action.
Why does it get stripped out in the first place? Because the form data was empty, hence the query-string was empty also ;)

how do I make a web browser display html in vb?

So I have a web browser, and it needs to login using html code that will get modified by textbox inputs. I know how to use the textbox inputs to modify the code, but how can I make the web browser run the code?
The code:
<form action="https://api.roblox.com/login/v1" method="post">
<input name="username" value="">
<input name="password" value="">
<button>Login</button>
so from what i can see there are three ways you can do this :
1) You can make the vb form enter the inputs required and submit the form in the background according to user inputs (which you have mentioned you already now about).However heres some code to do it :
WebBrowser1.Document.GetElementById("username").SetAttribute("value", TextBox1.Text)
WebBrowser1.Document.GetElementById("password").SetAttribute("value", TextBox2.Text)
WebBrowser1.Document.Forms(1).InvokeMember("submit")
2) You could also just save that html code as a html webpage and host it on a domain and then use this code to navigate it to your html page WebBrowser1.Navigate('http://www.yourhtmldomain.com')
3) If you want to run the html file from a local source lets say where the exe file for the web browser is located we would use this line of code ;
WebBrowser1.Navigate App.Path & "/mysite.html"

How to get info from a form in Rails?

I'm new on Rails and web developping.
I wonder how I can get what's written inside a form.
This is what I have :
<form>
<input id="bottom" type="email" name="email" placeholder="email"/>
<input type="submit" value="Ok"/>
</form>
What I want now is to get and save what written in the input, but I don't know how do to do it with rails.
Add a route and map it to the controller. Use the defined route in the action.
in the controller you can access the values as params[:input_name]. Replace input_name with the corresponding values.
I recommend to install 'pry' gem which allows you to write 'binding.pry' somewhere in the code (in your case you should add this line to your controller 'create' action which is responsible for the page where is your form located).
What will happen? Whenever you press submit button, you go to console and see that it shows you a 'create' action. Then you can type 'params' and press 'enter' and you will see how is the data from form stored.
The 'pry' gem is really essential assistant for Rails developing. You can paste 'binding.pry' at any point to check what is happening.

How to use the form value in the action?

I am trying to make a form in html that uses the value you enter to form the destination URL.
<form action="../search/${params.q}" method="post" id="q">
Busqueda: <input type="text" name="q" /><br />
</form>
This is what i am doing, but it does not work, any cluess? thanks!
You'd need to handle this using a script - either server-side or on the client (JavaScript).
HTML alone can't handle parameters in the way you're using them.
So you'd need to either POST the form (as you're already doing) and handle the postback by redirecting your request to the new address, or use JavaScript to capture the field's value when a submit button is clicked and loading the new address in the browser window.
I'd suggest server-side is the best option as JavaScript might be disabled or unavailable.