We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27889
    • 415 Posts
    I’m trying to build a form with MODx 0.9.6 documents and TV, here is my shema (fields are the defaults):

    	<object class="SiteContent" table="site_content" extends="xPDOSimpleObject">
    ...
    	<composite alias="SiteTmplvarContentvalues" class="SiteTmplvarContentvalues" key="id" local="id" foreign="contentid" cardinality="many" owner="local" />
    	</object>
    	<object class="SiteTmplvarContentvalues" table="site_tmplvar_contentvalues" extends="xPDOSimpleObject">
    ...
            <aggregate alias="SiteTmplvars" class="SiteTmplvars" key="id" local="tmplvarid" foreign="id" cardinality="one" owner="foreign" />
            <aggregate alias="SiteContent" class="SiteContent" key="id" local="contentid" foreign="id" cardinality="one" owner="foreign" />
    	</object>
    	<object class="SiteTmplvars" table="site_tmplvars" extends="xPDOSimpleObject">
    ...
            <composite alias="SiteTmplvarContentvalues" class="SiteTmplvarContentvalues" key="id" local="id" foreign="tmplvarid" cardinality="many" owner="foreign" />
    


    In a snippet I’m trying to build the form with makeform, there is a fourth parameter for setFormObject of xPDOObject type which I don’t know how to use, perhaps it’s the problem.
    <?php
    $form->setFormObject($object, $excludeFields,true); // true to include related element
    $elements  )
    $form->formElements['save']= array (
        'type' => 'submit',
        'name' => 'save',
        'value' => 'Save',
    );
    echo <<<END
    <div class="formError">[+formError+]</div>
    <div class="formMessage">[+formMessage+]</div>
    <form action="[~[*id*]~]" name="sampleForm" id="sampleForm" method="POST">
    [+sampleForm+]
    END;
    return $form->buildForm();
    echo "</form>";
    ?>

    My form is correctly builded but don’t show any TV.

    I "hacked" the _setFormObject function in makeform class:
    <?php
    ...
                if ($this->includeRelated && !empty ($object->_relatedObjects)) {
                echo  '<h2 id="pp"> include related and not empty de related object</h2> ';
                    foreach ($object->_relatedObjects as $relClass => $relDef) {
                        echo  '<h3 id="pppp">'." $relClass  $relDef".'</h3> ';
                        // here $relClass is set to  "SiteTmplvarContentvalues" but $relDef is empty <-------------------------
                        echo print_r($relDef); // Array()1
                        foreach ($relDef as $relKey => $related) {
                           echo  '<h3 id="u">'."relkey : $reKey  related: $related  object".'</h3> ';
    ...
    ?>

    I don’t know why $relDef is empty, must I add something in the class or whatever ?
    Thanks in advance.
      MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
      MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
    • Soda:

      Honestly, that class is out of date with all the changes going on in the rest of xPDO. In fact, I’m going to be moving MakeForm and MakeTable out of xPDO, and moving it into MODx, as they make more sense in that layer and I don’t want them to be mistaken as the only way to approach those problems with pure xPDO code.

      As for your specific issues with it, you have to have an object loaded with the related objects (i.e. using getObjectGraph(), getOne(), getMany(), or other functions that load the related objects into the main object being saved by the form).
        • 27889
        • 415 Posts
        Thanks for your answer, I will start with your class to build a different to serve eForm and work only with xpdo to retrieve all data from the db.
          MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
          MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]