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.
Related
Can you all help me with the approach I need to take once the user has submitted his data, I want those certain fields to be read-only permanently for that user upon submit.
So far I am able to save the data to MYSQL DB on submit and the below code also keeps the data in the field. But on refresh, the data in the form field disappears. How do I solve this? Any help and suggestions are greatly appreciated. Thank you.
<label class="control-label col-sm-2" for="lname">Last Name*</label>
<input type="text" class="form-control" id="lastname" placeholder="Last
Name" name="lastname" value="<?php if(isset($_POST['lastname'])) {echo
htmlentities($_POST['lastname']);}?>" autocomplete="nope" required/>
it should look like this each time the user login.
Its very simple just add readonly into your input filed.
<input type='text' value='Test' id='test1' readonly>
do one thing in your database table keep a field for flag and then set a value for it like Active or Deactive then at the time of submitting the data check the user is exist or not if exist then do disable to the input fields like
SELECT * FROM users WHERE status LIKE 'Active';
execute this query accordingly u set the input fields readonly
You might need javascript to do the trick. The trigger being clicking the submit button and change the readonly attribute to true as shown below.
jQuery <1.9
$('#relevantId').attr('readonly', true);
jQuery 1.9+
$('#relevantId').prop('readonly', true);
I have a a page where users create and account and edit password if the account already exists. I'm using php - codeigniter
When users update passwords, the input field currently allows them to change their username as well as their password. I'm trying to make it so that users can only update passwords and not usernames but I have had trouble doing so.
This is my code
<input required type="text"
placeholder="page name"
value="<?= $form_value['name'] ?>" name="name" id="name">
I am trying to make it so that the username is printed but it is not updated.
The only thing I can think of is making the input type hidden (as shown in the below code), but then users can minipulate it and change it in the inspect element option of the browser and update their users.
<input required type="hidden" placeholder="page name" value="<?= $form_value['name'] ?>" name="name" id="name">
I am not sure what to do,
Thanks in advance
use should echo your php variable to get its value inside your html input element
<input required type="text" placeholder="page name" value="<?= echo $form_value['name']; ?>" name="name" id="name">
in the above syntax you are using php shorthand syntax, so you should enable it first. you can use like this also without short tags
<input required type="text" placeholder="page name" value="<?php echo $form_value['name']; ?>" name="name" id="name">
I assume you're using a database to store this information. If that is the case - just don't update the username field when you are updating the password. There are many cases where the user could go into inspect element and change things, but all that matters is what you're doing on the back-end.
Just echo the plain username without input field (if user is logged in) & empty input field (for new user registration), while update take the user_id from session & update the respective password of the logged in user.
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 have a registration form. If a user fill out all the required fields.
And when he reloads the page with out submitting form, the fields contain the values entered by the user. I want them to be empty as they were on first page load.
I have given value="" to the fields but they still contain the previously entered values.
<form id="registration_form" name="registration_form" method="post">
<input name="first_name" id="first_name" value="">
<input name="last_name" id="last_name" value="">
<input name="user_email" id="user_email" value="">
<input name="status" id="status" type="hidden" value="active">
</form>
This is form auto-fill, not page caching. You can disable autocomplete with:
<form id="registration_form" name="registration_form" method="post" autocomplete="off">
Remember to add autocomplete="off" to your form. This is auto-complete issue with some browsers, then you need to use id trick, every time you're loading the registration page, let say:
http://localhost/register.php
you can try it manually to see if it's works for browsers you've been testing, for example load this address on your browser and see if it still auto complete the form:
http://localhost/register.php?id=23
you can add id=anynumber, this happens to work perfectly, I do this with my CSS imports. To make it more PHP you can write some code like this:
$number = rand(1,100);
header("Location: register.php?id=$number");
Hope it helps
If you want to remove cache as you asked first (before edit), There are many ways,
Adding meta tag on page
<meta http-equiv="Cache-control" content="no-cache">
By redirecting using javascript,
window.location.href+'?eraseCache=true';
These are discussed in an other topic here.
If you just want to delete the values on the fields,
use
document.getElementById('text_box_id').value="";
on the top inside the head tag.
I Have a simple html/php form on my page and i was wondering how can i add a prefix to one of the fields?
Example: if a field acts as email field, i need to have a grey prefix like "example#example.com" and dissapear when i write the email.
Is it possible?
My Form
The field i need prefix on:
<div class="form-field">
<div class="form-field-name"><b>Facebook profile</b></div>
<input type="text" name="fields[Facebook]" class="required size_half"/>
</div>
Assuming you actually mean 'placeholder', you can use the placeholder attribute with modern browsers. For example:
<input placeholder="Facebook name" type="text" name="fields[Facebook]" class="required size_half"/>
There are plenty of jQuery plugins to fix this on older browsers, for example:
http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html