We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26353
    • 1 Posts
    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;
    
    }
    
      • 10487 MODX Staff
      • 1,535 Posts
      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: [email protected]
        Twitter: @garryn
        Web: modx.com