can not access form array

rocknroad 18 Oct, 2010
I have multipage form. First page is an order form, second one is a summary of the entered data. The first form inludes some text inputs like this:


<input type="text" value="0" name="produkt[myproduct1]" class="cf_inputbox">
<input type="text" value="0" name="produkt[myproduct2]" class="cf_inputbox">


at the summary page, i want to access this via a foreach:

foreach($_POST["produkt"] as $item){
  echo $item;
}


But this does not work because $_POST["produkt"] is no longer an array. var_dump claims it as a string containing the comma seperated values of the inputs. The ChronoForms debug output displays it still as an array.

Itried to access the variable via JRequest::get('post') or JRequest::getVar('produkt', '', 'post') but its always a string.

Is it ChronoForms or a Jommla issue? Or do access the variables the wrong way?
rocknroad 18 Oct, 2010
Another example:

The text fields:

<input type="text" value="test1" name="test[t1]" class="cf_inputbox">
<input type="text" value="test2" name="test[t2]" class="cf_inputbox">


The Chronoform debug output (thats what i expected):
[test] => Array ( [t1] => test1 [t2] => test2 ) 


The var_dump(JRequest::get('post')); output:
["test"]=>  string(12) "test1, test2" 
GreyHead 19 Oct, 2010
Hi rocknroad,

You probably have "ChronoForms handle my posted arrays" set to 'Yes' in the Form General tab; this will have exactly that effect. It's there to prevent problems saving arrays in the database.

You can turn it off, or re-explode the string into an array again.

The multi-page plug-in makes the previous data available to you in an array from the user session:
<?php
if ( !$mainframe->isSite() ) { return; }
$session =& JFactory::getSession();
$posted = $session->get('chrono_formpages_data_mother_form_name', array(), md5('chrono');
?>
NB replace mother_form_name with the name of your mother form.

Bob
rocknroad 19 Oct, 2010
Thank you. That's it :-)
This topic is locked and no more replies can be posted.