• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Set Hidden field Value to Existing Field Value

Set Hidden field Value to Existing Field Value 3 years 8 months ago #41464

  • seowwee7
  • seowwee7's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Hi,

How can i set a Hidden field value to a string of concatenation of an existing Text field value and date timestamp, BEFORE the Submit button is clicked?

Example of my form:
Name = Johnny (this is input by user)
Hidden field = Johnny_2021-08-14-11-24 (Default value)

I tried to code this in Default Value of the Hidden field, but the name is blank.

//<code>
return $_POST['form'] ['Name'] . '_' . date("Y-m-d");
//</code>

Thank you.
Last Edit: 3 years 8 months ago by seowwee7. Reason: Some codes with [ ] are not appearing correctly.
The administrator has disabled public write access.

Set Hidden field Value to Existing Field Value 3 years 8 months ago #41469

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 246
  • Thank you received: 64
This works on two text fields 'name' and 'name2'

In the CSS and Javascript section of your form add
<script>
function populate(){
document.getElementById('name2').value = document.getElementById('name').value;
}
</script>

Then assuming you want to set the value of 'name2' to the users input value in 'name' in the latter under attributes - additional attributes add
onchange="populate()";

That will get the user input into your second field, now all you need is to work out how to contact the date about which I admit I have no idea
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 3 years 8 months ago by iceferret.
The administrator has disabled public write access.

Set Hidden field Value to Existing Field Value 3 years 8 months ago #41470

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 246
  • Thank you received: 64
So I got a cup of strong coffee and for my own curiosity did some research, so amend the function to
<script type="text/javascript">
function changeVal(){ 
document.getElementById("name2").value=document.getElementById("name");
}
</script>
 
<script>
function populate(){
  var today = new Date();
  var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
  var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  var dateTime = date+' '+time;
  var firstField = document.getElementById('name').value;
  var hiddenField = firstField + '_' + dateTime;
  document.getElementById('name2').value = hiddenField;
}
</script>

Works for me and I admit I'm rather chuffed about that. Obviously you'll have to change 'name' and 'name2' to your own field names
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 3 years 8 months ago by iceferret.
The administrator has disabled public write access.
The following user(s) said Thank You: gregs

Set Hidden field Value to Existing Field Value 3 years 8 months ago #41471

  • seowwee7
  • seowwee7's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Hi iceferret,

Thanks for your help! You have solved my problem.

You are so cool! B)
The administrator has disabled public write access.

Set Hidden field Value to Existing Field Value 3 years 8 months ago #41472

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 246
  • Thank you received: 64
No problem, and i learned something new today as well :woohoo:
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Set Hidden field Value to Existing Field Value 3 years 8 months ago #41478

  • qubertman
  • qubertman's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 15
  • Thank you received: 5
Here is another solution on the server side. Go to PHP Scripts > Script called on form process and add the following code:
$_POST['form']['HiddenField'] = $_POST['form']['Name'] . '_' . date("Y-m-d");
Last Edit: 3 years 8 months ago by qubertman. Reason: add space
The administrator has disabled public write access.
The following user(s) said Thank You: seowwee7

Set Hidden field Value to Existing Field Value 3 years 8 months ago #41479

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 246
  • Thank you received: 64
Yes, that will work but the OP asked fir the hidden field to be filled before the submit Button was clicked and the form processed
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.
The following user(s) said Thank You: seowwee7
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!