Forums

Using previously entered data in the same form

alex_1234 09 Jun, 2014
Hi,
I'm trying to use data entered on a previous page of the same form to
a) display it in text using custom code (eg "tell us more about {company_name}).

b ) Each page saves to a different table and I want to copy some data from one table to another by putting it in the field value of a hidden field (eg copy company_name to table2_companyname)


I've followed the instructions here & here .

I've tried using the formats:
company_name
  {company_name}
$form->data[company_name]
 $form->data['company_name'] 

I've checked spelling and tested with different forms or different variables without success - all of them just display/save the exact text I entered not replacing it with the name.

However, using {company_name} when sending an email to myself works fine. And the company_name field is saved in my database OK, and it displays fine when I use debug or custom code with
<?php
pr($form->data);
?>  


Any suggestions? (sorry to ask so many questions!)

Thanks🙂

Alex
GreyHead 09 Jun, 2014
1 Likes
Hi Alex,

I can't follow exactly what you need to do here. If you need to pass data between form pages you can use the Multi Page action in the Utilities action Group. If you need to pass data between forms then the Data to Session and Session to Data actions in the Sessions action group should do that.

If the data is in the $form->data array then you can output it with {input_name} in HTML or with echo $form->data['input_name']; in PHP.

Bob

PS Saving the same data into different database tables is usually a sign of a poor design. Better to save it once and then link the records so that you can recover it when needed (or combine the tables).
alex_1234 10 Jun, 2014
Hi Bob,

thanks for the reply.

The problem is I can't get using data from previous pages to display properly following the html instructions or the php instructions it just displays the string as I type it (eg it prints "{input_name}" rather than replacing that with the actual input name) .

For the database thing I'm just trying to copy a primary key into each of the later tables so I can link them, again I can't get the php or html to use a previously entered field to work properly.

Thanks
Alex
GreyHead 10 Jun, 2014
Hi Alex,

Yes . . .

How are you passing the data between pages?

What exactly is the code you are testing?

What do you see when you add a debugger action?

Bob
alex_1234 10 Jun, 2014
Hi Bob,

1) Using the multi-page action in 'setup'

2) a) in 'custom action' in designer, with the code
Tell us more about {company_name}

b) Using
{id}
as the field value in a hidden field.

3)
Data Array

Array
(
    [option] => com_chronoforms5
    [chronoform] => new_record
    [event] => page2titles
    [company_name] => Test company 1
    [company_type] => Education (college, uni, etc)
    [company_keywords] => 
    [company_website] => 
    [company_phone] => 
    [company_email] => 
    [Enter_address_data?] => 0
    [company_address1] => 
    [company_address2] => 
    [company_city] => 
    [company_postcode] => 
    [button1] => Save and continue
    [id] => 45
)

Array
(
)

Errors

Array
(
)

Debug Info

Array
(
    [17] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `nb_company` (`company_name`, `company_type`, `company_keywords`, `company_website`, `company_phone`, `company_email`, `company_address1`, `company_address2`, `company_city`, `company_postcode`, `user_id`, `created`) values ('Test company 1', 'Education (college, uni, etc)', '', '', '', '', '', '', '', '', '0', '2014-06-10 10:01:09');
                        )

                )

        )

)



Thanks

Alex
Max_admin 11 Jun, 2014
1 Likes
The custom code action will not replace the {field_name}, you should use the "display message" action instead!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
alex_1234 12 Jun, 2014
Ah that works for the display, thanks.

Is there any way to save the same data to two different fields (in different tables) I've tried

<?php 
 $unique = uniqid();
$form->data['company_companyid'] = $unique;
$form->data['title_companyid'] = $form->data['company_companyid'];
?>


but title_companyid just saves the word "$unique" rather than the actual numbers.

Thanks so much for all your help both of you.
GreyHead 12 Jun, 2014
Answer
1 Likes
Hi Alex,

I don't see why you would get '$unique' from that code :-(

Please try
<?php
$unique = uniqid();
$form->data['company_companyid'] = $unique;
$form->data['title_companyid']   = $unique;
?>

Bob
alex_1234 12 Jun, 2014
Yes that works🙂 thanks
This topic is locked and no more replies can be posted.