problem with hidden field

Talk about link fields or link implementations

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

Emmanuel71
Junior
Junior
Posts: 11
Joined: Apr 19th, '13, 17:56

problem with hidden field

Postby Emmanuel71 » Mar 2nd, '16, 20:17

I have 2 hidden fields defined as follows for default value in add mode:

$em_columns['create_time']=array('header'=>'Create Time','type'=>'hidden','align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','unique'=>'false','default'=>'CURRENT_TIMESTAMP',);
$em_columns['create_user']=array('header'=>'Create User','type'=>'hidden','align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','unique'=>'false','default'=>'user1',);


when i run the program the page source looks as follows:

...</table>
<input type='hidden' id='stycreate_time' name='stycreate_time' value='CURRENT_TIMESTAMP' />
<input type='hidden' id='stycreate_user' name='stycreate_user' value='user1' />
</form><script type="text/javascript">...


The problem is that the create_user field does not get updated. It stays empty. The create_time field is updated correctly. Any ideas?

thx,
Emmanuel Ingelaere

ne_moj
Master
Master
Posts: 243
Joined: Jan 1st, '16, 14:11

Re: problem with hidden field

Postby ne_moj » Mar 5th, '16, 15:08

Hello Emmanuel Ingelaere.

You could tell what kind of product you are using and its version.

Emmanuel71
Junior
Junior
Posts: 11
Joined: Apr 19th, '13, 17:56

Re: problem with hidden field

Postby Emmanuel71 » Mar 6th, '16, 20:36

I'm using the datagrid version 7.7.7. The page was originally created with the datagrid wizard and then customized.

I wil try to explain what I want to do:

I want to add a standard way I can use in my pages, for filling the fields create_user, update_user, create_time and update_time using hidden fields:

in add mode, create_user en create_time need to be filled in, I have managed to make this work now.
in detail mode, the 4 fields (create_user, update_user, create_time and update_time) need to be shown to the user.
in edit mode, create_user and create_time are shown to the user, update_time and update_user need to be updated trough hidden fields.

To accomplish this, I create the 4 fields as follows in section 7. Add/Edit/Details Mode Settings:

'create_time'=>array('header'=>'Create Time1','visible'=>'true','type'=>'date' ,'req_type'=>'st','readonly'=>'true'),
'create_user'=>array('header'=>'Create User1','visible'=>'true','type'=>'textbox','req_type'=>'st','readonly'=>'true'),
'update_user'=>array('header'=>'Update User1','visible'=>'true','type'=>'textbox','req_type'=>'st','readonly'=>'true'),
'update_time'=>array('header'=>'Update Time1','visible'=>'true','type'=>'date' ,'req_type'=>'st','readonly'=>'true'),


After the creation of the array with fields, I do the following to overwrite the first definition of the fields (it didn't work without creating the fields a first time in this section):
require $_SERVER["DOCUMENT_ROOT"] . "\phpfuncties\CreateUpdateUser.php";

The file contains following code:

switch ($mode) {
case 'add':
$em_columns['create_time']=array('header'=>'Create Time','type'=>'hidden','align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','unique'=>'false','default'=>'CURRENT_TIMESTAMP',);
$em_columns['create_user']=array("header"=>"Create User", "type"=>"hidden", "req_type"=>"st", "default"=>"$sUserId", "unique"=>"false", "visible"=>"false");
break;
case 'edit':
$em_columns['create_time']=array('header'=>'Create Time','type'=>'date' ,'align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','readonly'=>'true','unique'=>'false');
$em_columns['create_user']=array('header'=>'Create User','type'=>'textbox','align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','readonly'=>'true','unique'=>'false');
$em_columns['update_user']=array("header"=>"Update User", "type"=>"hidden", "req_type"=>"st", "value"=>"$sUserId", "unique"=>"false", "visible"=>"false");
break;
case 'details':
$em_columns['create_time']=array('header'=>'Create Time','type'=>'date','align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','readonly'=>'true','unique'=>'false');
$em_columns['create_user']=array('header'=>'Create User','type'=>'textbox','align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','readonly'=>'true','unique'=>'false');
$em_columns['update_time']=array('header'=>'Update Time','type'=>'date','align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','readonly'=>'true','unique'=>'false');
$em_columns['update_user']=array('header'=>'Update User','type'=>'textbox','align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','readonly'=>'true','unique'=>'false');
break;
default:
$em_columns['create_time']=array('header'=>'Create TimeUnknown','type'=>'date','align'=>'left','width'=>'','req_type'=>'st','maxlength'=>'-1','readonly'=>'true','unique'=>'false');
break;
}


This works perfectly now, the only problem is the update_user field does not get filled in edit mode. It always stays empty. Am I missing something?

administrator
Site Admin
Site Admin
Posts: 5981
Joined: Jan 7th, '09, 23:18
Contact:

Re: problem with hidden field

Postby administrator » Mar 7th, '16, 12:40

1. Rewrite "value"=>"$sUserId" with "value"=>$sUserId
2. Debug this variable if it gets something value: $sUserId

Emmanuel71
Junior
Junior
Posts: 11
Joined: Apr 19th, '13, 17:56

Re: problem with hidden field

Postby Emmanuel71 » Mar 7th, '16, 19:57

When I debug the variable (using echo), it contains a correct value (=user001). I have omitted the quotes in both create_user and update_user for the variable $sUserId. Situation after this remains the same: it works for create_user in add mode. Not for update_user in edit mode.

The page source in edit mode looks like this, I added some extra code so you can get an idea of the location of the code fragment:
</table>
<input type='hidden' id='styupdate_user' name='styupdate_user' value='user001' />
</form><script type="text/javascript">
<!--
document.getElementById("qhjhqloading_image").style.display="none";


The page source in add mode looks like this,
</table>
<input type='hidden' id='stycreate_time' name='stycreate_time' value='CURRENT_TIMESTAMP' />
<input type='hidden' id='stycreate_user' name='stycreate_user' value='user001' />
</form><script type="text/javascript">
<!--
document.getElementById("oafevloading_image").style.display="none";


In the database, the field update_user is defined as:
update_user, varchar(8) DEFAULT NULL (the same as create_user)

Emmanuel71
Junior
Junior
Posts: 11
Joined: Apr 19th, '13, 17:56

Re: problem with hidden field

Postby Emmanuel71 » Mar 8th, '16, 11:32

The output of the debug info in edit mode is as follows, the table view_st_hoofdpagina is actually a view used for view mode, not the table to update:

select sql (total: 12 | time: 0.2285 sec.) select CONCAT("\"wijzigen\" \"wijzigen\"") as action_links,id,taaknummer,DATE_FORMAT(datumin,"%Y-%m-%d") as datumin,naam,omschrijving,datumuit,voor_dienst,voor_personeelslid,type,eigenaar,projectleider,volledigafgewerkt,opvolging_opmerking,confidentieel,id_personeel_dienst_eigenaar,(SELECT count(*) FROM attachments WHERE tabel="st_steuntaken" AND id_in_tabel=view_st_hoofdpagina.id) as bijlage,update_time,update_user,create_time,create_user,concat("[ ",(SELECT count(*) FROM st_steuntaken_detail WHERE id_st_steuntaken=view_st_hoofdpagina.id)," subtaken ]" ) AS details_link from view_st_hoofdpagina where id_personeel_dienst_eigenaar in (15) ORDER BY id desc LIMIT 0, 20


Retrieve data for foreign key:
select sql (totaal: 42 | time: 0.0017 sec.) SELECT id,Naam FROM personeel_dienst WHERE 1=1 ORDER BY naam ASC


Retrieve data for foreign key:
select sql (totaal: 359 | time: 0.0025 sec.) SELECT id,Naamlang FROM gebruikers WHERE 1=1 ORDER BY naamlang ASC


Retrieve data for foreign key:
select sql (totaal: 42 | time: 0.0014 sec.) SELECT id,Naam FROM personeel_dienst WHERE 1=1 ORDER BY naam ASC


Retrieve data for foreign key:
select sql (totaal: 359 | time: 0.0023 sec.) SELECT id,Naamlang FROM gebruikers WHERE 1=1 ORDER BY naamlang ASC

POST:
Array
(
[stmode] => edit
[strid] => 55
[stpage_size] => 20
[stp] => 1
)


GET:
Array
(
)


FILES:
Array
(
)



Waarschuwingen:

1) Wrong parameter in []: Check this field carefully, it may be not a Primary Key!




DataGrid v7.7.7 | Extension: PDO | Database: mysql | Total running time: 0.287946 sec.

administrator
Site Admin
Site Admin
Posts: 5981
Joined: Jan 7th, '09, 23:18
Contact:

Re: problem with hidden field

Postby administrator » Mar 9th, '16, 08:20

There is a different for add and edit modes:
http://www.apphp.net/forum/viewtopic.php?f=33&t=592

Emmanuel71
Junior
Junior
Posts: 11
Joined: Apr 19th, '13, 17:56

Re: problem with hidden field

Postby Emmanuel71 » Mar 10th, '16, 03:25

I found what the problem was. It was the readonly option in the first declaration of the field. Setting this option to false resolved it. Thanks for the replies. Your grid really rocks!


Return to “Field type: "link"”