I found out that the things for this particular form element of
Formulaire get wrong encoded in the database:
ele_value in table prefix_form is:
a:3:{i:0;s:1:"1";i:1;s:1:"1";i:2;s:5:"Array";}
and should be (selection of three options)
a:3:{i:0;i:1;i:1;i:0;i:2;a:3:{s:8:"Option 1";i:1;s:8:"Option 2";i:0;s:8:"Option 3";i:0;}}
Got it from the SQL for the example form with fresh install.
This renders OK in the form (user to fill in), edit form (admin) and edit element (admin).
So the problem lies probably in the gathering of the data from the form and storing these in the database.
This is the html for the form.
<form name='form_ele' id='form_ele' action='elements.php?id=15' method='POST' onsubmit="return xoopsFormValidate_form_ele();">
<input type='hidden' name='skipValidationJS' id='skipValidationJS' value='0' />
<input type='hidden' name='op' id='op' value='save' />
<input type='hidden' name='ele_type' id='ele_type' value='select' />
<input type='hidden' name='ele_id' id='ele_id' value='144' />
<table width='100%' class='outer' cellspacing='1'><tr><th colspan='2'>Edit form element: dddth>tr><tr valign='top' align='left'><td class='head'>Caption's name *even'>text' name='ele_caption' id='ele_caption' size='50' maxlength='255' value='ddd' /> | top' align='left'>head'>Size * | even'>text' name='ele_value[0]' id='ele_value[0]' size='3' maxlength='2' value='1' /> |
top' align='left'>head'>Allow multiple selections | even'>radio' id='ele_value[1]0' name='ele_value[1]' value='1' />Ja radio' id='ele_value[1]1' name='ele_value[1]' value='0' checked='checked' />Nee
|
top' align='left'>head'>Options
Tick the check boxes for selecting default values Only the first checked is used if multiple selection is not allowed | even'>checkbox' id='checked[0]0' name='checked[0]' value='1' checked='checked' /> text' name='ele_value[2][0]' id='ele_value[2][0]' size='40' maxlength='255' value='Option 1' />
checkbox' id='checked[1]0' name='checked[1]' value='1' /> text' name='ele_value[2][1]' id='ele_value[2][1]' size='40' maxlength='255' value='Option 2' />
checkbox' id='checked[2]0' name='checked[2]' value='1' /> text' name='ele_value[2][2]' id='ele_value[2][2]' size='40' maxlength='255' value='Option 3' />
Add text' name='addopt' id='addopt' size='3' maxlength='2' value='' /> options submit' class='formButton' name='submit' id='submit' value='Add' />
|
top' align='left'>head'>Required | even'>checkbox' id='ele_req0' name='ele_req' value='1' />
|
top' align='left'>head'>Display | even'>checkbox' id='ele_display0' name='ele_display' value='1' checked='checked' />
|
top' align='left'>head'>Order | even'>text' name='ele_order' id='ele_order' size='3' maxlength='2' value='0' /> |
top' align='left'>head'> | even'>submit' class='formButton' name='submit' id='submit' value='Save' /> button' class='formButton' name='cancel' id='cancel' value='Niet doen'onclick="javascript:history.go(-1);" />
|
foot'>2'>* = Vereist |
I found
this remarks on naming and giving an id to the fields. I do not know if this is relevant or not.
The code for processing this form is in formulaire/admin/elements.php .
include_once("admin_header.php");
if ( file_exists("../language/".$xoopsConfig['language']."/modinfo.php") ) {
include "../language/".$xoopsConfig['language']."/modinfo.php";
}
else {
include "../language/english/modinfo.php";
}
if(!isset($_POST['id'])){
$id = isset ($_GET['id']) ? $_GET['id'] : '';
}else {
$id = $_POST['id'];
}
if(!isset($_POST['ele_id'])){
$ele_id = isset ($_GET['ele_id']) ? $_GET['ele_id'] : '';
}else {
$ele_id = $_POST['ele_id'];
}
if(!isset($_POST['ele_type'])){
$ele_type = isset ($_GET['ele_type']) ? $_GET['ele_type'] : '';
}else {
$ele_type = $_POST['ele_type'];
}
if(!isset($clone)){ $clone="";}
if(!isset($req)){ $req="";}
if(!isset($text)){ $text="";}
if(!isset($_POST['submit'])){ $_POST['submit']="";}
$sql=sprintf("SELECT desc_form FROM ".$xoopsDB->prefix("form_id")." WHERE id_form='%s'",$id);
$res = $xoopsDB->query($sql) or die('Erreur SQL !
'.$requete.'
'.$xoopsDB->error());
if ($res) {
while ( $row = $xoopsDB->fetchRow($res)) {
$title = $row[0];
}
}
if( !empty($_POST) ){
foreach( $_POST as $k => $v ){
${$k} = $v;
}
}elseif( !empty($_GET) ){
foreach( $_GET as $k => $v ){
${$k} = $v;
}
}
$ele_id = !empty($ele_id) ? intval($ele_id) : 0;
$myts =& MyTextSanitizer::getInstance();
if (isset($_POST))
{
foreach ($_POST as $k => $v)
{
$$k = $v;
}
}
if (isset($_GET))
{
foreach ($_GET as $k => $v)
{
$$k = $v;
}
}
if( $_POST['submit'] == _AM_ELE_ADD_OPT_SUBMIT && intval($_POST['addopt']) > 0 ){
$op = 'edit';
}
if ($ele_type == "text")
{ $name = _AM_ELE_TEXT;
} elseif ($ele_type == "textarea")
{ $name = _AM_ELE_TAREA;
} elseif ($ele_type == "areamodif")
{ $name = _AM_ELE_MODIF;
} elseif ($ele_type == "select")
{ $name = _AM_ELE_SELECT;
} elseif ($ele_type == "checkbox")
{ $name = _AM_ELE_CHECK;
} elseif ($ele_type == "radio")
{ $name = _AM_ELE_RADIO;
} elseif ($ele_type == "yn")
{ $name = _AM_ELE_YN;
} elseif ($ele_type == "date")
{ $name = _AM_ELE_DATE;
} elseif ($ele_type == "sep")
{ $name = _AM_ELE_SEP;
} elseif ($ele_type == "upload")
{ $name = _AM_ELE_UPLOAD;
} elseif ($ele_type == "mail")
{ $name = _AM_ELE_MAIL;
} elseif ($ele_type == "mailunique")
{ $name = _AM_ELE_MAIL;
}
switch($op){
case 'edit':
// snipped
break;
case 'delete':
// snipped
break;
case 'save':
if( !empty($ele_id) ){
$element =& $formulaire_mgr->get($ele_id);
}else{
$element =& $formulaire_mgr->create();
}
$element->setVar('ele_caption', $ele_caption);
$req = !empty($ele_req) ? 1 : 0;
$element->setVar('ele_req', $req);
$order = empty($ele_order) ? 0 : intval($ele_order);
$element->setVar('ele_order', $order);
$display = !empty($ele_display) ? 1 : 0;
$element->setVar('ele_display', $display);
$element->setVar('ele_type', $ele_type);
if (isset($_POST))
{
foreach ($_POST as $k => $v)
{
$$k = $v;
}
}
if (isset($_GET))
{
foreach ($_GET as $k => $v)
{
$$k = $v;
}
}
switch($ele_type){
case 'text':
$value = array();
$value[] = !empty($ele_value[0]) ? intval($ele_value[0]) : $xoopsModuleConfig['t_width'];
$value[] = !empty($ele_value[1]) ? intval($ele_value[1]) : $xoopsModuleConfig['t_max'];
$value[] = $ele_value[2];
break;
case 'textarea':
// snipped
break;
case 'areamodif':
// snipped
break;
case 'checkbox':
$value = array();
while( $v = each($ele_value) ){
if( !empty($v['value']) ){
if( $checked[$v['key']] == 1 ){
$check = 1;
}else{
$check = 0;
}
$value[$v['value']] = $check;
}
}
break;
case 'mail':
// snipped
break;
case 'mailunique':
// snipped
break;
case 'radio':
// snipped
break;
case 'yn':
// snipped
break;
case 'date':
$value = array();
$value[] = $ele_value;
break;
case 'sep':
// snipped
break;
case 'select':
$value = array();
$value[0] = $ele_value[0]>1 ? intval($ele_value[0]) : 1;
$value[1] = !empty($ele_value[1]) ? 1 : 0;
$v2 = array();
$multi_flag = 1;
while( $v = each($ele_value[2]) ){
if( !empty($v['value']) ){
if( $value[1] == 1 || $multi_flag ){
if( $checked[$v['key']] == 1 ){
$check = 1;
$multi_flag = 0;
}else{
$check = 0;
}
}else{
$check = 0;
}
$v2[$v['value']] = $check;
}
}
$value[2] = $v2;
break;
case 'upload':
// snipped
break;
}
$element->setVar('ele_value', $value);
$element->setVar('id_form', $id);
if( !$formulaire_mgr->insert($element) ){
xoops_cp_header();
echo $element->getHtmlErrors();
}else{
$url = "index.php?id=$id";
Header("Location: $url");
}
break;
}
include 'footer.php';
xoops_cp_footer();
function addOption($id1, $id2, $text, $type='check', $checked=null){
// snipped
}
function addOptionsTray(){
// snipped
}
?>
I believe maybe the code is addressed to PHP4 and as I found out some
constructs with arrays seems no longer to work in PHP5.
I am working with PHP 5.2.4 .
Is this code suffering from that problem? If yes, how should it be fixed, so it stays compatible with PHP4 and PHP5?
I have a programming background, but I am not deep enough in PHP to understand these finesses. (However the possibility remains that the cause of the problem is in a totaly different corner.)
Regards, Gerard.