We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44437
    • 74 Posts
    I'm loving ModX more and more each day. So many things things that you can do and so many things to learn. I'm getting there ... slowly but getting there. I need some advice on how to tackle the situation.

    I'm building a car dealer website. One functionality it must have is to allow the user to register his/her vehicle. I did that easily with the Login Snippet. However, I just realized that the user should have the ability to add another vehicle to his/her profile and the ability to update all of their data that they had submitted. Plus, when the user logs in, they should be able to
    view all of the profile custom fields.

    My Questions

    1) How do I allow the user to add a new vehicle? Would I have to use the Register Snippet again? Should I do it using the Update Profile Snippet? Any suggestions how the html code should look? I'm thinking that ALL new entries must have unique fields and I'm not sure how to do that.

    2) When a user is logged in and is on his/her profile page, how would I display ALL of their custom fields? According to the Profile Snippet, I must specify each custom field that is to be displayed. Is there a snippet that displays all custom fields and allow the user to edit/update them?

    ANY help will be much appreciated. I'm feeling lost.

    This question has been answered by Bruno17. See the first response.

      • 3749
      • 24,544 Posts
      Don't feel bad about being lost. That's a particularly nasty problem. As with so many things in MODX, there are a number of ways to handle it. I'm assuming that no car can have two owners, otherwise it gets quite a bit more complicated.

      The "correct" way, from a computer science perspective, would be to create a custom database table where each row was a car and one field in that row contained the ID of the owner. That would give you very fast searching and sorting, but it would take a fair amount of work to set up and some custom PHP code to use.

      I think using the MIGX extra might also be an option, but I haven't used it for anything like this.


      I think a good compromise, if you won't have a huge number of cars registered, might be to create a Resource for each car. You can re-purpose some of the resource fields for the characteristics of the car and use Template Variables (TVs) for the rest. I would put the ID of the user in the 'description' field. That will let you find the user's car(s) much faster than if it were in a TV.

      You could then use NewsPublisher to let users create and edit their car information in the front end (put the user's ID in the description field, but don't display it), and it should be fairly easy to use getResources to display their car information (with an edit button that would take them to NewsPublisher to edit it).














        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 44437
        • 74 Posts
        I am expecting thousands of users registering their vehicles online. Therefore, I will have to do it the "correct" way and it will be another learning experience for me.

        When I'm creating the custom database (I have never created one before), should I create it via manager and how lol? Or should I create through phpMyAdmin? I am familiar with some mysql and PhpAdmin.

        Also, would be wise to have all my vehicle fields in the custom database or should I do a combination of Profile snippet and custom database?

        Is there a tutorial online that I can follow?

        P.S Hey Bob, Just want to say I'm a fan of your work and I have bought a copy of your book. It really good. It sits by my desk everyday lol. It's my bible but I also get lost reading it. Sadly, I'm the only Modx developer in the company and I'm one of three persons on my island that knows how to build with Modx lol but I'm loving Modx more and more by the second.

        Come to Barbados sometime. Its a lovely island. Drinks on me

        • discuss.answer
          • 4172
          • 5,888 Posts
          with MIGXdb you could:

          create the needed package-directory
          add the needed xpdo-schema
          let MODX create the needed class-files and the table(s) from this xpdo-schema
          you can add/remove fields from your table by editing the xpdo-schema and parse the schema again with the MIGX-CMP

          create a manager-page for the admin to manage the users and their cars.

          create the frontend-listings and detail-views with migxLoopCollection (included with MIGX)


          you can use formit2db at frontend to let the users add/edit their cars.

            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 44437
            • 74 Posts
            I'm trying the MigxDB route but I'm getting some MIGX error "quip.thread_err_save" when I try to save any data. I have looked in my error log and is what I see

            [2014-07-29 23:15:50] (ERROR @ /home/myuser/myuser.com/testsite/core/xpdo/om/xpdoobject.class.php : 1447) PHP warning: PDOStatement::execute() [<a href='pdostatement.execute'>pdostatement.execute</a>]: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
            [2014-07-29 23:15:50] (ERROR @ /testsite/assets/components/migx/connector.php) Error HY093 executing statement:
            INSERT INTO `modx_mytoyota_vehicle` (`make`, `model`, `manu-year`, `other`, `reg-no`, `uid`, `published`, `deleted`) VALUES ('Toyota', '', '', '', '', '', 1, 1)
            Array
            (
                [0] => HY093
            )


            Maybe I code my schema wrong? I don't know. This is my schema

            <?xml version="1.0" encoding="UTF-8"?>
            <model package="mytoyotavehicle" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
                    <object class="myToyotaVehicle" table="mytoyota_vehicle" extends="xPDOSimpleObject" >
                    <field key="make" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                    <field key="model" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                    <field key="manu-year" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                    <field key="other" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                    <field key="reg-no" dbtype="varchar" precision="255" phptype="string" null="false" default="" /> 
                    <field key="uid" dbtype="varchar" precision="255" phptype="string" null="false" default="" /> 
                    <field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="" />
                    <field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="" />        
                    </object>
            </model>


            Can you tell me what is triggering this error?
              • 44437
              • 74 Posts
              So I think I did it wrong Or not the "correct" way. I am getting problems when I tried using Migxdb, so I tried using a Migx TV instead (desperate attempt). My Migx Tv has 6 fields in the Form Tabs and 5 headers in the Grid Columns. I have managed to figure out how to add data to the Migx TV via Formit using a hook.

              <?php
              $vehicle_id = 337; // vehicle page page ID
              
              $page = $modx->getObject('modResource', $vehicle_id);
              $input = $page->getTVValue('myToyota');
              $res = $modx->fromJSON($input);
              $count = count($res);
              
              
              $new_vehicle = array(
              	'MIGX_id' 		=> count($res) + 1,
              	'make'			=> $scriptProperties['fields']['vehiclemake'],
              	'model'			=> $scriptProperties['fields']['vehiclemodel'],
              	'manu-year'		=> $scriptProperties['fields']['manuyear'],
              	'other'			=> $scriptProperties['fields']['other'],
              	'reg-no'		=> $scriptProperties['fields']['registrationno'],
              	'uid'			=> intval($scriptProperties['fields']['uid'])
              );
              $res[] = $new_vehicle;
              if (!$page->setTVValue('myToyota', $modx->toJson($res))) {
                $modx->log(modX::LOG_LEVEL_ERROR,'There was a problem saving your MIGX PreviousServiceRequests TV!');
                return false;
              }
              
              
              return true;


              How can I edit/remove a row from a Migx TV via the frond end?
                • 44437
                • 74 Posts
                Ok ... I'm almost there

                After trying for a lonnnng time, I finally got

                create the needed package-directory COMPLETED
                add the needed xpdo-schema COMPLETED
                let MODX create the needed class-files and the table(s) from this xpdo-schema COMPLETED
                you can add/remove fields from your table by editing the xpdo-schema and parse the schema again with the MIGX-CMP COMPLETED
                create a manager-page for the admin to manage the users and their cars. COMPLETED
                create the frontend-listings and detail-views with migxLoopCollection (included with MIGX) COMPLETED
                you can use formit2db at frontend to let the users add/edit their cars. FAILURE sad

                I'm getting "Failed to create object of type:" error when I'm trying to edit with formit2db & db2formit

                In my error logs, I'm seeing "addPackage called with an invalid package name." and "No class specified for loadClass"

                I am quite certain I have the correct package name. It loads the XML schema when I call it in MIGX CMP.

                Any ideas???

                Here my code

                Formit call
                [[!FormIt? 
                    &hooks=`spam,formit2db,email` 
                    &preHooks=`db2formit`
                    &prefix=`modx_`
                    &packageName=`giveapraise_countries`
                    &tablename=`giveapraise_countries`
                    &emailTpl=`myEmailChunk` 
                    &emailTo=`[email protected]`
                    &validate=`
                        nospam:blank,
                        code:required,
                        name:required,
                        published:required`
                ]]


                Form HTML
                <form class="form" action="[[~[[*id]]]]" method="post">
                    
                    <input name="nospam" type="hidden" />
                    <input name="id" type="hidden" value="10" />
                    <label for="code">
                        Code:
                        <span class="error">[[+fi.error.code]]</span>
                    </label>
                    <input id="code" name="code" type="text" value="[[+fi.code]]" />    
                     
                 
                    <label for="name">
                        Country:
                        <span class="error">[[+fi.error.name]]</span>
                    </label>
                    <input id="name" name="name" type="text" value="[[+fi.name]]" />
                    
                    <label for="published">
                        Published:
                        <span class="error">[[+fi.error.published]]</span>
                    </label>
                    <input id="published" name="published" type="text" value="[[+fi.published]]" />
                    
                    <input name="deleted" type="hidden" value="0" />
                    
                <br class="clear" />
                <div class="form-buttons">
                        <input type="submit" value="Save" />
                    </div>
                </form>
                  • 4172
                  • 5,888 Posts
                  you will need to add your classname to the formit - call

                  &classname=`yourClass`
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 44437
                    • 74 Posts
                    Hey, it took awhile, but I think I have a grip on Migx and Migxdb. It is really amazing what you can do with it. Guess I have to buy you a beer
                      • 38705
                      • 101 Posts
                      Maybe an old thread but a had a similar problem in one of my configs.

                      Went the migxdb way and have most configs working briliant.
                      However 1 was not working. While trying to edit or save a row the errorlog threw the HY093 error.
                      After reconfiging for several times i decided to remove the minus character form fieldnames. That seems to solve the problem!

                      Do not use fieldnames containing a - (minus)!

                      i.e. start-time, when edited to starttime the problem was gone.

                      In random_Noob's post i see fieldname manu-year and reg-no. Maybe these cause trouble....

                      Hope this helps someone.
                        Addict since 2012....