Forums

Can onLoad data be used in onSubmit

chriso0258 20 Jul, 2015
Hello,

In my onLoad section I've retrieved the following information
Array
(
    [cont] => lists
    [ccname] => EastTransfer
    [act] => edit
    [gcb] => 3

    [0] => Array
        (
            [staff_id] => 5
            [bi_no] => bi01
            [name] => 
            [region_staff] => 2
        )
)


In my onSubmit section I have added the following custom code:

<?php
$form->data[location]['staff_id_loc'] = $form->data[0]['staff_id'];
?>

When I submit my form I get

    [location] => Array
        (
            [staff_id_loc] => 
        )


How do I pass onLoad data to my onSubmit data?

Thanks for your assistance.
GreyHead 20 Jul, 2015
Hi chriso0258,

Think of the Load and Submit events as separate spaces. The only data that is routinely passed between them is the names and values of the form inputs. The values can be entered by the user, or you can save them as the values of hidden or read-only inputs. The $form->data array is created in both places but data is not preserved between the two.

In this case you could add a set of form inputs like name="['0']['staff_id']" etc.; or you could collapse the data using json_encode in a Custom Code action and pass it all in one variable.

OR you can save the data to the user session - a block of temporary storage that Joomla! assigns to the User while they are on the site. Data saved in the session is preserved over time until the session expires. ChronoForms has Data to Session and Session to Data actions that will handle that (but take care not to over-write any user-submitted data).

OR you can look this data up in the On Submit event after the form is submitted. You presumably will need to pass some kind of a record identifier - that is easily done with a hidden input.

Bob
chriso0258 29 Jul, 2015
Hello Bob,

If I understand you correctly, I could use a hidden field in the designer view? If so, I've tried the following in the field name:
[code]location[staff_id[/code] but I'm not sure what to put in the Extra params box. This hidden field box is configured a little differently than when I used CFv4.

Thanks for you help.
chriso0258 29 Jul, 2015
Answer
Hello again,

I resolved my problem. Turns out I could use one of Joomla's tables instead of creating one of my own.

Thanks for your input.
This topic is locked and no more replies can be posted.