Hi all,
Looking for some help on how to post the results from CKEditor back to a database.
This is so that users can amend their profile. The users data is read from the MySQL Database and displayed on the form.
I have put the field into a textarea and I can amend it using CKEditor... that works fine.
But how do I post the amended text back to the database when the user clicks the "Submit" button?
Can anyone please point me to an article/posting that explains?
(I am sure this has been answered loads of times, but I cant seem to find the answer anywhere)
Thanks...
Philip.
Looking for some help on how to post the results from CKEditor back to a database.
This is so that users can amend their profile. The users data is read from the MySQL Database and displayed on the form.
I have put the field into a textarea and I can amend it using CKEditor... that works fine.
But how do I post the amended text back to the database when the user clicks the "Submit" button?
Can anyone please point me to an article/posting that explains?
(I am sure this has been answered loads of times, but I cant seem to find the answer anywhere)
Thanks...
Philip.
Re: A Simple newbie question...
Right now, I'm assuming you need an editing page, and its corresponding "write-to" page.
If you're using php, I think you can just assign the $_POST results to a $variable:
if (array_key_exists('editor_data',$_POST)) {
//assuming your form is inserted and active, and that your submit <input> has name "submit"
//and that your text area is called "editor_data"
$editor_results = $_POST['editor_data'];
//rough query...new to this, too
$sql = SELECT * FROM your_table_name;
//INSERT or UPDATE here
INSERT INTO your_table_name $editor_results WHERE column_id = ColumnName ;
}
Good luck. Right now, I'm just trying to figure out what information is missing between the sample page's replace div example and the underlying coding that it refers to. Because, it's not working for me...
Re: A Simple newbie question...
Thanks for that. I might give that a try. However, I am frustrated that I cant get it to work the way it SHOULD work.
So I will continue to mess with the code to see if I can get it to work. If I succeed I will post the way I did it.
All the best,
Philip.
Re: A Simple newbie question...
take out CKEditor, just use a textarea. Now add the rest of your code so the user can save and edit the contents of that textarea. When you have that part ready add back the CKEditor call and it will work.
You'll find much more information about creating a CMS using textareas as that's a basic HTML element instead of searching for CKEditor.
Re: A Simple newbie question...
Ok, Now I understand what is going on. :^) And I got it working ok. This is what you do to AMEND data served up by some SQL query or something.
First of all, you have to include this bit of script somewhere between your <head> and </head>
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
Obviously if you have installed to a different directory then you will have to change the path given above.
Then, on your page you should have a form that is populated with the data from the SQL query, (or from whatever has your data that you want to change.)
In my case, it was user profile data that I was wanting to amend. This was stored on a SQL server and there was a call to a PHP routine (not shown below) that populated all the variables with the existing user data.
The software that takes the user amended data expects specific variables to be filled with the amended data. So, for example, the existing users name is supplied to the page in the variable $newname - the program that recieves the completed form will expect the user-amended data to be in the 'newname' variable.
IT is slightly confusing here because both variables have similar names. Typically, the data will come from a SQL query that has served up a field called "Username" in a php variable called $row['username'] or something. The receiving form will expect the data in a different variable... perhaps called modifiedname or something.
Anyway, my form looked something like this...
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
<form name="modifyprofil" enctype="multipart/form-data" method="post" action=”http://www.mywebsite.com/my_page_that_validates_and_saves_the_data.php">
Name:<br>
<input type="text" name="newname" maxlength="50" size="50" value="<?php echo $newname; ?>"><br><br>
Email<br>
<input type="text" name="newemail" maxlength="50" size="50" value="<?php echo $newemail; ?>"><br><br>
Enter your Town:<br>
<input type="text" name="newcustom1" maxlength="250" size="50" value="<?php echo $newcustom1; ?>"><br><br>
Enter your Country:<br>
<input type="text" name="newcustom3" maxlength="250" size="50" value="<?php echo $newcustom3; ?>"><br><br>
Enter your extended description: <br>
<textarea id="newcustom6" name="newcustom6"><?php echo $newcustom6;?></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'newcustom6' );
</script>
<input type="submit" value="Save Changes">
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Some explanation is needed here….
The page was supplied with the data to be amended in the form of PHP variables $newname, $newemail, $newcustom1… etc.
The page that receives the user modified data expects the variables newname, newemail, newcustom1… etc. to be filled with the user modified data.
The bit of code <?php echo $newname; ?> fills in the form with the existing value of the (in this case) name. Ditto for all the other fields.
The mistake that I made was that I called the Textarea… “Textarea1” as was shown in the examples. I SHOULD have called it “newcustom6” – because it is the contents of newcustom6 that is posted back to the database.
Hopefully that makes sense.
If anyone needs any help with this – just let me know.
Philip.