We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7231
    • 4,205 Posts
    Need to make a few fields required, is there a plug-in for this in MM?
      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

      Something is happening here, but you don't know what it is.
      Do you, Mr. Jones? - [bob dylan]
      • 4310
      • 2,310 Posts
      That would be a nice feature Shane, but I don’t think it does it currently, unless I’ve missed something yet again.
        • 7231
        • 4,205 Posts
        I need to learn more about fow to make plug-ins for MM. There are several simple jquery validation scripts around that it should not be difficult to convert.

        I have a client that can’t seem to remember fill in all the ’required’ fields and I keep having to go in and fix them.
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 4310
          • 2,310 Posts
          The world would be a simlper place without clients.
          Mind you we’d all have to go and get a proper job sad
            • 7231
            • 4,205 Posts
            Quote from: dev_cw at Feb 06, 2009, 11:33 PM

            I have a client that can’t seem to remember fill in all the ’required’ fields and I keep having to go in and fix them.
            I could use a plugin to auto fill some for the required fields if empty, but a simple JS validation would be more flexible.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 10449
              • 956 Posts
              This isn’t Ajaxified or very elegant, but it does the trick:

              <?php
              
              /*
              
              "required fields" plugin
              =========================
              
              check event "OnBeforeDocFormSave" in configuration tab
              
              plugin code:
              include_once $modx->config['base_path'] . 'assets/plugins/required.php';
              
              */
              
              
              if (IN_MANAGER_MODE != "true") {
              	die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the MODx Content Manager instead of accessing this file directly.");
              }
              
              
              $back = "<br /><br /><a href=\"javascript: history.go(-1);\">back</a>";
              $e = & $modx->Event;
              
              switch($e->name) {
              
              	case "OnBeforeDocFormSave":
              
              	$pagetitle = mysql_escape_string($_POST['pagetitle']);
              	$alias = mysql_escape_string($_POST['alias']);
              
              		if(empty($alias)) {
              			die("The alias field is mandatory! $back");
              		}
              
              		if(empty($pagetitle)) {
              			die("The page-title field is mandatory! $back");
              		}
              
              	break;
              
              	default:
              		break;
              
              }
              
              ?>
              


              ^ this only checks pagetitle and alias fields.

              This could be vastly improved if you added some config settings at the top, e.g. list of required fields, list of documents etc. But if you need to set this globally for every doc in your modx site, it’s OK I guess.

              With JS you could of course add some über-cool CSS field-highlighting, so you see which field is empty (e.g. change bg-color or add a red border), but I’m kinda lazy today smiley

              // edit: I just realized this is a ManagerManager discussion. Sorry. The above is not in any way linked to MM. I don’t know how or if you could include it into MM.
                • 4971
                • 964 Posts
                shane: you could use mm_default($field, $value, $roles, $templates, $eval) and set a default in those fields...
                then if the clients forgets to fill them in, at least there is something there?
                  Website: www.mercologia.com
                  MODX Revo Tutorials:  www.modxperience.com

                  MODX Professional Partner
                  • 7231
                  • 4,205 Posts
                  Quote from: charliez at Feb 07, 2009, 05:45 PM

                  shane: you could use mm_default($field, $value, $roles, $templates, $eval) and set a default in those fields...
                  then if the clients forgets to fill them in, at least there is something there?
                  Thanks, that is a good tip.
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don&#39;t know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 30223
                    • 1,010 Posts
                    Here’s a little extension to ManagerManager that will do just what you want.

                    Drop the attached file into the managermanager/functions/ directory and rename it to a php file.

                    In mm_rules.inc.php (or in your rules chunk) you can now use (for example):
                    mm_requireFields('description,alias,introtext', $roles, $templates);
                    

                    If a required field is empty upon save the user will see an alert and the required fields will have their background set to a reddish color.

                    Take it for a test ride...

                    EDIT: It might help if I attached something smiley

                    EDIT: Added to repository as a ManagerManager Extra. Download it here Now supports TVs as well.
                      • 10076
                      • 1,024 Posts
                      Nice plugin, did not get the extension to function.

                      tried this call
                      mm_requireFields('description,alias,introtext');