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>
Related
My question, it´s very short.
is it possible to detect the kind of types we send as POST from a form?
If I have some fields and one field for each input type as text, the other textarea, the other file, etc, is it possible to use Php to detect, in each case, the type from these fields.
<form method="post">
<input type="text" name="test1" value="ok">
<textarea name="text2"></textarea>
<input type="file" name="test3" value="ok">
</form>
And finally determine whether the type is text, textarea, file, etc
I know it´s possible with Jquery buy i don´t find nothing about this with php.
Thank´s for the help in advanced
No, request contains only key-value pairs. But you can add additional hidden fields that passes these data. i.e. (for larger forms I's suggest it automaticaly with JS):
<input type="hidden" name="text2_type" value="textarea">
<input type="hidden" name="test3_type" value="file">
or
<input type="hidden" name="types[text2]" value="textarea">
<input type="hidden" name="types[test3]" value="file">
Other solution
Also you can just introduce naming convention for your fields, i.e.:
<textarea name="text2_textarea"></textarea>
or
<textarea name="textarea[text2]"></textarea>
so in your PHP you can check if key ends with _texteraea or is in array $_POST['textarea'] to determine the type o field.
I am trying to grey out a form field in HTML such that the user cannot edit it, as it will be pre-populated. This is the code section with the issue:
<div class="element-input"><label class="title">Name</label><input value="<?php echo $data ?>" class="large" type="text" name="name" disabled/></div>
and when I render this in the browser, I see that it is pre-populated as planned and I cannot edit it, but when I submit it to the Database, it works and all values are inserted into the db except for the "name" which I suspect is due to the disabled attribute.
Is there anyway, that I can prevent the User from editing the field/grey it out and still have it inserted into the DB?
Simply add the readonly attribute:
<div class="element-input">
<label class="title">Name</label>
<input value="<?php echo $data ?>" class="large" type="text" name="name" readonly />
</div>
A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).
By the way, sometimes it's handy to make a field readonly, and then remove the attribute with javaScript when some other condition is met.
I am using the "placeholder" attribute in HTML5. I use it in a PHP web page with an HTML section. It works as expected.
Here is my code (it was modified slightly from the w3schools website):
<!DOCTYPE html>
<html>
<body>
<form action="/nextpage.php">
<input type="text" name="firstname" placeholder="John"><br>
<input type="text" name="lastname" placeholder="Doe"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
As a user with the web page I tried using a form with the placeholder element and I clicked submit, but it acts like the field is empty if I do not change the default text that appears in light gray.
I want the text to be real -- and not act as though the field is empty. If the user changes the placeholder text in the fields, then that is fine. But if the user does not touch the placeholder text, I want the "Submit" click to ingest the placeholder text as if the user typed it in manually. How do I do this? I tried a variety of different things, but I cannot get it to work. The text could appear black -- but this does not matter. I want the text to be in the field if the user does not delete it or change it.
Also set the "value" param
<input type="text" name="firstname" placeholder="John" value="John">
It will have the user delete the placeholder but if nothing is changed then it is sent
Change placeholder to value
<!DOCTYPE html>
<html>
<body>
<form action="/nextpage.php">
<input type="text" name="firstname" value="John"><br>
<input type="text" name="lastname" value="Doe"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<script>
$("#firstname").on("click", function() {
$(this).val("")
});
$("#lastname").on("click", function() {
$(this).val("")
});
</script>
working jsfiddle : http://jsfiddle.net/Yu97Z/291/
A good approach to handling this type of thing is to provide the field with a default value when the page is loaded. For example:
<input type="text" name="firstname" value="John" placeholder="John">
That will pre-populate "John" in the input field making it so the user would not have to modify it if they chose not too. Perhaps then it would also make sense for placeholder to read something like "First Name", should someone remove the text altogether.
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.
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.