Hi,
I have a number of checkboxes in a form, all named regions[]
on submitting the form, this section of POST:array is as it should be [regions] => Array ( [0] => North_East [1] => North_West [2] => Yorkshire_And_The_Humber [3] => Wales [4] => East_Midlands )
I have a number of database tables being writen to with similar syntax as the below(without arrays, without the autogenerated code running, queries are in onsubmit after email)they work ok, it must be the way im handling the array that is not inserting the $regions into the table. Anything obvious you can see wrong with the array?
ChronoFormsv3.0
ive searched everywhere, and tried several variations over a number of weeks, ive just not found anything that clicks and works
also, another quick one..
is it possible to use the array key as a variable such as $key, if its set in the form as say arrayname[key] ? - this could cut the code down by 1000 lines!
many thanks
peers
I have a number of checkboxes in a form, all named regions[]
on submitting the form, this section of POST:array is as it should be [regions] => Array ( [0] => North_East [1] => North_West [2] => Yorkshire_And_The_Humber [3] => Wales [4] => East_Midlands )
I have a number of database tables being writen to with similar syntax as the below(without arrays, without the autogenerated code running, queries are in onsubmit after email)they work ok, it must be the way im handling the array that is not inserting the $regions into the table. Anything obvious you can see wrong with the array?
ChronoFormsv3.0
...
$regions = array();
$regions = JRequest::getVar('regions', array(), 'post', 'array');
foreach($regions as $key=>$region) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = '46',
data_txt = '$region',
data_char = '',
itemid = '$sobi_id;";
$db->setQuery($query);
$db->query(); }
...
ive searched everywhere, and tried several variations over a number of weeks, ive just not found anything that clicks and works
also, another quick one..
is it possible to use the array key as a variable such as $key, if its set in the form as say arrayname[key] ? - this could cut the code down by 1000 lines!
many thanks
peers
Hi peers,
I can see this problem in your code:
you can use the $key inside the foreach loop, it will has 0,1,2,3,4 based on the loop number as you can see in the DEBUG code!
Cheers
Max
I can see this problem in your code:
itemid = '$sobi_id;";
should beitemid = '$sobi_id'";//added 1 single quote before the string end!
you can use the $key inside the foreach loop, it will has 0,1,2,3,4 based on the loop number as you can see in the DEBUG code!
Cheers
Max
thanks Max! after so many hours it was a missing '
reference for if useful for anyone else..
reference for if useful for anyone else..
...
// all textbox form elements are named txtboxes[key] where key is the sobi2 directory fieldid
$txtboxes = array();
$txtboxes = JRequest::getVar('txtboxes', array(), 'post', 'array');
foreach($txtboxes as $key=>$txtbox) {
$query ="INSERT INTO #__sobi2_fields_data
SET fieldid = '$key',
data_txt = '$txtbox',
data_char = '',
itemid = '$sobi_id';";
$db->setQuery($query);
$db->query(); }
...
This topic is locked and no more replies can be posted.