How to load form "Bricks" into custom plugin

Discussion in 'aMember Pro v.4' started by mylkhead, Jan 10, 2013.

  1. mylkhead

    mylkhead New Member

    Joined:
    May 28, 2010
    Messages:
    16
    I'm working on a custom plugin and would like to load existing "Bricks" into an extended form.

    Alternatively, if there's a method to load the php representation of a custom form from the form creator into my plugin, that might be fine too.

    Either way, I just want to be sure I have a dynamically accurate representation of the ids, labels, etc. Would you please give me an idea what methods you'd recommend using to retrieve them? Oh, and piggy backing on the validators you've written would also be nice.

    I see a pile of Classes in Am\Form\Brick but I'm not sure if this is the place to start. Thanks!
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    So as I understood you need to create custom form which will be handled by your plugin? Could you provide more info about how you will use this form where it should be displayed etc?
  3. mylkhead

    mylkhead New Member

    Joined:
    May 28, 2010
    Messages:
    16
    Thanks for the feedback. Specifically I need to create some of my own form elements for quantity selection and other attributes of the order. the quantities directly impact the membership fees and I could not seem to create a field to suit my need through your form builder. I figured I'll need to process the data myself so I wanted to learn if I could use any existing methods to extend forms saved in the database? Thanks!
  4. mylkhead

    mylkhead New Member

    Joined:
    May 28, 2010
    Messages:
    16
    To give you an idea of what I'm struggling with, I need the ability to change the quantity of a product and influence the price. I want to be sure I can route orders and signups through amember so the invoices match qty * product price. Ideally there would be methods or hooks where I can increment or decrement products with quantity options. Please advise. Thank you very much for your insight on this.
  5. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Sure you can create elements which will be available in forms editor.
    You can find an examples of bricks in /amember/library/Am/Form/Brick.php
    You can place your code in /amember/configs/site.php
    Or even better create misc plugin or even better a module:
    http://www.amember.com/downloads/amember-example-module.zip
  6. mylkhead

    mylkhead New Member

    Joined:
    May 28, 2010
    Messages:
    16
    Thanks Alexander, but I know about that feature. I am able to create new blocks fine. What I want your recommendation on is how to load the custom forms with php? I am creating a new API plugin moule so I can use them with ajax. Is it possible to add controllers to hook into something like the Signup Form so I can use its validators but process it differently?

    So far when I extend SignupController, and want to send params in the URL such as /customform/index/param/1/param/2 I keep getting a 404 Not Found when there are params. I have extended Am_Controller directly as well and tested with your $this->getFiltered('param') method but the 404 makes me believe the frontController does not know about the module. Are these Am_Module for admin/private side only?

    Thanks for any clarification you can provide.
  7. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    No it could be used to create user's controllers as well.
    Enable example module(link in my previous post)
    Then modify example/controllers/IndexController.php:
    PHP:
    <?php
    /**
     * This class automatically gets url http://example.com/amember/example/index 
     * or simply http://example.com/amember/example/ (index is assumed)
     */
    include dirname(__FILE__)."/../../default/controllers/SignupController.php";

    class 
    Example_IndexController extends SignupController
    {
        
    /**
         * This method is automatically accessible as
         * http://example.com/amember/example/index/index
         * or
         * http://example.com/amember/example/index/
         * or
         * http://example.com/amember/example/
         * (index is assumed if no controller and action is specified)
         */
    }
    You will get signup form functionality but on different url: /amember/example/index/index/
    Then you can override methods of SignupController and define your own functionality.
  8. mylkhead

    mylkhead New Member

    Joined:
    May 28, 2010
    Messages:
    16
    Thank you Alex. I did not have a problem with extending it like you describe. The problem is with adding parameters after /index/. I receive a 404 and I want to figure out why.

    Using your example, this works:

    /amember/example/index/

    But if I create /amember/example/index/param/1

    I receive a 404. Normally in Zend Framework Controller Actions, you can append parameters after the action name and they'll be provided in the Request object. But it seems like something is different in amember? Do you use a different mod_rewrite for params? Or are these plugins not registered the same way as traditional ZF Controllers?

    Please describe how to make params work for plugin URL. Or do you think the 404 is related to something else such as the plugin bootstrap?

    Thanks a lot for your help, I really appreciate it.
  9. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Url which you try to use is wrong.
    I will explain on default example module. Correct url which you should use and which should work is:
    /amember/example/index/index/param/value

    Where /amember/example/ is path to module
    /amember/example/index/ is path to Example_IndexController
    /amember/example/index/index is path to indexAction within Example_IndexController
    Then from your indexAction then you can get param:
    $this->getParam('param') ; // which will return "value"

    Your url missing "action" so, it is routed to Example_indexController::paramAction method and this method doesn't exists so you get 404 error.
    Let me know if this is not clear enough.
  10. mylkhead

    mylkhead New Member

    Joined:
    May 28, 2010
    Messages:
    16
    Oh sheesh, well that would explain that problem! Thanks for realizing it for me. I'm not used to so many modules.

    Hopefully I can combine your Form builder options with special bricks to get all the features I need. Thanks a lot!
  11. mylkhead

    mylkhead New Member

    Joined:
    May 28, 2010
    Messages:
    16
    Hopefully these will be my last questions.

    1. What view is needed to load jquery and any other form js for validation?

    2. Is there an easier way to set the sign up form action dynamically than overriding Am_Form_Signup_Page? Because today it seemed like that was the only way to reach the Quick form object from pear.

    Thanks again!

Share This Page