Distinguishing between form inputs - html

I have several inputs (file) in my html form. Is there any way on my servlet when the form is submitted that I can get the name attribute of the file tag? I'm asking because the form has 2 different sections for uploading forms, and I need to put the forms into 2 different categories when I process them in the Servlet, and I'm hoping to use the input name prefix to tell what section of the form the file came from. I have prefixes on the input 'name' attributes, but I'm not sure how I can get that on the servlet.
I know with a traditional form, with say an input of type text, I can say: request.getParameter("myInputName") and get the object, but I'm not sure how to handle this with file inputs.

Related

Reference a custom field in NS on the standard HTML transaction form/SO email form

Does anyone know how to reference a NS field in the standard HTML form?
I have a custom field on my SO that links to our external website. The field uses a formula to pull the NS SO internal ID to create the link so we can send it out to the customer. That field works perfect and I was able to get that link to display properly as an element on the standard PDF form layout that gets emailed to the customer as an attachment on the SO notification email.
Now, here is the issue, I don't know how to reference it on the "a href" html tag in the HTML code on the transaction HTML layout. I know the field name/backend ID, I just don't know how to reference it in the "a href" html tag, this is what I have so far:
Securely View, Edit, & Track the status of this order
(in the curly brackets is my field name and I removed the carrots so the exact code would show up in this text box)
Does anyone know how to get that field from the SO form to show up in the Transaction HTML Layout form?
Actually I figured it out. I needed to have the href set as <NLCUSTBODYPG_LINK_SO>.

Why doesn't HTML allow nested forms?

I searched around on the site before posting so I hope this isn't a duplicate, but this has been a question that has been bothering me.
Why doesn't HTML allow nested forms (without JS)? I have seen that it doesn't allow nested forms, but never why they are not allowed. To me, it doesn't make sense why they aren't allowed, especially if each form routes to two different actions. Why is this?
HTML doesn't all nested forms because they would cause more problems than they solve.
Forms in HTML are built for single HTTP requests. If you submit a parent form, should you submit the child form as fields in the parent form to the parent action? Or should the child fields be submitted to the child action as well? How do you handle the responses to both of these requests? Which response do you render? What if the parent submit fails and the child succeeds? How do you handle this in the response markup?
Any of these answers are handled in script rather than markup.
If the fields are required in the parent form, that should be part of its form as a single encapsulated way to represent the data needed for a single request. Any nested form is its own request and should be encapsulated as such.
The reasoning behind this is because the <form> tag expects an event action to be specified and having one form within another form would only cause problems because each form is expecting a different event to occur which could cause unexpected results with submit buttons because their default event to fire is whatever event has been specified in your form action.
The being said, you can have multiple <form> tags on a page, just not nested.
EDIT
You can also read the W3C documentation on the form element here: https://www.w3.org/MarkUp/html3/forms.html
One of the first thing it says is: **
Note you are not allowed to nest FORM elements!
**
I can understand why it seems like this might work...
Think about HTML code in general; you open a <tag> and close the </tag>. Most of the tags can contain multiple other tags, right? The header tag holds tags for the <title>, <meta data>, etc., and the <body> tag wraps a whole bunch of stuff together before you see the </body> tag. Some tags have different rules; like the <img> tag which stands alone. The <form> tag falls into one of those tags with "different rules".
A <form> is actually part of a script. It is presented on the HTML page to your site visitors as a means of gathering information. Once the site visitor clicks on the submit button, the <form> sends the information to it's related script to be processed. All of the <form> tags, whether they are <input> values, <checkboxes>, or <password> fields, are bundled between the opening and closing </form> tags.
Every <form></form> sends information to a seperate script. So, a script that logs the user in would need one <form></form> and a script that allows the user to change his password would be another <form></form>. If you want the script to handle both options, then you would have to code your script to process all of those bits of information.
In summary, a <form></form>cannot be nested because they function as a User Interface to gather information that will be processed by a script stored on your websites' server.

Django: validating hidden input

I am currently in need of some advice regarding best practices when it comes to validating hidden input.
My situation requires me to connect some objects, and I have a form with some fields that provide information about how these should be connected. Though, I also need to know which objects to connect, and I thought best to do this using hidden input. There will be two hidden input fields, both providing pk's, integers. These will not be generated through by the form - I will write the HTML manually.
Now, my idea for validating that no tampering is done to these hidden input fields is this: I will add two integer-fields to the form, two fields that will not be rendered at all, that share the names of the hidden input fields. Hopefully, this would mean that the hidden fields are validated just like all the other fields when run:
form = my_form(request.POST) # request.POST containing hidden-fields as well
form.is_valid():
Would this be a relatively safe way of checking that nothing else than integers are passed via the hidden input? Would this be as safe as normal form processing? Or am I missing something?

handling the request parameters from id elements in server side

In the server side we fetch the form parameters by the form element name. Similarly how to fetch the form parameters in case the input element does not have the name attribute and has the id attribute?
I don't think that is possible. Unless an input element has name attribute it won't even be submitted in the GET/POST request while submitting the form.
So, my understanding is, to read value for any input field in html (on server side) we need to have name attribute defined on it.
Going through w3c specs at HTML specification, it says that the first step that happens during form submissions is Step one: Identify the successful controls. And successful control is the one that has Control name defined on that field. i.e, the name attribute .

HTML form and other elements

I am new to HTML and still trying to understand some concepts. Here it is one that I do not understand at all. After trying HTML form I noticed that if I have a form with attribute name I can access that form the following way document.attribute_name or document[attribute_name]. However if I try to do the same on a div for instance, it does not work. Can somebody please explain me why is this so.
Also, I was wondering if it good practice to use a form when using AJAX. Let say that I have some fields inside a form but I am using ajax and the form never is "posted" as I am using AJAX to change field's contents.
Thanks in advance!
Usually a form has the name attribute in order for you to be able to pass a value to a PHP/ AJAX script.
When writing THE FORM :
<FORM action = 'addDetailsToDatabase.php' method = 'post' >
<input name ='myName'>
<button type = 'submit'>
</form>
When you submit this form it will post the input field value that has the name attribute 'myName' to the addDetailsToDatabase.php script. So now whatever has been entered and submitted in the input you can use in your PHP script.
TAGS do not generally have a need for a name attribute. (I am saying generally need just incase theiris some library out there that uses this I have never seen a name attribut on a div tag.
The best way to get a div is to get it by ID . document.getElementByID('yourdivid') - Javascript.
Your div will look like this
You can use AJAX to post a form to be be run by a PHP script and this has the added benefit of the whole page not being refreshed.
Anwsering the second part its hard what you are asking. With Ajax you can make your page as dynamic as you want
You can select from the database and echo wherever you want the options are limitless (almost). The best thing to do is to learn HTML = SIMPLE Learn CSS =SIMPLE. Then learn some simple JQUERY or javascript. If your dealing with forms and databases learn how to post a form to PHP script and store in a database and then retrieve using the select statement (prepared statements will set you up for years to come try and avoid old SQL tutorials)
Once you get this learn your AJAX to fill the gaps