We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21946
    • 283 Posts
    Hello
    I was working on Drupal the last 8 monthes. One thing i like very much in Drupal is the possibility to manipulate easily any forms from anymodule; adding or deleting elements , adding validations fonctions or submit fonctions. For example it’s very easy to add a field to the user_register form, using the function form_alter to add a field and a hook to register the data collected in the database.

    Is this possible to do this kind of thing with the api of modx Revolution ? If yes, can you give me a link to a documentation for this point?
    More generally, is there an API dedicated to the forms or are they in html?
    Or to take another example : suppose i want to change the value of the submit button from the loggin form; how can i do that without hacking the core?

    thanks for your responses, Modx Revolution seems to be a framework so much easier to understand than Drupal’s API, i would like to come back to Modx has soon sa possible...
      [url=http://www.savepoint.fr/index.php?id=38] -petits tuyaux pour les d
      • 28215
      • 4,149 Posts
      Quote from: nyl at Sep 02, 2009, 07:05 AM

      I was working on Drupal the last 8 monthes. One thing i like very much in Drupal is the possibility to manipulate easily any forms from anymodule; adding or deleting elements , adding validations fonctions or submit fonctions. For example it’s very easy to add a field to the user_register form, using the function form_alter to add a field and a hook to register the data collected in the database.
      What do you mean by "forms"?


      Is this possible to do this kind of thing with the api of modx Revolution ? If yes, can you give me a link to a documentation for this point?
      More generally, is there an API dedicated to the forms or are they in html?

      Or to take another example : suppose i want to change the value of the submit button from the loggin form; how can i do that without hacking the core?
      The manager login form?

      By "forms", do you mean the manager interface?

      If you mean the front-end, MODx does not limit how you design forms at all. They are based completely on your own HTML.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 21946
        • 283 Posts
        sorry i’m french. By forms i mean hum... don’t know the best word, so that is what i call a form :
        a form
        <form action = "talatatsouin">
          <input type = "submit" name = "bill" value = "click if you dare"/>
        </form>
        


        And here’s what do drupal to generate the same things with the api:

        $form['bill'] = array(
          '#type' => 'submit',
          '#value' => 'click if you dare'
        );


        As forms are php arrays in drupal , and has they are passed by reference, you can change in the way you want any forms, anywhere (front-end, back-end, no matters).
        Suppose i want to add a check box on the user register form to ensure the user has read legal mentions of the site, i would code that width drupal:

        function mymodule_form_alter($form_id, &$form){
          if($form_id == 'user_register'){
            $form['submit'] = array(
             '#type' => 'checkbox',
             '#options' => array('Have you read the legal mentions?'),
             '#required' => TRUE
          }
        }


        It allows me to modifiy all forms of the site without hacking the core. I can change the value of a submit button without having to changing the code of a module.
        Is this possible with the framework of Modx revolution?

        Hope this time my explanations are more explicit, sorry for my poor english smiley
          [url=http://www.savepoint.fr/index.php?id=38] -petits tuyaux pour les d
          • 28215
          • 4,149 Posts
          Are you talking about forms in the front-end of your site?
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 21946
            • 283 Posts
            Yes, for the front-end mainly (but i’m acutally talking about all forms generated by Modx Revolution). Is it possible to change in this way a form in front end provided by a snippet (or a plug-in, don’t know exactly what can do a plug-in in Modx Revolution) ? If yes, can i do this with a plug-in or something else ?

            Thanks for your responses. smiley
              [url=http://www.savepoint.fr/index.php?id=38] -petits tuyaux pour les d
              • 28215
              • 4,149 Posts
              Quote from: nyl at Sep 02, 2009, 09:32 AM

              Yes, for the front-end mainly (but i’m acutally talking about all forms generated by Modx Revolution). Is it possible to change in this way a form in front end provided by a snippet (or a plug-in, don’t know exactly what can do a plug-in in Modx Revolution) ? If yes, can i do this with a plug-in or something else ?
              All forms in the front-end, unless you’re using eForm, are most likely done by straight HTML. So you can write forms as you want them to look. I’m not sure what you’re asking, or if you understand the basic Templating principles of MODx.

                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 17499 ☆ A M B ☆
                • 872 Posts
                I think he’s talking about forms html generated by php for front end.

                Nyl Auster give me a little hint about it a couple of months ago with the following codes:

                <?php
                // Imagine for exemple that you want to add on the register form a button with a choice yes or no to ask the user if
                // he has read the condition of utilisation of the site. 
                // Here is at what it looks like.
                
                if($form_id == 'user_register'){
                   $form['ma_checkbox'] = array(
                     '#title'       => "Avez vous lu les conditions générales d'utilisation du site ?",
                     '#type'       => 'radios',
                     '#required'  => TRUE,
                     '#options'   => array('oui', 'non');
                  )
                }
                return $form;
                ?>
                


                It generate the form for front end, and the handler with it.
                  • 22303 MODX Staff
                  • 10,725 Posts
                  My take on form generation is that there are a lot of approaches to it and that MODx should not dictate or provide this out-of-the-box. That’s not to say we won’t provide dynamic form generation solutions as Extras, but it should not IMO be a core feature. Of course, if a fool-proof, generic form generation technique should emerge from an Extra, we might consider adopting in core, but I’ll take bets that this is still an area best served outside of core; I’d rather folks have the option of using their preferred approach to generating and processing forms.
                    • 24935
                    • 160 Posts
                    The answer is no. There is no Forms API in MODx. Not YET at least! I am working on creating a general PHP-based Forms API that could be plugged into MODx in the future. (I have not been satisfied with any of the form apis that I have researched. They all seem to be too limited or too complex.) However, I expect it would be months before anything would be ready for MODx (if ever).

                    As far as changing forms in the back-end manager, there are different ways of doing it depending on the form. For example, Resources (documents) have Template Variables that can be added. If you have a specific manager page you would like to modify, just ask on the forum and people will give suggestions.