Basically, I have an input field in my form that is set in the CSS to display: none and I was wondering if auto fill programs fill in hidden fields? I set the value of the field to time() on load and compare it to the time the form is submitted to tell if the user is a human or bot.
Here is my code for the hidden field:
<?php
$loadTime = time(); // Initial time that the page loads is checked against the time the form is submitted and if its too fast, its probably a bot
?>
<input type="text" name="loadTime" id="loadTime" value="<?php echo $loadTime ?>" maxlenght="50" />
Instead of a text input with display:none; you should use <input type="hidden" .../>. Like this auto fill programs won't modify its value. Another (and safer) option is storing the time value as a server variable so that it can't be modified
I was wondering if auto fill programs fill in hidden fields?
(EDIT: By hidden I thought that you were asking for this:
<input type="hidden"...
)
Answer is no. Also, I would remove that hidden field because somebody could manipulate that value. I would rather store that time data in session because it's stored on server and not on client's computer.
Even if auto filling fills the form, It won't be visible since it is set in CSS. If you want the text to become visible, change the class CSS while JavaScript changes / fills the input. You can do both filling text and change CSS both, at the same time, using JavaScript.
Related
How to bring the first input box value to second input box after clicks the confirm button and refreshing the page.
But I dont want to save the value in the database, I just want to bring the value from first input box to the second input box after clicks the confirm button and refreshing the page. The first input box value will show into the second input box.
After that, How should I pass the second input box value to another page?
You have also a js API for cookies, cache and local/session storage, as well as IndexedDB, so you can use JS.
But why you need to refresh the page?? You could just put this value in a second field with JS without refreshing the page.
If you need badly to refresh the page after form validation, you have all form data sent by POST or GET, use the corresponding variables $_POST or $_GET in PHP and then echo wherever you want.
Or another option, if you need this value to be accessible all over your site/project and you use Sessions, you could save this value in the $_SESSION variable.
There are a lot of possible solutions, everything depends on your needs and goals.
Put this into top of the file
$first_value = isset($_POST['first_input']) ? $_POST['first_input'] : "";
and this into the form
<form action="_white.php" method="POST">
<input type="text" name="first_input">
<button>Confirm</button>
<input type="text" name="second_input" value="<?php echo $first_value; ?>">
</form>
It works
I have a form that i want to filled up by the end user in few steps.
in the first step i want to let them fill Name,Address,Mobile number.
And when click next button i want to appear another part of the form to fill the other details such as upload a image .
i did research online,i found 2 articles useful,
One thing is about sessions and the other thing is about hidden fields.
In my opinion i think sessions are not a good way to use for form submitting.Because some browsers are might have disabled sessions.
So ill go with hidden fields.
In my database i have a unique id which is auto increment.What i want to do is to let user to submit a form.In the first step i want them to submit their name,addres,mobile number(In this time it is inserting data to the database- Only for couple of columns.) And in my database i have a field for upload a image.In the first step it gets a null value.I want to update that null value in the next step by getting a that id from the first step
Please give me the basic idea to start this.A little help much appreciated!
Thanks in advance
you can try like this:-
You can add a class on the input which you want to hide
<input type="text" name="example" class="inputHidden">
after that add style in your page like this
<style>
.inputHidden{
display:none;
}
</style>
If you're trying to place the form data into new, hidden inputs - take the initial input.
<input type="text" name="example">
On the next page add a hidden input.
<input type="hidden" name="exampleP2" value="<?php echo $_POST['example']; ?>">
You can get form submited data and use it in input hidden fileds
for e.g. in first form you have
name ,email etc fields
in other form you have more fields
here you can use <input type="hidden" name ="firstname">
and thus you can add as many as you want
I have a page with a single form, and a submit button.
What I'm trying to achieve is when some text is entered it's saved to the $_POST array and outputted below. However, what I then want to do is use the same form to then perform the same task (albeit different text), but ensure both/multiple values are saved.
I'm assuming the best way to achieve this would be to save them to an array as the page is reloaded; but i'm not sure where to start.
Thank you.
What you could do is make some hidden fields and init them with the data from the form,
wich has been edited the first time.
Then when it is posted for the second time you could use the values from the hidden fields and the new information from the normal fields
<input type="hidden" name="hiddenFieldName" value="<?php $_POST['normalFieldName'] ?>"
On this form, I have some input field and select boxes that should not be edited by some users.
However, I need those unable fields to be inserted anyway.
I'm thinking about passing those values to a hidden field (should this be done in js ?);
And submit the form by using those hidden fields instead.
Is this a good approach ? Please advice.
You can use hidden fields to pass the data in to your form, but bear in mind that if someone's planning mischief, they can edit the values with tools like Firebug and submit them anyway, so relying on hidden fields may lead to issues.
If you want to be properly secure, you'll have to do everything on the server side - check to see if the client has permission to access those fields when they submit the form. If they do, take the values they've submitted; otherwise, use default values stored in your PHP code instead.
Just put them in hidden field:
echo $form->hiddenField($model,'property');
Just use hidden feilds within your form, like so:
<input type="hidden" name="id" value="00001" />
No js is required.
I would go with disabled on checkboxes and maybe readonly on text fields. The thing is that you KNOW what value they should have when they are submited. So on server side you can just ignore them and use the value you have choosen. And ignore the data if someone is manipulating the post request.
I have a text field for documentation, which is working good. Now the problem is whenever user enters some new text into it. I need a date in format(dd.mm.yy), that should be attached to it automatically, with the time stamp.
For example, when the user first enters, "Problem with production". then clicks save then it should display as
19.10.10 16:39 "Problem with production".
After that if someone else changes the field and adds, "In development phase".
it should be 19.10.10 18:39 "Problem with production", 29.10.10 16:59 "In development phase".
While sumbitting the form, i am not able to track the text that is newly added. As i will get the complete text in post variables.
I found a dirty trick, placing some wierd character after saving the text. Now in my post variables, i will be able to differentiate what is the old text and what is newly added. Add current time stamp to the newly added one.
I would be glad if some one can suggest me a better procedure.
Thanks in advance!
Off the top of my head a couple of options:
(a) With JS - change trigger
Some javascript on the text field that triggers sets a value in a hidden form field. This field is posted back to PHP so it knows the text field may have changed (still can't tell if the user changed it then changed it back).
eg. JS trigger on field change.
<input type="text" name="textfield"
onChange="this.form["textfieldchanged"].value=1;" />
<input type="hidden" name="textfieldchanged" value="" />
(b) With PHP - change detect
Upon form submit check the current version of the field with the submitted version, if it's changed then store the new version.
eg. PHP compare
if ($_REQUEST["textfield"]!=$current_textfield) {
//...
}
In both cases, when actually storing the value, now just add a date from PHP.
code: final PHP piece
function storeText($text) {
$date=Date();
//Store $text+$date .. file, SQL, not sure what you're doing here.
}
You could also use JS to set a date on a hidden field when the text is updated (rather than a flag). This has the advantage that the local-system date is included with the form-submit (especially helpful if users are in different timezones) but has the disadvantage users could game your software by changing their local clock when they're submitting entries... imagine someone wanted to appear to have added text before someone else, they could just set their clock back - make the submit - set the clock to the correct time and carry on.
Not sure I quite follow - You could have a hidden field in the form which defaults to the date - it would then be submitted as a seperate post variable...
<form>
<input type='text' name='textfieldforcomments' />
<input type='hidden' name='datetracker' value='".date("d.m.y h.i")."'/>
</form>