Write an inverted number in the DB with ChronoForms

webmidia 06 Jun, 2016
Bob,

How do I write an inverted number in the DB with Chronoforms?
Fields form of ex .:
- Name: Mary Hart
- Functional ID: 123456789
- Code: 9876654321 (field hidden)
- (...)

The "Code" field would be "hidden" with the reversed number field "Functional ID".
Coo I do that with PHP or JavaScript?
GreyHead 07 Jun, 2016
Hi webmidia,

Please see the PHP docs here

Bob
webmidia 07 Jun, 2016
Grateful Bob.

How do I implement this in CF?
How do I run the reversal after typing in "Functional ID"? (JS onload?)
I'll need to send "Code" for that user.

Awaiting return.
Thanks.
GreyHead 07 Jun, 2016
Hi webmidia,

If the name of the input with the Functional ID is say functional_id, then you can add a Custom Code action to the form On Submit event with PHP like this
<?php
$form->data['code'] = strrev($form->data['functional_id']);
?>

Bob
webmidia 07 Jun, 2016
Bob,

I found that I need to show the inversion before recording.
I'll use JavaScript (onBlur) in the "Functional ID" field to include the inverted value in the "Code" field.
What do you think?
I will test now.

Thanks.
webmidia 08 Jun, 2016
Dear Bob,

Resolve with JS.
Below tested script:


<!DOCTYPE html>
<html>
<body>

Functional ID: <input type="text" id="functional_id" onblur="ReversedCode()" />
<br />
Code: <input type="text" id="code" disabled="disabled" />

<script type="text/javascript">

function ReversedCode() {

   var x = document.getElementById("functional_id").value;

   if( x !== "" ) {

      var reversed = "";
      for (var i = x.length - 1; i >= 0; i--) {
         reversed += x[i];
      }
      document.getElementById('code').value = reversed;

   } else {

      document.getElementById("functional_id").focus();
   }
}

</script>

</body>
</html>


I hope others enjoy.
Thanks.
This topic is locked and no more replies can be posted.