What is the point of input without name in HTML5? - php

In HTML5, an input without name is also valid
e.g.
<input type="text" id="user" />
But what is the point if I cannot access the form element in my backend PHP code?

Not all input is used server-side. In many cases it's used for form submission via AJAX. Additionally, a JavaScript app can make use of user input without ever needing to use a form.

Click the "link" button on any question or answer here on Stack Overflow, you will see an example of an <input> without a name or associated form.
Granted, this particular input is created with javascript - but it's pretty common to see an input field or textarea for copy/paste purposes, for one example.
..and it's also useful for basically anything to do with javascript.
One non-AJAX example I am currently using:
I have a spreadsheet for several dollar amounts to be filled in. I use an <input> field with no name to display the total amount of each column with javascript. On the server side, I don't need a "total amount" field coming through, and I sure as hell wouldn't trust it. The real total amount is calculated on the server side based on the other inputs, but we still show it in real time on the front end for the user.

Related

Autofill HTML form page for Web Development

I am created a dynamic registration page using HTML, PHP, and Javascript. I am trying to make it so that the form would not be submitted unless it meets the requirements of the form. Some sample requirements are if a field is filled, verified, in email form, or has minimum length. I have a quite a bit of required fields now and it's a pain to fill all of them when I want to test the form. I'm using Eclipse IDE and I'm using the built in web browser and a web server to test the form. I already have code implemented to verify the input upon some basic requirements.
How can I auto fill my HTML form web page with various fields and various types of entry without having to change the code? This is only for testing purposes to verify that my form is producing the correct output given a set of inputs.
You could use a macro program to autofill the form. One such program is AutoHotkey. I am sure there is a more convenient way to do so. Of course, if you use autohotkey you should use the autowriter as well which can be found using this Stack Overflow post: https://superuser.com/questions/229720/where-can-i-find-a-macro-recorder-for-autohotkey Best of luck!
Use the value. Like this:
<input type="text" name="something" value="value here">
In case of a textarea:
<textarea cols="5" rows="5">value here</textarea>

Pass data to other website search

Is there a way to search on www.qantas.com.au or other sites that don't use GET method, from my own form?
I mean something like this : http://site.com/search.php?data=myData
I don't want to return result on my webpage, I just want to send data with a href
Depending on the website, many forms may contain CSRF tokens intended to prevent this behavior (imagine if a third party site could 'submit' a form for you to another site, perhaps to trans fer money or write embarassing posts)
That said, for sites that don't implement this feature, it should be possible just to copy their form (from <form> to </form>) including the action="/their/website/controller" and method="POST" (if you want it posted)
If you want to design your own form that submits the same data, just make sure the input fields have a name="blah" the same as the form data value that you want to submit
AJAX is also an option if you dont want to use a form. (see http://api.jquery.com/jQuery.post/)

Using random name fields for input to fight spambots

I'm considering using random input names for registration form. It would be done this way:
User requests register form site.
Create random names for input fields and save them to user's session.
Render form and display it to the user.
I just wonder if that method gives me anything. If session driver is a cookie - it's
encrypted and secured in the best possible way using third party library which I consider as save enough. If user don't except cookies I can refuse registration.
To remove cookies as potential security risk I can store sessions in database. This seems more secure but also might overload the server(?).
My question is quite simple. Is there any sense to implement such feature?
The standard approach is to have a hidden text field. That is a field with type=text, but with CSS rules applied to it so that it's invisible.
markup:
<input type="text" name="put_some_innocuous_name_here" class="some_innocuous_css_class_name_here" value="" />
CSS:
input.some_innocuous_css_class_name_here {
display: none;
}
PHP:
if ((isset ($_POST ['put_some_innocuous_name_here']))
&& ($_POST ['put_some_innocuous_name_here'] != ''))
{
throw new Exception ('Suspected bot!');
}
The way this works is quite simple. A normal user will never see your hidden text field because CSS rules will keep it hidden. therefore a real user will never fill it out.
However, most spambots aren't aware of CSS. They just parse the form markup and they see a text field that appears to need filling out. So they fill the field out with some random data. Because a form field that should never be seen by a normal user has been filled out, this means you're probably dealing with a bot.
Don't use input type=hidden for this, because most spambots are smart enough to notice them and ignore them.
A little late but I have created an class file which does exactly what you need you can find it here.
You just need to pass the name of the form through a function example.
<input type="text" name="<?php echo $obj->DynamicName("fieldName")?>"/>
and once the form is submitted it will populate $_POST['fieldName'] with appropriate data as soon as you create its object.
Try checking the IP against known spammers lists, it's very effective. Good examples would be Botscout and Spambusted. I've tried both, and they reduced my spammer bot registrations.

PHP contact form: can I take the value of a span instead of an input?

I'm setting up a contact form, but I have some saved information in some spans (It's an ecommerce shopping basket) and the built in checkout is awful so we're just slapping together an easy solution: turn it into an email form and email us the order instead of losing customers.
Anyway, can I use the info in the span, taking the id or name or do I have to turn it into an input? And if I do, how can I disable the input field?
Example of code I want to take into the email is in this jsFiddle, I want the spans with name="ACTUAL PRICE" etc emailed. Is this possible?
Thanks :)
Maybe you want to use a hidden input field.
<input type="hidden" name="key" value="foobar" />
It is not displayed, but can be used to submit information with the form.
You'd be far better off using hidden form fields if possible. Else if the user has JS disabled you may run in to issues down the line. Rare but possible.

PHP and Barcode Scanners

If i have a website running php and apache, what do i need to be able to attach a scanner to it? How do i get the scanner to fill in a value on one of the webforms on my page?
I just did this for an application. It's actually simple. The scanner is just another input method and is, in fact, similar to a keyboard. When you scan the barcode the data is decoded by the scanner and sent to whatever application is waiting to receive it. In the case of a web-based application it would be a form, most likely with a textarea with focus. The data would then populate the textarea just as if someone had typed the barcode's data into it. The form is then submitted and processed normally.
Just make sure the textarea has focus or else the data will go either nowhere or to wherever focus is (which may be another form field or the address bar).
I have yet to figure how how to get the form to auto-submit upon the entry of the barcode data as the scanner does not send event information (i.e. submit) and special characters such as tab (\t) do not seem to work. (If anyone knows how to accomplish this I am very interested in knowing how it can be done).
For actually creating barcodes in PHP, you might want to have a look at:
http://www.mribti.com/barcode/
http://www.ashberg.de/php-barcode/
Usually, these scanners are equivalent to a keyboard input, so you just select the appropriate input point on the web page, scan, and then submit the form.
WASP makes a line of barcode scanners that simply plug into USB or PS/2 inputs and basically convert the barcode scanned into the characters, just like a user typed them using a keyboard. They have an FAQ and help videos that may be of assistance, too.
When designing your web app, depending on how users interact with it, you can use Javascript to move focus from one field to another so that a user can scan barcodes sequentially without having to click on the field where the characters go. (Similar to how some forms move focus as you type data with a known length, such as a zip code or phone number.)
You can try this:
I think this is the best way to integrate barcode in web application
using php.
integrating barcode scanner into php application?
I hope this link is usefull to all.
Using an autofucus input is the better way. You just have to make sure that you create a for and add autofocus to the input box. So each time a user scans any item, the form is automatically submitted. So just give the form an id and handle the data easily with jquery

Categories