The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP5 - Issue with tinymce in php
Discuss Issue with tinymce in php in the PHP Development forum on Dev Shed. Issue with tinymce in php PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 31st, 2013, 08:06 AM
|
|
|
|
PHP5 - 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,full screen,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&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');
}
?>
|

January 31st, 2013, 05:05 PM
|
 |
Lost in code
|
|
|
|
|
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?
|

February 2nd, 2013, 11:59 AM
|
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|