Buy Now
Sign in

How to combine three fields in one? Day/Month/Year

indiana71 , August 04 at 07:10
I
indiana71
Hi Bob,
I create a form with tree combo fields, one for day, one for month, one for year.
I used this solution because I had some issue on mobile.
Now my problem is... how to combine the three field in one named "birthday" that will be saved on db?
In PHP I can use a solution like that, but how in chronoform?
$birthday = $year . "-" . $month . "-" . $day;
GreyHead
Hi indiana71,
You can use a PHP action in the form On Submit event to create a new data item. Pleaes see page 34 of the CFv6 manual.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
I
indiana71
Thanks, and to save it on db?
Can I use an hidden field? and mark the single one as "no save", "no email"?
GreyHead
Hi indiana71,
Once you have added 'birthday' to the form data you can save it with a Save Data action like any other form data.
Can I use an hidden field? and mark the single one as "no save", "no email"?
Sorry, I don't understand what you are asking here :-(
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
I
indiana71
Thanks Bob. Don't care for the second question. You just answer me!
Meanwhile I used another solution. I don't know if it is less efficient, but it works.
I left here for some other people that need it.
I put a Javascript and a custom hidden field named "birthday" on my form.
Inside Javascript (flagged 'Add Inside domready event') I put this code:
$("#birthday,#birthmonth,#birthyear").on("change", function(){​
​ $("#datebirth").val( $("#birthyear").val() + "-" + $("#birthmonth").val() + "-" + $("#birthday").val() );​
​});
#birthday and #birthmonth are two combo fields with values (01, 02, 03, ...10, 11...)
#birthyear is another combo that recall a php function in setup section
{var:latest_100_years}
developed as follow:
$years = array_combine(range(date("Y"), 1900), range(date("Y"), 1900));​
​return $years;
GreyHead
Hi indiana71,
Using JavaScript is good too.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
healyhatman
OR just put the following in your save data action
birthday:{data:birthyear}-{data:birthmonth}-{data:birthday}
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
I
indiana71
Hi Bob,
I used Javascript solution for a long but sometime data field save on db blank. I think that some browser don't work javascript well.
Now I'm trying to switch to PHP solution.
I use review page before submit to database.
On review page I can view datas. I added the following PHP code on review and it work
/*​
​$this->data['datebirth'] = $this->data['birthyear'] . "-" . $this->data['birthmonth'] . "-" . $this->data['birthday'];​
​$this->data['passportissue'] = $this->data['pass_whenIssuedYear'] . "-" . $this->data['pass_whenIssuedMonth'] . "-" . $this->data['pass_whenIssuedDay'];​
​$this->data['passportexpiry'] = $this->data['pass_expirationYear'] . "-" . $this->data['pass_expirationMonth'] . "-" . $this->data['pass_expirationDay'];​
​*/​
​​
​​
​$this->data("datebirth", $this->data['birthyear'] . "-" . $this->data['birthmonth'] . "-" . $this->data['birthday'], true);​
​$this->data("passportissue", $this->data['pass_whenIssuedYear'] . "-" . $this->data['pass_whenIssuedMonth'] . "-" . $this->data['pass_whenIssuedDay'], true);​
​$this->data("passportexpiry", $this->data['pass_expirationYear'] . "-" . $this->data['pass_expirationMonth'] . "-" . $this->data['pass_expirationDay'], true);​
On submit page I lost datebirth, passportissue and passportexpiry.
I tryed also to insert
birthday:{data:birthyear}-{data:birthmonth}-{data:birthday}
into savedata action, but nothing!
Data wont save on DB.
Help!
healyhatman
What does the {debug:} say?
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
I
indiana71
Data empty..​
​​
​I found the solution, I hope.​
​Passing through a form to another I need to fill again the data fields. The system lost them.​
​​
​​
​So I added another PHP Action with same code of review page to submit page.
healyhatman
You should be using the multi page action
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
I
indiana71
Multipage I've use....
healyhatman
Then unless you tick the mix with data button, you need to use {session.multipage:field}
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman