0

I have inserted a rich text editor to an textarea, but I get the following error after submitting my form:

Notice: Undefined index: msgpost in C:\wamp\www\mycms\administrator\page_new_parse.php on line 15

I have changed the textarea name, and the id to "msgpost" as explained on their website.

I have also changed the body class, as they suggested.

My error line looks like this:

$msgpost = ($_POST['msgpost']); //Looks ok to me?

When I try to send the data to the database, my code looks like this:

// Add the info into the database table
$query = mysqli_query($myConnection, "INSERT INTO pages (pagetitle, description, keywords, linklabel, position, heading, pagebody, lastmodified) 
        VALUES('$pagetitle','$description', '$keywords', '$linklabel', '$position', '$heading', '$msgpost',now())") or die (mysqli_error($myConnection));

Everything gets processed, excepts the text that is written in the textarea using "YUI 2 - Rich text editor".

It fullfills my needs, so I am curious on how to get this to work.

Any suggestions, experiences on this issue?

Klemme

4
Contributors
7
Replies
17
Views
6 Years
Discussion Span
Last Post by Qaalid
0

Right, This is the only field in which I have used the text editor:

<p><b>Pagebody:&nbsp;<span class="required">*</span></b></p><textarea name="msgpost" id="msgpost" cols="100" rows="19"></textarea>

And then I get it like this on the processing page:

$msgpost = ($_POST['msgpost']);

Mysql query:

// Add the info into the database table
$query = mysqli_query($myConnection, "INSERT INTO pages (pagetitle, description, keywords, linklabel, position, heading, pagebody, lastmodified) 
        VALUES('$pagetitle','$description', '$keywords', '$linklabel', '$position', '$heading', '$msgpost',now())") or die (mysqli_error($myConnection));

I seems to look fine to me, but I am new to this still so I might have missed something, obviously :-)

0

What about your whole form? I can't see form tags or a submit button to be able to answer the question.

0
<form id="form" name="form" method="post" action="page_new_parse.php" 
    onsubmit="return validate_form ( );">
    
   <p><b>Page Full Title:<span class="required">*</span></b></p><input name="pagetitle" type="text" id="pagetitle" 
   size="53" maxlength="80"/> 
    
    <p><b>Link Label:<span class="required">*</span></b></p><input name="linklabel" type="text" id="linklabel" 
    size="53" maxlength="65"/> 
    
    <?php 
		include_once "connect_to_mysql.php";
		//Placing the page, using a dropdown list
	$query="SELECT * FROM pages ORDER BY position ASC";
	?>
	<p><b>Place Your Page:&nbsp;<span class="required">*</span></b></p>
	<select class="boxstyles" name="position">
	<?php
	echo "<option>Choose Position&nbsp;</option>";?>
    <?php
	$result = mysqli_query($myConnection, $query);
	$subject_count = mysqli_num_rows($result);
		// Subject_count +1 b/c adding a subject
		for($count=2; $count <= $subject_count+1; $count++) {
		echo "<option value=\"{$count}\">{$count}&nbsp;</option>";	
		} 
	?>
	</select>
    
    <p><b>Heading:;<span class="required">*</span></b></p><input name="heading" type="text" id="heading" size="53" maxlength="65" />
   </div>
    
    <div id="body_right">
    <p><b>Description:</b><i>(Optional - Read "Tips On SEO" for information!)</i></p><textarea name="description" id="description" cols="47" rows="3"></textarea>   
      
    <p><b>Keywords:</b><i>(Optional - Read "Tips On SEO" for information!)</i></p><textarea name="keywords" id="keywords" cols="47" rows="3"></textarea>
    </div>

    <div id="body_bottom"> 

    <p><b>Pagebody:<span class="required">*</span></b></p><textarea name="msgpost" id="msgpost" cols="100" rows="19"></textarea>

    <input type="submit" name="button" id="button" value="Create Page!" />
    </form>

This is the whole form, incl. the textarea field (msgpost), which has got the TUI text editor attached.

In my process page, I have the following code:

$pagetitle = ($_POST['pagetitle']);
$description = ($_POST['description']);
$keywords = ($_POST['keywords']);
$linklabel = ($_POST['linklabel']);
$position = ($_POST['position']);
$heading = ($_POST['heading']);
$msgpost= ($_POST['msgpost']);

//And then my dql insert query

$q = mysqli_query($myConnection, "UPDATE pages SET position = position + 1 WHERE position >= $position");

$query = mysqli_query($myConnection, "INSERT INTO pages (pagetitle, description, keywords, linklabel, position, heading, pagebody, lastmodified) 
        VALUES('$pagetitle','$description', '$keywords', '$linklabel', '$position', '$heading', '$msgpost', now())") or die (mysqli_error($myConnection));

Everything gets sent to the database, execpt the text written in pagebody, using the YUI text editor.

If I remove the YUI editor, the text from the pagebody processes fine to the database, so for some reason, when using the YUI editor, I get this line to cause an error:

$msgpost = ($_POST['msgpost']); //Error = Undefined index...Works fine without YUI..?

Any new eyes that can see the problem?

By the way, I include the editor like this in the head section:

<!-- Skin CSS file -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.2r1/build/assets/skins/sam/skin.css">
<!-- Utility Dependencies -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js"></script> 
<script src="http://yui.yahooapis.com/2.8.2r1/build/element/element-min.js"></script> 
<!-- Needed for Menus, Buttons and Overlays used in the Toolbar -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/container/container_core-min.js"></script>
<script src="http://yui.yahooapis.com/2.8.2r1/build/menu/menu-min.js"></script>
<script src="http://yui.yahooapis.com/2.8.2r1/build/button/button-min.js"></script>
<!-- Source file for Rich Text Editor-->
<script src="http://yui.yahooapis.com/2.8.2r1/build/editor/editor-min.js"></script>

//Change the body class
<body class="yui-skin-sam">

//Then I render the editor by writing msgpost in the id
<textarea name="msgpost" id="msgpost" cols="50" rows="10">
    <strong>Your</strong> HTML <em>code</em> goes here.<br>
    This text will be pre-loaded in the editor when it is rendered.
</textarea>

var myEditor = new YAHOO.widget.Editor('msgpost', {
    height: '300px',
    width: '522px',
    dompath: true, //Turns on the bar at the bottom
    animate: true //Animates the opening, closing and moving of Editor windows
});
myEditor.render();

//Then I get the data from the editor
var myEditor = new YAHOO.widget.Editor('msgpost');
myEditor.render();
 
//Inside an event handler after the Editor is rendered
YAHOO.util.Event.on('somebutton', 'click', function() {
    //Put the HTML back into the text area
    myEditor.saveHTML();
 
    //The var html will now have the contents of the textarea
    var html = myEditor.get('element').value;
});

When posting msgpost, with php it doesnt get sent..

Can the order of the above cause this to (not) happen?

0

yes u can solve this problem by using the function below the render function,

function myDoSubmit() {
	//alert('handling submit!');
	myEditor1.saveHTML();
	//alert(document.getElementById('msgpost').value);
	return true;
}

and then in the form tag cal the function

<form action="editorconnection.php" method="post" onsubmit="return myDoSubmit()">

really it works.... try it.....:)

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

I have a problem same like this i'm using easyphp 5.3.8.0 n mysql so i'm using YUI RTF the insert is working me fine but the update is not working proberly, the update fields are working except the TextArea data, when click edit and loaded the data then edited All data saved nice but the TextArea not working. So any one can help me for that?? i dont have time i want to submit my project after 2 days!

This is my full code:

  1. Heading section

    <head>
    <!-- Text Editor Styles and popups -->
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
    <style type="text/css">
    /*margin and padding on body element
      can introduce errors in determining
      element position and are not recommended;
      we turn them off as a foundation for YUI
      CSS treatments. */
    body {
        margin:0;
        padding:0;
    }
    </style>
    
    <link rel="stylesheet" type="text/css" href="CSS/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="CSS/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="CSS/build/fonts/fonts-min.css" />
    <link rel="stylesheet" type="text/css" href="CSS/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="CSS/build/editor/assets/skins/sam/editor.css" />
    <script type="text/javascript" src="CSS/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="CSS/build/element/element-min.js"></script>
    <script type="text/javascript" src="CSS/build/container/container-min.js"></script>
    <script type="text/javascript" src="CSS/build/menu/menu-min.js"></script>
    <script type="text/javascript" src="CSS/build/button/button-min.js"></script>
    <script type="text/javascript" src="CSS/build/editor/editor-min.js"></script>
    
    </head>
    <body class="yui-skin-sam">
    
  2. My PHP code:

      <?php
        include"Conn2.php";                         
    
        $id =$_REQUEST['Sem_id'];
        //echo $id; //to test if the id is working or not
        echo'<form method="post">';
        echo'<input type="hidden" name="id_2" value='.$id.'/>';
        $id_2 =$_REQUEST['Sem_id'];
        //echo $id_2;
    
        $query="SELECT * FROM seminar WHERE Sem_id  = '$id'" or die(mysql_error());
        $result = mysql_query($query) or die("Unable to verify database because: ".mysql_error());
    
        $row = mysql_fetch_array($result);
        if (!$result)                               
        {
        die("Error: Data not found..");
        }
            $title=$row['Sem_title'] ;
            $date= $row['Sem_date'] ;                   
            $speaker=$row['Speaker'] ;
            $place=$row['Place'] ;
            $cost=$row['Cost'] ;
            $atten=$row['Attenders'] ;
            $detl=$row['Detail'] ;
            $editor=$row['Body'] ;
    
            if(isset($_POST['save']))
            {   
            $tit= $_POST['title'];
            $dat = $_POST['date'];
            $spk = $_POST['speaker'];
            $place = $_POST['place'];
            $cost = $_POST['cost'];
            $attnd = $_POST['atten'];
            $det = $_POST['detl'];
            $editor = nl2br($_POST['editor']);
    
            mysql_query("UPDATE seminar SET Sem_title ='$tit', Sem_date ='$dat', Speaker ='$spk', Place ='$place', Cost ='$cost', Attenders ='$attnd',  Detail ='$det', Body='$editor' WHERE Sem_id = '$id_2'") or die("Unable to update because: ".mysql_error());                             
    
            //header("Location: Seminar.php");
            echo"Data Updated Successfully";
            }                           
            mysql_close($conn);
        ?>
    
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <table>
        <tr>
            <td>Title:</td>
            <td><input type="text" name="title" value="<?php echo $title ?>"/></td>
        </tr>
        <tr>
            <td>Date:</td>
            <td><input type="text" name="date" value="<?php echo $date ?>"/></td>
        </tr>
        <tr>
            <td>Speaker:</td>
            <td><input type="text" name="speaker" value="<?php echo $speaker ?>"/></td>
        </tr>
        <tr>
            <td>place: </td>
            <td><input type="text" name="place" value="<?php echo $place ?>"/></td>
        </tr>
        <tr>
            <td>Cost: </td>
            <td><input type="text" name="cost" value="<?php echo $cost ?>"/></td>
        </tr>
        <tr>
            <td>Attenders: </td>
            <td><input type="text" name="atten" value="<?php echo $atten ?>"/></td>
        </tr>
        <tr>
            <td>Detail: </td>
            <td><input type="text" name="detl" value="<?php echo $detl ?>"/></td>
        </tr>
        <tr>
            <td></td>
            <td>                             
                <?php
                    echo "<textarea id='editor' name='editor'>" . $row['Body'] . "</textarea>
                    <br /><button type='submit' name='save'>Save</button>";
                ?>
    
    
    
    
    
    
    <script>
    
    (function() {
        var Dom = YAHOO.util.Dom,
            Event = YAHOO.util.Event;
    
        var myConfig = {
            height: '200px',
            width: '600px',
            dompath: true,
            focusAtStart: true
        };
    
        YAHOO.log('Create the Editor..', 'info', 'example');
        var myEditor = new YAHOO.widget.Editor('editor', myConfig);
        myEditor._defaultToolbar.buttonType = 'basic';
        myEditor.render();
    
    })();
    </script>    
    

Edited by diafol: tried to reformat code

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.