Forum Moderators: coopster

Message Too Old, No Replies

javascript submit disable works

but one of the form fields is created with php

         

php4U

12:34 am on Mar 20, 2008 (gmt 0)

10+ Year Member



Rather than using the annoying pop-up alerts in javascript, I decided to use some other javascript that disables the submit button until the required fields are filled in. No problem with javascript, so I didn't post there...this is a question of how to validate my editor.

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

phparion

5:05 am on Mar 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if you check your source code of the page your editor field name will be , if i havent forgotten fckeditor, "fckeditor" because you used it in the constructor.

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

php4U

5:56 am on Mar 20, 2008 (gmt 0)

10+ Year Member



Yeah, when I did a basic javascript alert it worked using "fckeditor". I went in and took a look at fckeditor.php where the editor construction takes place. I thought this might be the easier solution to implement, but I added onblur="javascript:validate();" to a few lines there without any success. Now that I think of it, a lot more might might have to go into making this work but I was going this route because I had an issue with the php validation I was working with.

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!

phparion

7:38 am on Mar 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



bring it on the floor!

php4U

3:38 pm on Mar 20, 2008 (gmt 0)

10+ Year Member



Thanks! Here it goes. The form has 3 required fields which are validated at top of the code "subject" "text_version" and "fckeditor". When the fields are blank and submit is pressed, the validation works to show the errors, but I need the form to show again, so the blank fields can be corrected and the mail can be sent. Currently the errors are shown, but the form isn't available again and the rest of the code executes below the validation "if".

<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
}
}
?>

phparion

7:52 pm on Mar 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



your code is a mess dude :( all i can suggest is to write it from scratch with following guideline if possible,

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

php4U

11:03 pm on Mar 20, 2008 (gmt 0)

10+ Year Member



thanks...not all my code though...like $HTTP_POST_VARS was already adapted into the script I am working with (maybe coded in an early version of php 4). Mainly modifying this existing CMS that only allowed simple text format messages to be sent.

thanks for the logic model, I'll see what I can come up with.