Forums

Chronoforms for data enrty with part common data

wallyhowe 10 Dec, 2013
I am trying to use Chronoforms for entering a number of records by reloading the form after DB save. Having prepared the first record using dynamic data there are some fields (e.g. a reference number)that are then common to all the next records I am inputting. My problem having tried using multi form and also data to session/session to data is when the form is reloaded in the 'Show HLML' then either all fields are empty (Reload data 'NO') or all are filled in (Relaod data 'Yes'. I cannot seem to find a way of preserving the odd field .
I am sure I am missing something fundamental or alternatively am looking at my requirement in the wrong way.
Any advice greatly received.
GreyHead 11 Dec, 2013
1 Likes
Hi WallyHowe,

If you need to make some of the form data temporarily 'sticky' you can save it separately in the user session (or in a cookie). Here's an example using a cookie*:
On Submit, save two values:
<?php
$app = JFactory::getApplication();
$app->input->cookie->set('eco_ipad_survey', $form->data['survey'], time()+60*60*24*30 );
$app->input->cookie->set('eco_ipad_hv_id', $form->data['hv_id'], time()+60*60*24*30 );
?>

On Load, recover them again:
<?php
$app = JFactory::getApplication();
$form->data['survey'] = $app->input->cookie->getString('eco_ipad_survey', '');
$form->data['hv_id'] = $app->input->cookie->getString('eco_ipad_hv_id', '')
?>


and the same thing using the User Session. On Submit:
<?php
$session = JFactory::getSession();
$session->set('eco_ipad_survey', $form->data['survey'] );
$session->set('eco_ipad_hv_id', $form->data['hv_id'] );
?>

On Load:
<?php
$session = JFactory::getSession();
$form->data['survey'] = $session->get('eco_ipad_survey', '' );
$form->data['hv_id'] = $session->set('eco_ipad_hv_id', '' );
?>

The difference is that the cookie data is preserved for longer (30 days in this case) but you may require to set a cookie policy and get permission to use them; session data only lasts through the current user session - until there is 15 minutes with no further actions is the Joomla! default setting.

Bob
wallyhowe 11 Dec, 2013
Hi Bob

Works a treat first time then fields disappears again on the next iteration.

Also I have tried rewriting the values back into the session data before the next passoff and that does not seem to work.

Is there something I am missing for multi iterations of a form?

Really appreciate the help you are giving.

Wally
wallyhowe 11 Dec, 2013
Scrub the above. It is not working on the first iteration when i look on the database.
Am investigating.
Wally
wallyhowe 11 Dec, 2013
I have the session passing of the sticky field working so the field value gets passed across but the field is not written into the database record on the DB load event.
I have tried it with both the field hidden and unhidden and it makes no difference.
Debugger lists the field and its value and the field name matches the database column (in fact I regenerated the table to make sure).
Is there something else to get the form to recognise this as part of the input as it was not part of the POST submission.
I notice from the debugger that the field is properly set in the main array but is blank in the [chronoform_data] => Array array.
How do I get the value across to there?
Wally
wallyhowe 11 Dec, 2013
I have worked out a way to do it.
Along with passing the sticky field across in session data I set 'republish form data' to 'Yes'in the Show HTML action. Then I unset the form data prior to the data to session. On the next form load I reload the sticky field value from session data and thats it.
Still puzzled why the settings of Yes and No make such a difference on the 'Republish form data on SHOW HTML.
Thanks for your help, Bob.
Wally
GreyHead 23 Dec, 2013
Hi wallyhowe,

Very late reply here :-)

I'm not sure why republishing makes a significant difference here. What it does is to turn on (or off) a search and replace in the Form HTML that tries to find and set the values of any inputs in the form HTML with corresponding values in the $form->data array (which holds any data from the session, URL and post data from a preceding form if there was one.

Bob
This topic is locked and no more replies can be posted.