We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51399
    • 7 Posts
    So I'm using MigxDB to collect email addresses entered into a form, with a CMP to manage said email addresses.

    At the moment the email addresses are added with a snippet that contains the following:

    $emailAddress = $modx->getOption('email', $scriptProperties, '');
    
    $path = MODX_CORE_PATH.'components/email_subscribers/';
    $modx->addPackage('email_subscribers', $path.'model/');
    
    $subscriber = $modx->newObject('EmailSubscriber');
     
    $date = new DateTime;
    
    $subscriber->set('email', $emailAddress);
    $subscriber->set('createdon', $date->format('Y-m-d H:i:s'));
     
    return $subscriber->save();


    I based this code from this post on Bob's Guides: http://bobsguides.com/custom-db-tables.html.

    This works absolutely fine, but I'm just wondering is this best way to achieve this? At the moment I'm treating it like it's a regular custom DB table, but it feels like there should be a way to do this with Migx itself. I've searched around and I can't find anything and I just feel like I'm missing something.

    Perhaps I'm overthinking it and I should just be happy that my code works.

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

      • 44580
      • 189 Posts
      If you are using Formit for your form, then it can save to the DB for you - in your case by using the FormitToDB hook. If you don't need/ want Formit, then your way seems as good as any other.
      • discuss.answer
        • 5430
        • 247 Posts
        The purpose of Migx is to allow you to do this very thing without the drama of building your own component. There's nothing built in to Migx that would make this easier, your pretty much doing it.
          • 51399
          • 7 Posts
          Thanks for your replies, I'll keep doing it the way I'm doing it then, I just like to be sure I'm doing things the best way smiley.