#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    74
    Rep Power
    18

    Issue with tinymce in php


    I am currently making my own simple CMS, just for the fun of it, and to spend some spare time. I am not sure that the problem that I have should be classified as php or html.

    I looked at the tutorial at http://www.w3programmers.com/build-a-cms-with-php-oop-and-mysql-part-2/ to get started, and made some custom changes.

    The problem arises in the admin part. There I have a list of articles. The administrator can edit existing articles, add new articles or remove articles. Both edit and adding functionality work as expected.
    However, I added a tinyMCE editor. The editing panel looks nicer now, and I can still edit existing articles, but I can not add new articles. The submit button does not seem to respond at all, even though it is the exact same page as used for the editpage (same page, different action). Can somebody enlighten me here?

    The code for the article editor view (views/editArticle.php) is:

    PHP Code:
    <?php include "templates/admin/include/header.php";
    ?>
    <script src = "js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
    <script>
    tinyMCE.init({
            // General options
            mode : "textareas",
            theme : "advanced",
            plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

            
    });
    </script>
    <?php

    echo '

    <h2>Widget News Admin</h2>
    </header>
    <p>You are logged in as <b> '
    .htmlspecialchars$_SESSION['username']) .'</b><a href="index.php?action=logout">Log out</a></p>


    <h1>'
    ;
    $results['pageTitle'];

    echo 
    '</h1>

    <form action="index.php?action='
    htmlspecialchars($results['formAction']).'" method="post">

    <input type="hidden" name="articleId" value="'
    .(int) $results['article']->id .'"/>';

    if ( isset( 
    $results['errorMessage'] ) ) { 

    echo 
    '<div>'$results['errorMessage'].'</div>';

     } 
    echo 
    '<ul><li><label for="title">Article Title</label>';
    echo 
    '<input type="text" name="title" id="title" placeholder="Name of the article" required autofocus maxlength="255" value="'.htmlspecialchars$results['article']->title ).'" />';
    echo 
    '</li><li><label for="summary">Article Summary</label>';
    echo 
    '<textarea name="summary" id="summary" placeholder="Brief description of the article" required maxlength="1000" >'.htmlspecialchars$results['article']->summary).'</textarea>';
    echo 
    '</li><li><label for="content">Article Content</label>';
    echo 
    '<textarea name="content" id="content" placeholder="The HTML content of the article" required maxlength="100000" >'.htmlspecialchars$results['article']->content ).'</textarea>';
    echo 
    '</li></ul><div>';
    echo 
    '<input type="submit" name="saveChanges" value="Save Changes" />';
    echo 
    '<input type="submit" formnovalidate name="cancel" value="Cancel" />';
    echo 
    '</div></form>';




    if ( 
    $results['article']->id ) { 

    echo 
    '<p><a href="index.php?action=deleteArticle&amp;articleId='.(int)$results['article']->id.'">';
    echo 
    'Delete This Article</a></p>';



    include 
    "templates/admin/include/footer.php";
    The code for adding a new article (newArticle.php) is:

    PHP Code:
    <?php

    $results 
    = array();

    $results['pageTitle'] = "New Article";

    $results['formAction'] = "newArticle";

    if ( isset( 
    $_POST['saveChanges'] ) ) {

    // User has posted the article edit form: save the new article
    $article = new Article();

    $article->storeFormValues$_POST );

    $article->insert();

    header"Location: index.php?status=changesSaved" );

    } elseif ( isset( 
    $_POST['cancel'] ) ) {

    // User has cancelled their edits: return to the article list

    header"Location: index.php" );

    } else {

    // User has not posted the article edit form yet: display the form

    $results['article'] = new Article();

    require( 
    "templates/admin/views/editArticle.php" );

    }

    ?>
    The code for index.php is:

    PHP Code:
    <?php

    session_start
    ();
    require( 
    "../PDOConnect.php" );
    require(
    "../defines.php");
    require(
    "../core.php");

    $action = isset( $_GET['action'] ) ? $_GET['action'] : "";

    if ( 
    $action != "login" && $action != "logout" && !isset($_SESSION['username']) ) {

        require(
    'login.php');

        exit;

    }

    switch ( 
    $action ) {

        

        case 
    'newArticle':

            require(
    'newArticle.php');

            break;

        ......

        default:

            require(
    'listArticles.php');

    }



    ?>
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    If the submit button doesn't submit an HTTP request back to the server then you have a client side issue, but I don't see it in your code. See if you're getting any JavaScript errors.

    The other possibility is that your action URL is the same as the URL you're currently viewing, and it is actually submitting but you didn't realize that.

    Are you sure $_POST['saveChanges'] is actually not empty?
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    74
    Rep Power
    18
    I found the source of the problem:

    the tinyMCE converted the textareas to texteditors, however these formelements still had the 'required' attribute. So there was a conflict while validating and the errors were not posted. By removing this attribute the form could be posted as expected.

IMN logo majestic logo threadwatch logo seochat tools logo