data[user_id]} - {$form->data[id]} "; // Both have valuesforeach ( $form->data as $key=>$value ) { echo "" . $key . ": " . $value . ""; }// >>>>>> The id exists - GREAT ?>------ Second - "custom code" at the top of the "Submit" section: start of Submit: "; echo " {$form->data[user_id]} - {$form->data[id]} "; // Neither one has a value foreach ( $form->data as $key=>$value ) { echo "" . $key . ": " . $value . ""; }// >>>>>> The id does NOT exist - NO GOOD?>Notes: 1. Before db Read - Custom Code: $user =& JFactory::getUser();$form->data[id] = $user->id; $form->data[user_id] = $user->id; 2. db Read - Setup - Conditions: $form->data[id]); ?>3. db Read - On Found - Custom Code: $form->data['email'] = $form->data[jUser][email];$form->data['username'] = $form->data[jUser][email]; // imp to save$form->data['firstname'] = $form->data[jUser][name];4. db Save - Setup - Conditions: $form->data[id]); ?>5. Overview: The attached screen shot shows the complete setup."> db Record id is Lost When Form is Submitted - Forums

Forums

db Record id is Lost When Form is Submitted

bilal.abdeen 29 Mar, 2016
Hi,

I managed to build a user registration form, to be used instead of Joomla's default registration form.

Now, I am trying to build a form to edit the user's information. I managed to read the users information. However, when the form is submitted, it doesn't save the new information.

For troubleshooting purposes, I created a "custom code" entry at the bottom of the "On Load" section, and another one at the top of the "Submit" section. As you can see below, the "id" is available at the former, while it is NOT available at the latter. What am I missing?

-------- First - "custom code" at the bottom of the "On Load" section:
<?php
echo "<p> <b>end of OnLoad:</b> </p>"; 

echo "<p> {$form->data[user_id]}  - {$form->data[id]} </p>";  // Both have values

foreach ( $form->data as $key=>$value )
       { echo "<p><b>" . $key . ":</b> " . $value . "</p>"; }

// >>>>>> The id exists - GREAT 
?>

------ Second - "custom code" at the top of the "Submit" section:
<?php
echo "<p><b> start of Submit: </b> </p>"; 

echo "<p> {$form->data[user_id]}  - {$form->data[id]} </p>"; // Neither one has a value 

foreach ( $form->data as $key=>$value )
       { echo "<p><b>" . $key . ":</b> " . $value . "</p>"; }

// >>>>>> The id does NOT exist - NO GOOD
?>


Notes:
1. Before db Read - Custom Code:
$user =& JFactory::getUser();
$form->data[id] = $user->id; 
$form->data[user_id] = $user->id; 


2. db Read - Setup - Conditions:
<?php
return array('id' => $form->data[id]); 
?>


3. db Read - On Found - Custom Code:
$form->data['email'] = $form->data[jUser][email];
$form->data['username'] = $form->data[jUser][email]; // imp to save
$form->data['firstname'] = $form->data[jUser][name];


4. db Save - Setup - Conditions:
<?php
return array('id' => $form->data[id]); 
?>

5. Overview:
The attached screen shot shows the complete setup.
GreyHead 29 Mar, 2016
Hi bilal.abdeen,

The screenshot didn't make it. You have to Upload attachments before you submit the post here :-(

How are you passing the id from the load event to the submit event? Do you have it in a form input? Or are you getting it again from the Joomla! User Object?

Be very careful about using id as a variable name - it will be overwritten if there is an id in the page URL e.g. from an article id.

Bob
bilal.abdeen 31 Mar, 2016
GreyHead,

Thank you very much for the feedback. I thought that assigning the id to $form->data[id] would make it available throughout the form (after being defined.) However, it seems that id is a very special field that has to be defined as a form input.

I have decided to use another field $form->data[user_id], as suggested by some other FAQ or a forum topic (probably by GreyHead). This seems to be safer. If anybody is facing the same problem and reading this, I would suggest assigning the user id to $form->data[user_id] in a Custom Code. Then, use it in the Condition field for reading/saving data, i.e. <?php return array('id' => $form->data[user_id]); ?>

Now, I am struggling to make the multi-select check boxes work. It seems that there are some hints in other forum topics, which I am looking into...

This is a powerful extension. However, I think we need better documentation for the various capabilities. I think that the "search capabilities" and/or "topics and FAQ categorisation" can be improved. 😉
GreyHead 31 Mar, 2016
Hi bilal.abdeen,

FYI I use Google search and not the forum search. if you use - site:chronoengine.com search term - that works well.

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