Robert has created a user-defined function to ensure that the form fields are not left blank while
submitting the form. This is a time-consuming task. Help Robert to identify the form attribute that
he can use to ensure that the form fields are not left blank
Since Robert is working in HTML5, Robert can use the required attribute(for input fields) instead of writing separate user-defined function for blank fields.
Usage of the same
Username: <input type="text" name="usrname" required>
I hope this is helpful to Robert!!
There are also a variety of third party plugins to ensure the same. Robert should consider those options too!!
Related
We have an assessment engine in which the questions contain form inputs (input, select, etc). In order to display the answer, we replicated the question exactly and display the correct answer. By default the answer is a hidden copy of the question, and we just intended to display it and set the value to the correct answer. There is no security issue because the quiz does not contain the information as to the correct answer until the user clicks to populate, and the server will not give the information until after a release day/time.
However, just having the inputs mirrored means that it looks like the quiz has double the number of inputs. Is there any way to flag inputs in a form to be ignored (ie, NOT SENT to the server?)
Otherwise, the easy way to do this seems to be to write two pages, one with only questions, and one with questions and answers.
<form method="post" action="grade">
What is 2+2?
<input id="q1_1">
<div class="answer">
<input id="a_1_1">
</div>
</form>
The CSS for answer contains display: none so at first, the answers are not displayed, and they can be dynamically made viewable by JavaScript.
Setting the disabled attribute on the input will omit it from the form post.
…disabled controls can not receive focus and are not submitted with the form…
I have a form to submit to my database and I need to setup restrictions on my form. Does anyone know how to limit certain links to be submitted on a form. For example, a user can only submit google.com links with anything following it, it just has to start with the root: google.com/(anything). Thanks! Below is some code of what I got now.
<input type="text"
required pattern="google.com/ | apple.com/ | facebook.com/"
/>
You need to use a regular expression, something like that:
(....google.de/.)|(....apple.com/.)
"." stands for any character
"*" stands for repeating it any amount of times
"|" is or, but you need to use brackets i think
Chrome is being overzealous and thinks my HTML form contains credit card information and thus proposes to fill it in with credit card information.
Are there any attributes that I can use to tell Chrome that there is no credit card information to be filled in, in this form?
The field names it is trying fill in credit card information in are:
reg_id (it puts in a CC number here)
emergency_first_name (it puts in first name here)
emergency_last_name (it puts in last name here)
I don't want to have to disable autocomplete if I don't have to.
The frustrating thing here is the Chrome 'knows better' attitude, where it ignores any value to autocomplete, including off:
<input autocomplete="off" value="" size="10" maxlength="10" id="id_reg_id" name="reg_id" type="text">
Edit: updated following answers.
try
input type="custom"
or use textarea with a single row and resize off
Your browser shouldn't remember your credit card number by default -- I can only assume that you entered into a field that had a 'generic' autocomplete value on it. You can always force your browser to forget this information by simply hitting Delete when selecting it (with the arrow keys) in the dropdown of pre-fill options.
As for preventing it appearing in certain fields, it depends on what information you want each field to hold, but there's a wide array of autocomplete values that you can use. You can use number for IDs, and the other two fields you mentioned actually come with specialised autocomplete values, given-name and family-name:
<input name="reg_id" autocomplete="number" />
<input name="emergency_first_name" autocomplete="given-name" />
<input name="emergency_last_name" autocomplete="family-name" />
If number just won't cut it, you can also make use of a JavaScript regular expression to further restrict input:
const regex = new RegExp("^[a-zA-Z]+$");
const form = document.getElementsByTagName('form')[0];
const reg_id = document.getElementsByTagName('input')[0];
form.addEventListener('click', function(e) {
e.preventDefault();
if (regex.test(reg_id)) {
this.submit();
}
});
<form>
<input name="reg_id" autocomplete="number" />
<input name="emergency_first_name" autocomplete="given-name" />
<input name="emergency_last_name" autocomplete="family-name" />
</form>
I have been banging my head against the desk for a while because of this. We have forms to enter Instruments test data, and a field called "Test Card Number", as well as "Kit (Exp. Date)". Guess what Chrome thinks these fields are for?
Needless to say, I'm pretty sure the users would be VERY upset to see chrome us trying to pull their CC information when they're inputing clinical research data.
Even autocomplete="new-password" and autocomplete="nope" are failing to do any good, here.
I tried to load the field with no label and add it dynamically in javascript. No dice. Used html entities instead of characters. Nope.
Well, after a few hours of scouring the web with no solution in sight, I figured one out: insert a few random - within each word of the offending labels. (For me, with Test Card Number, it had to be in BOTH Card and Number. Test was fine left alone).
One could easily write a javascript extension/utility function to split the html of an offending label and slap that invisible span down the middle (and one to remove it in case of needing to use the label value).
Something like this (using jQuery and old js standards because we support old browsers, with no verifications if label is missing or empty, so adapt accordingly. In fact, I'm sure a regex or some other fancy stuff could be used, but I don't have the time to fiddle around with it atm):
jQuery.fn.breakAutofill = function () {
var $lbl = $("label[for='" + this[0].id + "']"),
finalText = $lbl.html().split(" "),
foilSpan = "<span style='display:none;'>-</span>";
for (var idx in finalText) {
var textVal = finalText[idx],
midPos = Math.floor(textVal.length / 2);
finalText[idx] = textVal.substr(0, midPos) + foilSpan + textVal.substr(midPos);
}
$lbl.html(finalText.join(" "));
}
Which you can then call on document ready :
$("your_input_selector").breakAutofill();
I hope that helps someone.
I have an HTML form that sends a food dish. For example,
placeorder.com/order.php?id=STEAK
I want to add another value and send
placeorder.com/order.php?category=MEAT&id=STEAK
But, I don't want the user to have to select meat anywhere, since this has been already decided.
I tried to tinker with the form target and include it from there, but it didn't work.
Is there some "hidden text box" to write the category to so that it gets posted, or is there another way to do it?
Thanks in advance!
First, I just thought I'd mention that it's funny how the questions is phrased since you pretty much answered your own question:
Is there some "hidden text box"
Anyway, yes:
You can use type='hidden'
I assume that you are already using a GET form so I will just include the input part:
<input name='category' type='hidden' value='MEAT'>
I'm writing a landing page to test a business idea.
For testing purpose, I want to write a Credit card number field, to see if the customer is actually ready to buy the product.
As it is only a test, I don't want this value to be submitted.
Actually for security purposes I don't even want this value to be sent in the request.
Is a separate form enough?
<form> Sensitive info</form>
<form>Info I want
<input type="submit">
</form>
Yes, only the elements from the one form will be sent (whichever one was submitted).
Alternatively, you could:
mark the input as disabled (either from the start, or onsubmit)
remove the name attribute of the input
put another input later in the form with the same name (it will override the value of the first)
Yes, that will work.