I am now back on the project.
I have two custom tables, one for players and another for the honours they have achieved in a club. I am trying to use a list box from the players table with a list of players to select the one I want to use to create a record in the honours table.
I am using formit and migxloopcollection as a select tool. However, when I try to create an honours record the name does not get selected, a 0 is input into the playername field.
The migxloopcollection select tlpoption was suggested by halftrainedharry some months ago.
The resource code is.
[[!FormIt?
&hooks=formit2db,redirect
&preHooks=db2formit
&prefix=agc_
&packagename=honours
&classname=honposition
&tablename=positionagc
&redirectTo=5
&store=1
&validate=nospam:blank, playername:required, position:required, yearwhen:required
]]
Add Position Form
[[!+fi.successMessage]]
[[!+fi.validation_error_message:notempty=`
[[!+fi.validation_error_message]]
`]]
Select position...
Mens Captain
Ladies Captain
President
Vice President
Select member ...
[[!migxLoopCollection?
&prefix=`agc_`
&usecustomprefix=`agc_`
&packageName=`honours`
&classname=`player`
&selectfields=`fullname,gender`
&tpl=`tplOption`
&sortConfig=`[{"sortby":"surname"}]`
&where=`{"gender":"1"}`
&selected=`[[!+fi.playername]]`
]]
Select member ...
[[!migxLoopCollection?
&prefix=`agc_`
&usecustomprefix=`agc_`
&packageName=`honours`
&classname=`player`
&selectfields=`fullname,gender`
&tpl=`tplOption`
&where=`{"gender":"2"}`
&selected=`[[!+fi.playername]]`
]]
Select member ...
[[!migxLoopCollection?
&prefix=`agc_`
&usecustomprefix=`agc_`
&packageName=`honours`
&classname=`player`
&selectfields=`fullname,gender`
&tpl=`tplOption`
&selected=`[[!+fi.playername]]`
]]
Year Captain:
[[!+fi.error.yearwhen]]
<div class="form-buttons">
<input type="submit" value="Enter captain details" />
</div>
The tplOption is.
<option value="[[+fullname]]" [[+fullname:eq=`[[+property.selected]]`:then=` selected="[[+fullname]]"`]]>[[+fullname]]</option>
The schema is:
<?xml version="1.0" encoding="UTF-8"?> <model package="honours" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1"> <object class="player" table="playerdetails" extends="xPDOSimpleObject"> <field key="timeset" dbtype="varchar" phptype="string" precision="25" null="false" default="" /> <field key="title" dbtype="varchar" phptype="string" precision="10" null="false" default="" /> <field key="initial1" dbtype="varchar" phptype="string" precision="10" null="false" default="" /> <field key="initial2" dbtype="varchar" phptype="string" precision="10" null="false" default="" /> <field key="initial3" dbtype="varchar" phptype="string" precision="10" null="false" default="" /> <field key="surname" dbtype="varchar" phptype="string" precision="100" null="false" default="" /> <field key="fullname" dbtype="varchar" phptype="string" precision="50" null="false" default="" /> <field key="gender" dbtype="int" phptype="string" precision="1" null="false" default="" /> <composite alias="captain" class="captain" local="fullname" foreign="playername" cardinality="many" owner="local"/> </object> <object class="honposition" table="positionagc" extends="xPDOSimpleObject"> <field key="playername" dbtype="varchar" phptype="string" precision="100" null="false" default="" /> <field key="position" dbtype="int" phptype="string" precision="1" null="false" default="" /> <field key="yearwhen" dbtype="int" phptype="integer" precision="10" null="false" default="0" /> <aggregate alias="player" class="player" local="playername" foreign="fullname" cardinality="one" owner="foreign" /> </object> <object class="competition" table="competitionagc" extends="xPDOSimpleObject"> <field key="compname" dbtype="varchar" phptype="string" precision="100" null="false" default="" /> <field key="comptype" dbtype="int" phptype="string" precision="1" null="false" default="" /> <field key="compdesc" dbtype="text" phptype="string" precision="500" null="false" default="0" /> </object> </model>
Any help would be useful.