Really Confused regarding updating records

Dt Dtorr1981 22 May, 2015
Guys,

I have posted reference to this elsewhere but i wanted to try and explain myself a little better.

i've been hovering around and reading posts and i'm still really confused, i was hoping someone could try and explain to me what steps are involved in creating a form to update a table, as at present my form adds a new entry. There are so many options i really do not know what to do. I am using chronoconnectivity to create a list then the edit option options a form whereby i would like to update some details which on being submit will overwrite what is already in the table (this is the first part anyway). Now the form loads the data from the DB no problem, below is the data array info:

Array
(
    [cont] => lists
    [ccname] => leadinfotest
    [act] => edit
    [gcb] => 67
    [leadinfotest] => Array
        (
            [id] => 67
            [uniq_id] => 05e80ae97ef496d8cc888ad204cb30823a64fef0
            [user_id] => 1007
            [created] => 2015-05-21 16:02:58
            [modified] => 2015-05-21 15:02:58
            [s_type] => 1
            [fname] => Annette
            [lname] => Curtain
            [school] => Leicester
            [class] => Super-Sparks
            [t_num] => 07566665484
            [email] => Name@hotmail.co.uk
            [activity_status] => 0
            [t_date] => 20-05-2015
            [conf_call] => 0
            [taster_conf] => 0
            [taster_attended] => 0
            [t_dns] => 0
            [button6] => Submit
            [hidden66] => 
            [addinfo] => Test
        )

    [user] => Array
        (
            [id] => 1007
            [name] => Annette Curtain
            [username] => Curtain3b3d97b
            [email] => name@hotmail.co.uk
            [password] => $2y$10$yB7gTcRRQuB2KSq2
            [block] => 0
            [sendEmail] => 1
            [registerDate] => 2015-05-21 16:02:58
            [lastvisitDate] => 2015-05-21 14:25:19
            [activation] => 0
            [params] => Array
                (
                    [editor] => 
                    [timezone] => 
                    [language] => 
                    [admin_style] => 
                    [admin_language] => 
                    [helpsite] => 
                )

            [lastResetTime] => 0000-00-00 00:00:00
            [resetCount] => 0
            [otpKey] => 
            [otep] => 
            [requireReset] => 0
        )

)


Now initially what i want to do is from this form change the s_type value from 0 to 1 and vice versa and have this update the same record in the table, where as it is adding a new record at the moment. The user model has a primary key field 'id', the foreign key to this field in the leadinfotest model is 'user_id'. The primary key in the leadinfotest model is again 'id'.

Where do i even start with this to change it from an insert to an update? Please help its driving me mad.

Best Regards
Donna
Gr GreyHead 23 May, 2015
Hi Donna,

I don't understand what you are trying to do here? Are you trying to allow the user to edit to form data? Or just toggling one column value?

If you just want to toggle a single column then you can probably do that with a single form event and some custom code
<?php
if ( $form->data['[leadinfotest]']['s_type'] == 1 ) {
  $s_type = 0;
} else {
  $s_type = 1;
}
$db = JFactory::getDBO();
$query = "
    UPDATE `#__leadinfotest`
        SET `s_type` = {$s_type}
        WHERE `id` = '{$form->data['[leadinfotest]']['s_type']}' ;
";
$db->setQuery($query);
$result = $db->execute();
?>

Bob
Dt Dtorr1981 26 May, 2015
Hi Bob,

I am trying to let the user edit data, but thought the simplest way is to try and concentrate on getting one field working rather than confusing myself with multiple fields.

Best Regards
Donna
bi bighen 15 Jun, 2015
Hi all,

I had the same problem as Dtorr1981
I knew I could do some manual adjustments creating load form/update data scripts but was lucky to find the solution - for sure for my CC+CF instances of course.

The reason of adding the record instead of updating existing one was "Disabled" status of id field in the form.
Somehow it is invisible for the script so it is assuming there is no id value and doing "INSERT" instead of "UPDATE"

So the update works if the id field is "Hidden" or "Parent hidden" (what that means ?)

Hope it helps

CC + CF is a quite complex enviroment and not all minor things cooperate...

Regards
Henryk
bi bighen 15 Jun, 2015
Of course it works for the status "Visible & Enabled" as well !
H.
Gr GreyHead 16 Jun, 2015
Hi Henryk,

I'm not clear if you have answered your question or not?

If an input is disabled then nothing from that element is submitted when the form is submitted. If you want an element to be submitted but not editable then either use a hidden input; or set the element to readonly (which is submitted).

The 'Hidden' setting only hides the input element, the surrounding HTML including the label is still shows; 'Parent Hidden' hides the element and the HTML around it so that it is effectively invisible until un-hidden.

Bob
This topic is locked and no more replies can be posted.