On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • The example code in the Module Documentation (the phone book module) throws errors due to unescaped quotes. The working code is below:
    /* A simple module */
    
    $opcode = isset($_POST['opcode']) ? $_POST['opcode']:'';
    
    // action directive
    switch($opcode) {
    case 'save':
    // save code here
    echo 'Save action';
    break;
    
    case 'delete':
    // delete code here
    echo 'Delete action';
    break;
    
    case 'search':
    // search code here
    echo 'Search action';
    break;
    
    default: // display module page
    echo '<html>';
    echo '<head></head>';
    echo '<body>';
    echo '<script language="JavaScript" type="text/javascript">';
    echo ' function postForm(opcode){';
    echo ' document.module.opcode.value=opcode;';
    echo ' document.module.submit();';
    echo ' }';
    echo '</script>';
    echo '<form name="module" method="post">';
    echo '<input name="opcode" type="hidden" value="" />';
    echo '<h1>Phone book</h1>';
    echo '<h3>Manage your contacts with ease</h3>';
    echo '<hr />';
    echo '<a href="javascript:;" onclick="postForm(\'save\');return false;">Save</a> | '; 
    echo '<a href="javascript:;" onclick="postForm(\'delete\');return false;">Delete</a> | '; 
    echo '<a href="javascript:;" onclick="postForm(\'search\');return false;">Search List</a> | '; 
    echo '<a href="javascript:;" onclick="postForm(\'\');return false;">Main</a>'; 
    echo '</form>';
    echo '</body>';
    echo '</html>';
    break;
    
    }
    
    • Good catch! Thanks for posting smiley

      EDIT: Documentation updated (note to documentators: escape the escape characters for them to be displayed wink )
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: support@modx.com
        Twitter: @garryn
        Web: modx.com