Anyone know how to make an entire form disappear on a jsp page? - forms

<H1 align="center">ID Lookup</H1>
<FORM ACTION="index.jsp" METHOD="POST">
<H3 ALIGN="center">Please enter your User ID:</H3>
<INPUT TYPE="TEXT" NAME="userIDTextBox">
<br>
<br>
<INPUT TYPE="SUBMIT" value="Submit">
<%
String userID = request.getParameter("userIDTextBox");
%>
</FORM>
I'm a beginner and this is my form on my jsp page. What I want to do is have the form disappear after submitting. Can anyone help me please? Or give some tips?

Give your form an ID, then use a javascript command to get your form element and set its visibility.
var myform = document.getElementById('myForm');
myform.style.visibility="hidden";
Now you just need to handle a javascript event and run that.

After Reading your requirement all I understand is you are trying to read parameter "userIDTextBox" from one page and need to display the value to some other page. And You are trying to achieve the same in one page.
Rather have two separate pages..
First with Form and required text field
Other to display the value
Define servlet and servlet-mapping configuration in web.xml
That is the valid way to do it. Hope it may help

Related

Codeigniter 4 form action path

sorry for the very noob question. I have a page : www.example.com/edit/3 with form inside.
<form class="" action="" method="post">
Usually my form action I will specify something like add, register, etc. In this case, I am not sure how do I specify it. Currently it is working when I save it if I leave it blank without specifying anything. But I am not sure is this the right way to do it.
Controller
public function edit_game(){}
Routes
$routes->match(['get', 'post'], 'account/edit_game/(:num)', 'Addgame::edit_game/$1');
Can anyone advise?
action="" is the URI to which send the form data, aka the controller where you treat the received data. If not specified, it will be the same page as the one you are currently on.
What you can do:
<form method="post">
</form>
<form method="post" action=""> <!-- same as previous -->
</form>
<form method="post" action="/some/page">
</form>
In the last example, note the leading /, it means it is according to the site root. If you forget it, it will be relative to the current URI.
Exemple, if the page containing the <form> is http://example.com/edit/3:
action="/some/page" will redirect to http://example.com/some/page.
action="some/page" will redirect to http://example.com/edit/some/page

PHP 5.3.10 global behaviour

I'm having trouble with a global variable, I think it might be pulling its data from a HTML Form Input, but I can't find any documentation on the web about global var pulling data from a HTML Form Input.
Thanks.
When a form is submitted the method tag specifies if it is a POST or GET request. Depending on what method your form is using your form values can either be in your $_POST or $_GET Super global.
Example:
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
After the submit button on the form is clicked the form contents can be found by referencing the name attribute in the super global(In this case the POST).
$_POST['name']
$_POST['email']
For documentation see
http://php.net/manual/en/reserved.variables.post.php
This applies to PHP 4 >= 4.1.0, PHP 5, PHP 7 ie. fits PHP 5.3.

Prevent user to skip a line in a form

On my website, users can fill out a form. By default they can skip lines in the form, but how can i prevent this?
this is my code
<div class="form-group">
<label class="label-main">{{ t('Description') }}</label>
<textarea name="[description]" class="form-control" placeholder="Your message" rows="7" maxlength="500"></textarea>
</div>
Thanks!
There is no HTML-way to achieve this. With e.g. Javascript you could disable the "enter"-key for the textarea or monitor and correct the user input in real time, but that would supposingly confuse the user. Therefore I'd suggest to simply validate the user input (e.g. with Javascript) on form submit and remove all blank lines from the text without bothering the user with it.
This might help you how to do: Javascript: How to use a regular expression to remove blank lines from a string?

Autofill populating wrong fields

I have a site with a checkout page that has always worked beautifully.
Recently, any customer that uses autofill to fill out his info, gets his email address dumped into the company field.
There are no changes that we did that could affect that.
What other tools can I use to get to the bottom of this?
The OP's problem may have been solved (or may have come back again in recent updates!) but as of early 2019, you can diagnose some of these problems by setting the show-autofill-type-predictions flag in chrome://flags, restarting Chrome, then looking at the title (tooltip text) for the input in question. It will tell you what information is being used to guess the "type" of field, and what kind of saved data should be used to populate it.
We still don't know what caused the issue, but for anyone seeing this we ended up making the field readonly so that auto-fill doesn't fill it. We then wrote some JS that on focus, it becomes active and the user can manually fill it in.
<input type="text" name="company" readonly="" onfocus="this.removeAttribute('readonly');">
Found myself in a similar problem, and the autocomplete property is what to be used in this situations
<input type="text" name="fooBar" autocomplete="organization" >
exhaustive list of autocomplete/autofill tags for html form inputs
I encountered a similar problem, having a "company" field placed under a "name" field. That company field was auto-filled with a birth year.
It came from another form on the same site that was displaying a "birthdate" field group just below the "name" field. So chrome stored its auto-fill values in that order.
I ended up with changing my second form field order (sadly it was the best I could do).
You need to add name to the input tag. Browsers use name to identify what info is supposed to go into the field. You can also use the same for ID and for placeholder if you like.
Try this:
<input type="text" name="company" id="company" placeholder="company">
If that still does not work, you might consider turning off autofill for that particular field*:
<input type="text" name="company" id="company" placeholder="company" autocomplete="off">
*you can also turn off autofill for the whole form using the same autocomplete property and off value.
We recently started having an issue like this with our shopping cart page when it was viewed from chrome and you had a saved user name and password for the site. Chrome would inexplicably put the user name value into the quantity box. After much hair-pulling, we realized that there were a hidden user name and password field on the page. These auto-filled correctly when visible. When hidden chrome would auto-fill the quantity input box. By setting autocomplete="username" and autocomplete="current-password" on these controls the issue went away.
The Almost Invisible Input Proxy Trick
I just encountered the same issue with the Chrome 72... It just wanted to fill any kind of field (select or input) as long it was not readonly (with complete no respect for name, autocomplete, etc attributes), with any kind of value it may have stored previously.
You may want to avoid the field to be populated because you listen on the change event or there are some validation on input that may trigger error message just because of bad autofill.
You just want the autofill value to be discarded and not even show (even before javascript execution).
You just provide another field for the browser to fill and you make it almost impossible to see by hiding it under the other field.
<input type="text" id="autofill-if-you-dare" style="position: absolute; z-index: -1; top: 20px; width: 0; height:0" />
Note: You can still hide or remove it by javascript afterwards but you should not hide it before autofilling has been completed, because Chrome will populate only visible fields. And as other answers have stated, it doesn't trigger any event, so you must rely on polling to do so.
I had the problem that chrome will fill in my email in all fields in one of my forms. The other form works correctly.
I found the problem is that the word Name must be before the name input. Or the word email must be before input for email. I had it afterwards. Also using <label for="email">Your email</label> after the email input worked.
**Incorrect autocomplete:**
<input type="text" name="name"/> Your name
<input type="email" name="email"/> Your email
**Correct autocomplete:**
Your name <input type="text" name="name"/>
Your email <input type="email" name="email"/>
or
<label for="name">Your name</label> <input type="text" name="name"/>
<label for="email">Your email</label> <input type="email" name="email"/>
or
<input type="text" name="name"/> <label for="name">Your name</label>
<input type="email" name="email"/> <label for="email">Your email</label>
I solved this problem by making sure the section I was adding was actually wrapped in a <form> tag. The site's global "search" field was being considered part of the page's form because neither had a <form> tag.
Since you can have inputs outside of forms, and this isn't really a big problem for a single-page-app (maybe not the best practice though!), this might be a worthwhile thing to check.
February 2021:
autocomplete="__away" worked for me src.
autocomplete="new-password" also worked src.
Still hacky but it worked for me in Chrome and MS Edge both 88.0.7.
Related(Duplicate?) questions:
Autocomplete Off is completely Ignored
Disabling Chrome Autofill
Autocomplete off vs false?
I have been encountering this issue lately, specifically with chrome. It seems that
autocomplete="off"
isnt being picked up anymore by Chrome. I found the following sources helpful :
Chromium (which i believe is what a lot of Chrome is based on) has the following code that shows the regex that is used when finding fields to populate with Chrome's autocomplete:
https://cs.chromium.org/chromium/src/components/autofill/core/common/autofill_regex_constants.cc?sq=package:chromium&g=0&l=262
I feel like they only other work around that I have found is to follow these conventions :
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
Or at least make sure that you give an attribute that's disimilar enough from the above list so it that wont get picked up by autocomplete features.
Suppose there are three fields, One with wrong autocomplete.
<input type="text" name="field1"/>
<input type="password" name="field2"/>
<input type="text" name="wrongAutocompleteField3"/>
Now make display of wrongAutocompleteField3 as none:
<style>
.d-none{
display:none;
}
</style>
....
<input type="text" name="wrongAutocompleteField3" class="d-none"/>
On page load remove this .d-none class:
<script>
$(function(){
$('[name="wrongAutocompleteField3"]').removeClass('d-none');
});
</script>
In Chrome, add this on the top of the page:
<input id="" class="" name="" type="password" style="display: none;">
You need to add form tag
<form action="#" method="GET">
<input type="text" name="text"/>
</form>

Tinymce Editor in web application

I want to use the Tinymce Editor in my web application. I have a text area on it and I want to submit the data of that text area to the next page. That page should display the data it received. Can you give any suggestions how I can do this.
The best way to think of TinyMCE is as a special textarea. Just like you can submit data from a textarea and retrieve the content via request variables, you can do the same for a TinyMCE editor instance.
In your front-end code, you would have something like this:
...
<script type="text/javascript">
tinyMCE.init({
mode : "textareas"
});
</script>
</head>
<body>
<form method="post" action="show.php">
<p>
<textarea name="content" cols="50" rows="15">Content in TinyMCE</textarea>
<input type="submit" value="Save" />
</p>
</form>
...
Then, in your show.php page, you would retrieve the content like you would retrieve a textarea value:
<?php
...
echo $_POST['content'];
...
It's about as simple as that to retrieve the data and display it in your page. Of course, you would need to take security precautions in displaying data that is entered by an end user. Also, this is assuming you are using PHP as the back-end technology; but, the principles carry over to any technology.
And, consult the TinyMCE documentation for detailed instructions and information on advanced use cases.
You should start with this instructions.
Displaying html content is very simple. You need to place the written text one of yor pages receives on that page - that is all.