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>
Related
I am making a basic post-box management system in PHP. the postman can add 2 inputs which are 'delivered by' and 'item number'. and a button for the postman to click to submit the inputs.
Now, when the submit button is clicked, I want PHP to record the date and time of when the inputs are being submitted (so that later on I can set a mechanism to track the item duration and see how long an item has been in the box-but this is not part of the question). How do I do that?
sorry I have just started learning PHP so my current code is still very basic, and I haven't start with the Box-function.php page yet:
The HTML page:
<form method="post" action="Box-function.php">
Delivered by : <input type="text" name="Delivered-by"> <br>
Item No : <input type="text" name="Item-no"> <br>
<input type = "submit">
</form>
Note: I have seen similar questions but those questions involve using MySQL while I am not using it. it's just pure PHP and HTML.
In the box-function.php page, you can get the current date and store it along with the other data.
Getting current date
Do the same when the order is delivered. The difference between the two times will tell you how long the package took to be delivered.
Also, as the comments under your post say, you will have to store the data somewhere. You can't retrieve it later if it isn't stored anywhere.
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.
I'm building a virtual tour application and have hit a bit of a stumbling block during the setup process. Currently, the administrator is the one responsible for determining which stop belongs to which panorama as well as the choices for the next move. In order to complete this, I need to be able to insert the photo name into the database along with the other information of the current stop.
My form solution was to add the photo names of a certain directory into an array, count the number of images in the folder, and create the corresponding number of mini-forms on the page. Each form has its own save button that works via ajax, so all information is updated as the user works through the stops.
My issue has to do with adding the photo name via the submit process. The photo itself is not a user-defined field in the form, and I'm using POST to pass the variables to the insert function. Is there a way to include the filename in the $_POST array just before submission?
what you have to do its use a hidden input with the filename in the value attribute.
<input type="hidden" name="filename" value="the filename" />
also, you can add the filename as a parameter in the ajax call, but i think that the input its cleaner.
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.
I am creating a site in PHP while storing my date in a MySQL database. I have already created my sign-up, login, logout portions, but I would like to make things more user friendly and add an area where people can change their user settings. Some of the settings that I would like for the user to be able to modify are as follows:
full name
email
age
gender
etc.
That being said, I would like for them to be able to fill out only the portions of a form that they would like to update. They should be able to leave everything else unchanged and submit all of their changes with a single submit button.
Any suggestions as to the best way to approach this problem are greatly appreciated.
As a side, I would eventually like for this site to contain AJAX (where the user might be able to select individual settings and change them at will), so if your solutions take that into consideration, that would be great.
EDIT:
Sorry, but I should have mentioned that I want to keep the information from being shown to the user (i.e. displayed in the text field) unless they explicitly type in there. As far as I can tell, this would keep me from always posting all of the data every time.
I have a great way of achieving this. Just simply do some if/else coding in php. Like this--
Html Code:
<form action="settings.php" method="POST">
<input type="text" name="full name" />
<input type="text" name="email" />
........ (and more)
</form>
And PHP code ---
<?php
if($_POST)
{
if(isset($_POST['full name'])) { //Update full name of user and redirect to the settings page on success. }
else { //Redirect and show errors! }
if(isset($_POST['email'])) { //Update email of user and redirect to the settings page on success. }
else { //Redirect and show errors! }
}
?>
Or you can use array function of PHP to set the MySql queries in it like ---
<?php
mysql_query("
UPDATE table name SET
//Loading different values from the array using foreach() php function.
");
?>
Just try to do some modifications in it.
Hope this helps you.
Your choices are:
1) multi-stage edit process. 1. pick fields to change. 2. present fields for editing. 3. save updated data. Rather tedious
2) present all the fields in a form, but use some Javascript to keep track of which ones were changed and submit only those
3). present all the fields in a form, and update all the fields in the database. if one or more weren't changed, the update is a null-operation anyways.
3)'s easiest to implement. 2)'s dependent on javascript. 1)'s tedious for you and even more tedious for the user.
As long as you do proper validation on all the fields, I don't see how #3 is anything but the most logical choice.
Create a edit.php or something else. Create textfields which one you want to edit.
All information could be showed thats related with the unique id of a user.
input type='text' value='"Example: Select * from users WHERE id = '$userid'"' name'Example: Update_name'
Do this for all the field you want to edit. After creating this edit.php. Use a script to update the $_POST or $_GET user details. Based on this easy to use script you've got a edit function for a user.