Date contact form database
Author: Nicole B.
Visited 933,
Followers 1,
Shared 0
How can i get the date to auto populate in the database, instead of having the date being enter manually on the contact form. I want to remove the date from the form but have it auto populate in the database.
Posted on the
You can first use Javascript to insert the date automaticly into the date input field and then use CSS code to hide the date input field so that it is invisible in the browser.
----- Instructions -----
Under ...
3 Sitemap
... mark the page with the contact form and click on “Properties” at the top, then click on the “Advanced” tab.
Here at...
Custom code:
Before the </HEAD> tag
<style>
#imObjectForm_29_4 { display: none; }
</style>
... CSS code was entered and then at ...
Custom code:
Before the </BODY> tag
<script type="text/javascript">
document.getElementById("imObjectForm_29_4").readOnly = true;
document.getElementById("imObjectForm_29_4").value = new Date().toLocaleString('en-EN');
</script>
... Javascript code was entered, see also in the screenshots below.
However, the number _29_4 must first be determined from the source code of the page with the contact form, as this number varies from user to user.
The Javascript and CSS experts can check the code and possibly make suggestions for improvements or offer their own code.
I haven't tested it with the database, but in the Browser, see screenshots below
-----
-----
----- With javascript code -----
----- With javascript and css code -----
Unfortunately, I can't test the form on my test page because the submit button doesn't seem to respond to mouse clicks.
If I can't find a solution to this problem, then we'll have to wait for the experts.
Now I see that the message above says that the date is not in the correct format, so I would have to find the javascript code that shortens the date with time to the date.
The Javascript experts will probably have to take care of this part.
There is a change in CSS code
<style>
div#imObjectForm_29_4_container { display: none; }
</style>
-----
It is maybe better to add an extra field to the table.
This field can be set to automatic set the date + time when the record is created.
It's worked out
-----
-----
The numbers _21_1 are for my website and must be adjusted by other users, see the source code of the form page.
----- CSS code >> Before the </HEAD> tag -----
<style>
div#imObjectForm_21_1_container { display: none; }
</style>
----- Javascript code >> Before the </BODY> tag----
<script type="text/javascript">
document.getElementById("imObjectForm_21_1").readOnly = true;
var date10 = new Date();
var options = { day: '2-digit', month: '2-digit', year: 'numeric' };
document.getElementById("imObjectForm_21_1").value = date10.toLocaleString('de-DE', options);
</script>
----- Screenshots -----
-----
-----
Find the personal number in the source code of the form page.
-----
My test page with date format en-US also works.
The numbers _29_4 are for my website and must be adjusted by other users, see the source code of the form page.
----- CSS code >> Before the </HEAD> tag -----
<style>
div#imObjectForm_29_4_container { display: none; }
</style>
----- Javascript code >> Before the </BODY> tag ----
<script type="text/javascript">
document.getElementById("imObjectForm_29_4").readOnly = true;
var date10 = new Date();
var options = { month: '2-digit', day: '2-digit', year: 'numeric' };
document.getElementById("imObjectForm_29_4").value = date10.toLocaleString('en-US', options);
</script>
-----
Author
Thanks Daniel, but do i remove the date field from the form? I tried to play with the database but my date comes up as zeros
Author
Nevermind Daniel old site was showing. The date field is no longer showing BUT I cant submit the form. I click send and nothing happens
The date input field must remain in the contact form because the Javascript code has to write the date into this input field in the background.
The CSS code ensures that the date input field is not visible in the contact form on the website.
If the send button doesn't work, it's probably because the Javascript code wasn't executed and no date was written into the date entry field, perhaps the Javascript code was inserted in the wrong place. So scroll up and you should see an error message about the missing date.
The Javascript code must be error-free and also inserted in the correct place.
In addition, the personal number from the source text must also be in both codes, otherwise both codes cannot work.
With normal text, errors aren't a problem, but with code, it can make the difference between working and not working.
I have included many screenshots in my instructions so that it is clear what is entered where and how.
Post the link to the contact form page so that I or the moderators can check that everything is entered correctly.
Author
https://rhs94alum.org/registration.html
When I delete the CSS make invisible directive using the browser tool, the input field shows the date so the javascript works.
-----
The form is not sent because... - see screenshot
-----
My test page
-----
Author
I didnt have the dateformat correct as your test page. You are totally awesome Daniel. You should be on staff, not just a user.