In a nutshell a userID is being saved in the database that doesn’t exist anywhere else in code. I’m a beginner with PHP and Joomla, just finished a big component that was for the most part simple in what it does:
Component Description
- Main screen has the list of all the users, filtered by department.
- There are two main tables whose values are listed on that main screen. Click on a value, bring up the edit.php view.
- The link to the Chapters table contains the user’s ID, a class ID, and if the record exists a record ID, and if not then the record ID gets populated on save using Joomla’s JForm native save functionality.
- There are 9 chapters, so each user has up to 9 entries depending on what stage of completion they’re at.
- Fill out the information, Save / Save & Close / Cancel are the only options.
Problem Description
– If the user has no entries at all for chapters 1-9, then a userID of 127 is saved. Where is the 127 coming from? No clue. If there’s an entry in one chapter then it works fine.
Code snippets:
To save: (view.html.php)
JToolBarHelper::apply('chapters.apply', 'JTOOLBAR_APPLY');
JToolBarHelper::save('chapters.save', 'JTOOLBAR_SAVE');
XML (chapters.xml)
<field name="chapter_userid"
type="text"
label="Student UserID"
description=""
size="10"
readonly="true"
class="readonly"
/>
Edit form: (edit.php)
<li>
<?php echo $this->form->getLabel('chapter_userid'); ?>
<?php echo $this->form->getInput('chapter_userid', null, $this->UserID ); ?>
</li>
HTML output for example user 170 (saved in the database as 127, Joomla says it was saved correctly):
<input type="text" name="jform[chapter_userid]" id="jform_chapter_userid" **value="170"** class="readonly" size="10" readonly="readonly"/>
Stuff I’ve done:
-
Have debugging on
-
Lot of adding values to see what’s triggering this.
-
Searched entire html outputs (both main screen and edit.php) for “127” with debugging on – nothing
-
Used get_defined_vars() at the top of the edit screen, searched for 127 – nothing.
-
Pulled out out a lot of hair
I don’t understand why if userID=170 is correctly being passed all the way to the html output that it’s being saved as 127. Has anyone seen anything like this? Is there anything else I can do to debug? Places to check? I suspect that it’s some sort of value stuck in Joomla’s memory, but I also would have thought that get_defined_vars would have spit that out in some way. Or some sort of binary 2^8 offset by 1 (ok, so now I’m in MIDI land, but I’m desperate).
Thank you!
The 127 value was really bugging me, went through all the output and could find nothing out of place – turned out that not only did I have the wrong datatype set but I had the wrong idea of what datatypes were:
http://matthom.com/archive/2006/11/28/mysql-integer-columns-and-display-width
I was expecting no more than a three digit value, so setting it to TinyInt(4) seemed safe when really the () had nothing to do with the length of the value, only the display length.
Hoping this helps out someone else.