Forum Moderators: coopster
The validate() function is defined like the following
if(document.inputform.subject.value != ""){
above is "subject" and in my subject input field info I add onblur="javascript:validate();" to check it.
The issue is when I get down to the HTML editor(called with PHP)
<?php include("FCKeditor/fckeditor.php") ;?>
<?php
$oFCKeditor = new FCKeditor('fckeditor') ;
$oFCKeditor->BasePath = './FCKeditor/';
$oFCKeditor->Value = $text;
$oFCKeditor->Create() ;
?>
I tried a few things that didn't work, but I wanted to see if anyone knew how I might be able to create a formfield that can be validated like "subject" above but using the editor. The field name is defined in the php as "fckeditor". Thank you
You can use javascript to check for the value of fckeditor field and it should work as normal for other fields since the field should be within the same form
I posted about the T_ELSE error I was getting with the php validation, and I finally cleared that up but the code after the php validation was being executed instead of showing the form again on error.
The code isn't that long, would someone mind to take a look at it? I am at a total loss as to what exactly it needs so the mail isn't sent after it displays what errors need to be corrected? Thank you!
<p id="sectionTitle"><?php echo PAGETITLE_SEND_NEWSLETTER ?></p>
<p><a href="index.php?page=../massemail/mass_email_admin_menu" class="linkBg">« Back</a></p>
<?php
require_once "../include/Validator.php";
if ($HTTP_POST_VARS){
$validator = new Validator();
$validator->validateGeneral($HTTP_POST_VARS['subject'], NEWSLETTER_VAL_SUBJECT);
$validator->validateGeneral($HTTP_POST_VARS['text_message'], NEWSLETTER_VAL_TEXT);
$validator->validateGeneral($HTTP_POST_VARS['fckeditor'], NEWSLETTER_VAL_EDITOR);if ( $validator->foundErrors() ){
echo '<b style="color:#C92E2A; font-size:12px;"> '. ERROR_PLEASE_INSERT .' </b> <br /><i>'.$validator->listErrors('<br>').'</i><br><br /><br /><br /> <a href="index.php?page=../massemail/new2" class="linkBg">« Back - show form again</a>';
}else{
//echo "<p><a href=\"index.php?page=../massemail/new2\" class=\"linkBg\">« Back - show form again</a></p>";
}
}
?>
<?php
require_once 'system_data.php';
$query = "select fname,email from newsletter where status='1'";
$result = mysql_query($query) or die(mysql_error());if (0 == mysql_num_rows($result))
{
echo "<p>".SEND_NEWSLETTER_EMPTY_SUBSCRIBERS_LIST."</p>";
}
else
{
if (isset($_POST['submit']))
{while (list($full_name,$email) = mysql_fetch_row($result))
{################################################## ##################################################
################################################## ##################################################//** load email class definition.
include('class.Email.php');
//** establish to,from, and any other recipiants.
$Sender = "". $site_name . "<" . $admin_email . ">";
$Cc = "";
$Bcc = "";//** create the text and HTML versions of the body content here.
$textVersion = "Dear " . stripslashes(str_replace('_', ' ', $full_name)) . ",\n\r";
$textVersion .= stripslashes($_POST['text_message']);
$textVersion .="\n\r----- *** Notice *** -----\n\r";
$textVersion .= "If you don't wish to receive our newsletter anymore, please click the link below for safe and permanent unsubscription.\n\r";
$textVersion .= $websiteUrl . "/massemail/confirm.php?action=remove&email=" . $email;$htmlVersion = "<html>";
$htmlVersion .= "<head>";
$htmlVersion .= "Dear " . stripslashes(str_replace('_', ' ', $full_name)) . ",<br><br>\r\n\r\n";
$htmlVersion .= $_POST['fckeditor'];
$htmlVersion .="<br><br>----- *** Notice *** -----<br><br>\r\n\r\n";
$htmlVersion .= "If you don't wish to receive our newsletter anymore, please click the link below for safe and permanent unsubscription.<br><br>\r\n\r\n";
$htmlVersion .= "<a href='$websiteUrl/massemail/confirm.php?action=remove&email=$email'>$websiteUrl/massemail/confirm.php?action=remove&email=$email</a>";
$htmlVersion .= "</html>";unset($msg);
//** ! SEND A MULTIPART/ALTERNATIVE EMAIL !
//** create the new message using the to, from, and email subject.////// $msg = new Email($email, stripslashes($_POST['subject']). " - " . date("l \\t\h\e jS"));
$msg = new Email($email, $Sender, stripslashes($_POST['subject']));
$msg->Cc = $Cc;
$msg->Bcc = $Bcc;//** set the message to be a multiprat/alternative email. This allows for
//** multiple versions of same content.
//** NOTE: you cannot send attachments when a message is set to be
//** multipart/alternative. there is also no way to switch
//** back to normal multipart/mixed after this call.$msg->SetMultipartAlternative($textVersion, stripslashes($htmlVersion));
//** send the email message.
$SendSuccess = $msg->Send();
echo "Multipart/alternative email was ",
($SendSuccess ? "sent" : "not sent"), "<br>";################################################## ##################################################
################################################## ##################################################}
echo "<b>".SEND_NEWSLETTER_SUCCESS."</b>";
}
else
{
?>
<?php print "" . $_POST['fckeditor'] . "" ?>
<form action="<?php "" .$_SERVER['PHP_SELF']. "" ?>" method="post">
<p><b><?php echo SEND_NEWSLETTER_SUBJECT ?></b><br />
<input type='text' name='subject' size="65" class="field" />
<input type='hidden' name='action' value="send" />
</p>Text Version:<br /><textarea autocomplete="off" name="text_message" style="width: 100%; height: 200px"></textarea>
<p><b><?php echo SEND_NEWSLETTER_MESSAGE ?> </b><br />
<?php
include("FCKeditor/fckeditor.php") ;
?>
<?php
$oFCKeditor = new FCKeditor('fckeditor') ;
$oFCKeditor->BasePath = './FCKeditor/';
$oFCKeditor->Value = $text;
$oFCKeditor->Create() ;
?></p>
<p class="submit"><input type='submit' name='submit' value='<?php echo BUTTON_SEND_NEWSLETTER ?>' class="buttons" /></p>
</form>
<?php
}
}
?>
a - do not use HTTP_POST_VARS instead use $_POST
Rough Algo:
BEGIN
CHECK IF THE FORM IS SUBMITTED
IF YES THEN
1 - validate form
IF errors found THEN
a) show error messages
b) show form
END IF
ELSE IF ERRORS NOT FOUND
SEND EMAIL
END ELSE
ELSE IF form not submitted
SHOW FORM
END ELSE
END IF
if you get my algorithm then put the form within a function and make a function call to display the form this way you wont write the same code twice within IF conditions but just a function which will display the form wherever required.
I hope that helps
thanks for the logic model, I'll see what I can come up with.