I'm having several problems with FCKeditor. Firstly, I can't figure out how to insert data from FCKEditor into a MYSQL Database. I'm not too well versed in this sort of thing so be easy on me please. Also, my submit button doesn't work. I have a form that needs to email to a list of subscribers using swiftmailer and then also insert into a database. I have the datbase correctly constructed, and swiftmailer was working just fine until I tried to incorporate FCK editor. The form doesn't email or do anything for that matter except refresh itself since I set up FCKEditor. Here's my code below.
Thanks a bunch,
Michael Smith
***Page that User Sees***
<?php require_once('Connections/baseball.php'); ?>
<?php include("fckeditor/fckeditor.php") ; ?>
<?php if (!isset($_SESSION)) { session_start(); } $MM_authorizedUsers = ""; $MM_donotCheckaccess = "true"; // *** Restrict Access To Page: Grant or deny access to this page function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { // For security, start by assuming the visitor is NOT authorized. $isValid = False; // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. // Therefore, we know that a user is NOT logged in if that Session variable is blank. if (!empty($UserName)) { // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. // Parse the strings into arrays. $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } // Or, you may restrict access to only certain users based on their username. if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && true) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "adminlogin.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) $MM_referrer .= "?" . $QUERY_STRING; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?>
<?php $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "news")) { mysql_select_db($database_baseball, $baseball); $Result1 = mysql_query($insertSQL, $baseball) or die(mysql_error()); $insertGoTo = "adminsection.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } //Display an error if something went wrong if (!empty($_GET["error"])) { switch ($_GET["error"]) { case "not_enough_info": ?>
<strong style="color: red;">You need to complete all fields marked *<strong><?php
break;
case "invalid_email": ?>
<strong style="color: red;">Please provide a valid email address</strong><?php
break;
case "upload_failed": ?>
<strong style="color: red;">The file you uploaded failed to attach, this could be a temporary problem.
Please try later.</strong><?php
break;
case "sending_failed": ?>
<strong style="color: red;">Temporary problem, please try later.</strong><?php
break;
}
}
?>
<html>
<head>
<title>:: Colorado American Legion Baseball- Since 1925 ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css"
href="baseball.css" />
</head>
<body>
<TABLE WIDTH=709 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD> <a href="<a href="http://www.calb.org/index.php" target="_blank">http://www.calb.org/index.php</a>"><IMG SRC="../images/home.gif" WIDTH=103 HEIGHT=22 Border=0></a></TD>
<TD> <a href="<a href="http://www.calb.org/Standings.php" target="_blank">http://www.calb.org/Standings.php</a>"><IMG SRC="../images/standings.gif" WIDTH=101 HEIGHT=22 Border=0></a></TD>
<TD> <a href="<a href="http://www.calb.org/schedules.php" target="_blank">http://www.calb.org/schedules.php</a>"><IMG SRC="../images/schedules.gif" WIDTH=113 HEIGHT=22 Border=0></a></TD>
<TD> <a href="<a href="http://www.calb.org/Directions.php" target="_blank">http://www.calb.org/Directions.php</a>"><IMG SRC="../images/field_directions.gif" WIDTH=145 HEIGHT=22 Border=0></a></TD>
<TD> <a href="<a href="http://www.calb.org/Tournaments.php" target="_blank">http://www.calb.org/Tournaments.php</a>"><IMG SRC="../images/tournaments.gif" WIDTH=120 HEIGHT=22 Border=0></a></TD>
<TD> <a href="<a href="http://www.calb.org/coachesoffice.php" target="_blank">http://www.calb.org/coachesoffice.php</a>"><IMG SRC="../images/coaches_office.gif" WIDTH=127 HEIGHT=22 Border=0></a></TD>
</TR>
<TR>
<TD COLSPAN=6> <IMG SRC="../images/calb.gif" WIDTH=709 HEIGHT=128></TD>
</TR>
</TABLE>
<table cellpadding=10 cellspacing=0 border=0 width="475">
<tr>
<td bgcolor="#000066" width="25%">
<!--- Left Navigation -------------------------->
<table cellpadding=0 cellspacing=10 border=0>
<tr>
<td nowrap> <br> <img src="../images/team_registration.gif" alt="" border="0"><br>
<a href="../register.php" class="leftnav">How
to register</a><br> <a href="../registrationforms.php" class="leftnav">Registration
Forms</a> <br> <br> <img src="../images/state_rules.gif" alt="" border="0"><br>
<a href="../baseball_rules.php" class="leftnav">Baseball
Rules</a><br> <a href="../B_and_C_Recruiting_Rules.php" class="leftnav">B
and C Recruiting Rules</a><br> <a href="../Tiebreakers.php" class="leftnav">Tiebreakers</a><br>
<a href="../Tourney_Rules.php" class="leftnav">Tourney
Rules</a> <br> <br> <img src="../images/national_rules.gif" alt="" border="0"><br>
<a href="../National_Baseball_Rules.php" class="leftnav">National
Baseball Rules</a><br> <a href="../National_Tourney_Rules.php" class="leftnav">National
Tourney Rules</a> <br> <br> <img src="../images/coach_bulletins.gif" alt="" border="0"><br>
<a href="../Coach_Calendar.php" class="leftnav">Coach
Calendar</a><br> <a href="../Newsletters.php" class="leftnav">Newsletters</a>
<br> <br> <img src="../images/forms.gif" alt="" border="0"><br>
<!---<a href="../main_page.asp?pdf=n&category=Misc. Legion Forms&page_name=A State History" class="leftnav">A State History</a><br>--->
<a href="../Alcohol_and_Drug_Policy.php" class="leftnav">Alcohol
and Drug Policy</a><br> <a href="../Code_of_Ethics.php" class="leftnav">Code
of Ethics</a><br> <a href="../First_Aid_Kits.php" class="leftnav">First
Aid Kits</a><br> <a href="../Insurance_Application.php" class="leftnav">Insurance
Application</a><br> <a href="../Patch_Order_Form.php" class="leftnav">Patch
Order Form</a><br> <a href="../Scholarships.php" class="leftnav">Scholarships</a><br>
<a href="../Tourney_Ads.php" class="leftnav">Tourney
Ads</a><br> <a href="../Tourney_Host_Agreement.php" class="leftnav">Tourney
Host Agreement</a><br> <a href="../Tourney_Host_Application.php" class="leftnav">Tourney
Host Application</a><br> <a href="../Tourney Host Manual.php" class="leftnav">Tourney
Host Manual</a><br> <a href="../Umpire_Manual.php" class="leftnav">Umpire
Manual</a><br> <a href="../Umpire_Nomination_Form.php" class="leftnav">Umpire
Nomination Form</a> <br> <br> <img src="../images/links.gif" alt="" border="0"><br>
<a href="../Legion_Emblem_Sales.php" class="leftnav">Legion
Emblem Sales</a><br> <a href="../National_Legion_Baseball.php" class="leftnav">National
Legion Baseball</a><br> <a href="../Western_Regional.php" class="leftnav">Western
Regional</a><br> <a href="../World_Series.php" class="leftnav">World
Series</a> <br> <br> <img src="../images/about_calb.gif" alt="" border="0"><br>
<a href="../Leagues_Divisions.php" class="leftnav">CALB
Leagues/Divisions</a><br> <a href="../State_Champions.php" class="leftnav">CALB
State Champions</a><br> <a href="../Commission.php" class="leftnav">Commission</a><br>
<a href="../Contact_Us.php" class="leftnav">Contact
Us</a><br> <a href="../Donations.php" class="leftnav">Donations</a><br>
<a href="../Legion_Baseball_History.php" class="leftnav">Legion
Baseball History</a><br> <a href="../Sponsorship_Opportunities.php" class="leftnav">Sponsorship
Opportunities</a><br> <a href="../Suggestion_Box.php" class="leftnav">Suggestion
Box</a><br>
<!---<a href="<a href="https://www.maxathletix.com/maxPage.asp?page=MaxSite" target="_blank">https://www.maxathletix.com/maxPage.asp?page=MaxSite</a>" target=_blank class="leftnav">Website Developer</a><br>--->
<br /> <a href="../What_Legion_Baseball_Offers.php" class="leftnav">What
Legion Baseball Offers</a>
<br>
<br>
</td>
</tr>
</table>
</td>
<!----- Body ----------------------------->
<td width=30%>
<table align=center border=0 bordercolor="#c9c9c9" cellpadding=0 cellspacing=5 width=525 ID="Table1">
<tr>
<td class=bar><br>
CALB Administration : Administrator
</td>
</tr>
<tr><td height='5' bgcolor=#000066> </td></tr>
</table>
<table align=center border=0 bordercolor="#000066" cellpadding=0 cellspacing=5 width=525>
<tr>
<td width=50%>
<a href="../addevent.php">Add CALB Tournament/Event</a><br>
<a href="../addenews.php">Add Commission Corner Message</a><br>
<a href="../sendenews.php">Send Commission Corner Message</a><br>
<a href="../addcoachcalendar.php">Add Coach Calendar</a><br>
<a href="../addnewsletter.php">Add Newsletter</a><br><br>
<a href="../addcalbtournamentteams.php">Add/Edit CALB Tournament Teams/Results</a><br>
<a href="../adddivisions.php">Add/Edit Legion Divisions</a><br>
<a href="../addleagues.php">Add/Edit Legion Leagues</a><br>
<a href="../addlegionteam.php">Add/Edit Legion Team</a><br>
<a href="../addstatechamps.php">Add/Edit State Champions</a><br>
<a href="addeditwebsitepages.php">Add/Edit Website Pages</a><br>
<br>
</td>
<td width=50%>
<a href="../adminviewsubscribers.php">View CALB News Subscribers</a><br>
<a href="../addevent.php">View/Edit CALB Tournament/Event</a><br>
<a href="../viewcoachcalendar.php">View Coach Calendar Events</a><br>
<a href="../viewcommissioncorner.php">View Commission Corner Messages</a><br>
<a href="../viewnewsletters.php">View Newsletters</a><br>
<a href="../viewcoachesemail.php">View All Coaches Email</a><br><br>
<a href="legion_administration.asp?opt=101&admin=View Current PDF Documents">View PDF Files</a><br>
<a href="uploadpdf.php">Upload PDF Files</a><br><br>
<a href="<?php echo $logoutAction ?>">Log out</a>
</td>
</tr>
<tr><td height='5' bgcolor=#000066 colspan=2> </td></tr>
</table>
<table align=center border=0 bordercolor="#c9c9c9" cellpadding=0 cellspacing=5 width=600 ID="Table2">
<!--DWLayoutTable-->
<tr>
<td class=bar>Add Newsletter<br> </td>
</tr>
<tr>
<td height="500">
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="news" onSubmit="function updateHtml() {
hidden = FCKeditorAPI.__Instances.FCKeditor1.GetHTML();
document.getElementById("hidden").value = hidden;
} ">
<table>
<!--DWLayoutTable-->
<tr>
<td width="102" height="22" class="label">Sender Name</td>
<td width="186"><input type="text" name="sender_name" value="" /></td>
<td width="205"> </td>
</tr>
<tr>
<td height="28" class="label">Sender E-mail address</td>
<td><input type="text" name="sender_email" value="<a href="mailto:info@calb.org" target="_new">info@calb.org</a>" /></td>
<td> </td>
</tr>
<tr>
<td height="22" class="label">Title</td>
<td><input type="text" name="comment_title" value="" /></td>
<td> </td>
</tr>
<tr>
<td height="28" class="label">Attachment (optional)</td>
<td><input type="file" name="attachment" /></td>
<td> </td>
</tr>
<tr>
<td height="356" colspan="3" valign="top">Body of Newsletter<br />
<?php
$oFCKeditor = new FCKeditor('FCKeditor1');
$oFCKeditor->BasePath = '/fckeditor/';
$oFCKeditor->Width = "600";
$oFCKeditor->Height = 400;
$oFCKeditor->Value = '';
$oFCKeditor->Create();
?>
<input name="hidden" type="hidden" value="hidden">
</td>
</tr>
<tr>
<td height="24" colspan="2" valign="top"><input name="Submit" type="submit" value="Submit" /></td>
<td> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="news">
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
<TABLE WIDTH=709 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<tr>
<td align=left><img src="images/footer_Graphic.gif"></td>
</tr>
</table>
<br>
<TABLE WIDTH=709 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<tr>
<td width=25%> </td>
<td width=75% align=center valign=top>
Copyright ? 2006 Colorado American Legion Baseball.<br />
All Rights Reserved.<br />
</td>
</tr>
</table>
<br>
<br>
</body>
</html>
**End**
**SwiftMailer Script--handle_newsletter.php**
<?php
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["sender_name"]) || empty($_POST["sender_email"])
|| empty($_POST["comment_title"]) || empty($_POST["comment_body"]))
{
//redirect back to form
header("Location: <a href="http://www.calb.org/addnewsletter.php");" target="_blank">http://www.calb.org/addnewsletter.php");</a> //This should really be an absolute URL if you know it
exit();
}
//Copy into global variables
$name = $_POST["sender_name"];
$email = $_POST["sender_email"];
$title = $_POST["comment_title"];
$body = $_POST["comment_body"];
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9_\\.-]+/", $email))
{
header("Location: <a href="http://www.calb.org/addnewsletter.php?error=invalid_email");" target="_blank">http://www.calb.org/addnewsletter.php?error=invalid_email");</a>
exit();
}
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if (!empty($_FILES["attachment"]["tmp_name"]))
{
if ($_FILES["attachment"]["error"])
{
//Redirect if the upload has failed
header("Location: <a href="http://www.calb.org/addnewsletter.php?error=upload_failed");" target="_blank">http://www.calb.org/addnewsletter.php?error=upload_failed");</a>
exit();
}
$file_path = $_FILES["attachment"]["tmp_name"];
$file_name = $_FILES["attachment"]["name"];
$file_type = $_FILES["attachment"]["type"];
}
//Everything looks ok, we can start Swift
require_once "swift/Swift.php";
require_once "swift/Swift/Connection/SMTP.php";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//Create a Swift instance
$swift =& new Swift(new Swift_Connection_SMTP("mail.calb.org"));
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
//Create the message to send
$message =& new Swift_Message("New comment: " . $title);
$message->attach(new Swift_Message_Part($body));
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
//Try sending the email
$sent = $swift->send($message, "<a href="mailto:michael@legiondata.org" target="_new">michael@legiondata.org</a>", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
header("Location: <a href="http://www.calb.org/success.php" target="_blank">http://www.calb.org/success.php</a> ");
exit();
}
else
{
header("Location: <a href="http://www.calb.org/addnewsletter.php?error=sending_failed");" target="_blank">http://www.calb.org/addnewsletter.php?error=sending_failed");</a>
exit();
}
?>
<?php error_reporting(E_ALL); ini_set("display_errors", "On"); ?>
**end**
RE: Inserting into MYSQL Database and submit
Legionsmith, In your code you have the line....
$oFCKeditor = new FCKeditor('FCKeditor1') ;
Search for it now so you know what Im talking about...
In the single quotes is the name that FCKeditor will give the textarea. So in your PHP file that catches all the form variables, you should be catching one called FCKeditor1.
You can of course change that name to what ever you want. So if you called it 'content', then your FCKeditor code would look like this....
$oFCKeditor = new FCKeditor('content') ...
... and your PHP script would look like this.. $form_content = $_REQUEST["content"];
Or somthing similar.
If you allow your users to edit stuff they have edited, then you can do the folloeing when your laoding your ediroter page...
$oFCKeditor->Value = $StuffTheyEnteredBefore;
SUBMIT BUTTON---
If the submit button is not working then take it out and use your onw. Aslong as the editor appears within the form element, its contents will be sent to the PHP script you using to catch the variables.
Hope it helps.
http://sosoduko.com
graham@thelondongayscene.co.uk