Skriv ut ämne
?nskar pyttelite php-kodningshj?lp
etxgmg
Hej

K?r pirdanis MailToAll infusion p? en v7.00.07 sajt. I denna finns en funktion som kollar f?ltet f?r ?mne (subject).

Idag testar den bara f?r att n?got ?r ifyllt, men jag vill att den ?ven testar f?r att det inte ?r mer ?n 54 tecken ifyllda. (Om det ?r mer ?n 54 tecken i ?mnet s? skickas n?mligen inte mejlet och ingen f?r n?got beskede om detta!)

Kan n?gon v?nlig och PHP-kodningskunnig sj?l hj?lpa mig med att l?gga till 54-teckentestet till if-satsen i nedan funktion?

function ValidateForm(frm) {
if(frm.subject.value=='') {
alert('".$locale['mta116']."');
return false;
}
}
 
DrunkeN
Hur ser hela koden ut ?
HobbySite.nu
"Bättre att vara långsam och noggrann än att ha bråttom och slarva"
 
etxgmg
Fast jag har nog tidigare varit inne och moddat andra saker i denna:

<?php
/*---------------------------------------------------+
| PHP-Fusion 7 Content Management System
+----------------------------------------------------+
| Copyright ? 2002 - 2008 Nick Jones
| http://www.php-fu...
+----------------------------------------------------+
| Released under the terms & conditions of the
| GNU Affero GPL v3.
+----------------------------------------------------*/
require_once "../../maincore.php";
require_once THEMES."templates/admin_header.php";
require_once INCLUDES."sendmail_include.php";

if (!checkrights("IP")) redirect("../index.php");

if (file_exists(INFUSIONS."pd_mailtoall/locale/".$settings['locale'].".php")) {
include_once INFUSIONS."pd_mailtoall/locale/".$settings['locale'].".php";
} else {
include_once INFUSIONS."pd_mailtoall/locale/English.php";
}

if (isset($_POST['send']))
{
$subject = stripslash($_POST['subject']);
if ($_POST['format'] == "plain") {
$content = stripslash($_POST['content']);
} else if ($_POST['format'] == "html") {
$content = "<html>
<head>
<style type=\"text/css\">
<!--
a { color: #0000ff; text-decoration:none; }
a:hover { color: #0000ff; text-decoration: underline; }
body { font-family:Verdana,Tahoma,Arial,Sans-Serif; font-size:10px; }
p { font-family:Verdana,Tahoma,Arial,Sans-Serif; font-size:10px; }
.td { font-family:Verdana,Tahoma,Arial,Sans-Serif; font-size:10px; }
-->
</style>
</head>
<body>
".stripslashes($_POST['content'])."
</body>
</html>";
}
//Send to
$msg_to_group = $_POST['msg_to_group'];
if ($msg_to_group == "101" || $msg_to_group == "102" || $msg_to_group == "103")
{
$result = dbquery("SELECT user_name, user_email FROM ".DB_USERS." WHERE user_level>='".$msg_to_group."'");
while ($data = dbarray($result))
{
sendemail($data['user_name'],
$data['user_email'],
$settings['siteusername'],
$settings['siteemail'],
$subject,
$content,
$_POST['format'],
$cc="",
$bcc="");
}
} else {
$result = dbquery("SELECT user_name, user_email FROM ".DB_USERS." WHERE user_groups REGEXP('^\\\.{$msg_to_group}$|\\\.{$msg_to_group}\\\.|\\\.{$msg_to_group}$')");
while ($data = dbarray($result))
{
sendemail($data['user_name'],
$data['user_email'],
$settings['siteusername'],
$settings['siteemail'],
$subject,
$content,
$_POST['format'],
$cc="",
$bcc="");
}
}


opentable($locale['mta101']);
echo "<center><br />\n";
$error = "";
if (!$error) {
echo ($locale['mta102']),"<br /><br />\n";
} else {
echo ($locale['mta103']),"<br /><br />\n".$error."<br /><br />\n";
}
echo "<a href='mailtoall.php'>".$locale['mta104']."</a><br /><br />
<a href='".ADMIN."index.php'>".$locale['mta105']."</a><br /><br />
</center>\n";
closetable();
}
if (isset($_POST['preview'])) {
$subject = phpentities(stripslash($_POST['subject']));
$content = phpentities(stripslash($_POST['content']));
$plain = ($_POST['format'] == "plain" ? " checked" : "");
$html = ($_POST['format'] == "html" ? " checked" : "");
if ($_POST['format'] == "plain") {
$contentpreview = nl2br(stripslash($_POST['content']));
} else {
$contentpreview = stripslash($_POST['content']);
}
opentable($subject);
echo "$contentpreview\n";
closetable();
tablebreak();
}

if (!isset($_POST['preview'])) {
$subject = "";
$content = "";
$html = "";
$plain = " checked";
}

if (isset($_POST['listaddr'])) {
$msg_to_group = $_POST['msg_to_group'];
if ($msg_to_group == "101" || $msg_to_group == "102" || $msg_to_group == "103") {
$result = dbquery("SELECT user_name, user_email FROM ".DB_USERS." WHERE user_level>='".$msg_to_group."'");
}
else {
$result = dbquery("SELECT user_name, user_email FROM ".DB_USERS." WHERE user_groups REGEXP('^\\\.{$msg_to_group}$|\\\.{$msg_to_group}\\\.|\\\.{$msg_to_group}$')");
}
while ($data = dbarray($result))
{
echo $data['user_email'];
echo ";";
echo "<br>";
}
}
$action = FUSION_SELF;
//Usergroups & Levels
$user_groups = getusergroups();
$user_types = "";
while(list($key, $user_group) = each($user_groups)){
if ($user_group['0'] != "0") {
$sel = ($msg_to_group = $user_group['0'] ? " selected" : "");
$user_types .= "<option value='".$user_group['0']."'$sel>".$user_group['1']."</option>\n";
}
}

opentable($locale['mta106']);
echo "<form name='inputform' method='post' action='$action' onSubmit='return ValidateForm(this)'>
<table align='center' cellspacing='0' cellpadding='0' class='tbl'>
<tr>
<td width='100'>".$locale['mta107']."</td>
<td><select name='msg_to_group' class='textbox'>\n".$user_types."</select></td>
</tr>
<tr>
<td width='100'>".$locale['mta108']."</td>
<td><input type='text' name='subject' value='$subject' class='textbox' style='width:250px;'></td>
</tr>
<tr>
<td valign='top' width='100'>".$locale['mta109']."</td>
<td><textarea name='content' cols='95' rows='15' class='textbox'>$content</textarea></td>
</tr>
<tr>
<td>".$locale['mta110']."</td>
<td>
<input type='button' value='p' class='button' style='font-weight:bold;width:25px;' onClick=\"addText('content', '<p>', '</p>');\">
<input type='button' value='br' class='button' style='font-weight:bold;width:25px;' onClick=\"insertText('content', '<br />');\">
<input type='button' value='b' class='button' style='font-weight:bold;width:25px;' onClick=\"addText('content', '<b>', '</b>');\">
<input type='button' value='i' class='button' style='font-style:italic;width:25px;' onClick=\"addText('content', '<i>', '</i>');\">
<input type='button' value='u' class='button' style='text-decoration:underline;width:25px;' onClick=\"addText('content', '<u>', '</u>');\">
<input type='button' value='link' class='button' style='width:35px;' onClick=\"addText('content', '<a href=\'http://\' target=\'_blank\'>', '</a>');\">
<input type='button' value='img' class='button' style='width:35px;' onClick=\"insertText('content', '<img src=\'".$settings['siteurl']."fusion_images/\' style=\'margin:5px;\' align=\'left\'>');\">
<input type='button' value='center' class='button' style='width:45px;' onClick=\"addText('content', '<center>', '</center>');\">
<input type='button' value='small' class='button' style='width:40px;' onClick=\"addText('content', '<span class=\'small\'>', '</span>');\">
<input type='button' value='small2' class='button' style='width:45px;' onClick=\"addText('content', '<span class=\'small2\'>', '</span>');\">
<input type='button' value='alt' class='button' style='width:25px;' onClick=\"addText('content', '<span class=\'alt\'>', '</span>');\">
</td>
</tr>
<tr>
<td><br />".$locale['mta111']."</td>
<td><br /><input type='radio' name='format' value='plain'$plain>".$locale['mta112']." <input type='radio' name='format' value='html'$html>".$locale['mta113']."</td>
</tr>
<tr>
<td align='center' colspan='2'><br />
<input type='submit' name='preview' value='".$locale['mta114']."' class='button'>
<input type='submit' name='send' value='".$locale['mta115']."' class='button'>
<input type='submit' name='listaddr' value='Lista valda mejladresser' class='button'>
</td>
</tr>
</table>
</form>\n";
closetable();
echo "<script language=\"JavaScript\">
function ValidateForm(frm) {
if(frm.subject.value=='') {
alert('".$locale['mta116']."');
return false;
}
}
</script>\n";


require_once THEMES."templates/footer.php";
?>
 
DrunkeN
vet inte om detta funkar men prova iallafall
Kod Källa  

<?php
/*---------------------------------------------------+
| PHP-Fusion 7 Content Management System
+----------------------------------------------------+
| Copyright ? 2002 - 2008 Nick Jones
| http://www.php-fu...
+----------------------------------------------------+
| Released under the terms & conditions of the
| GNU Affero GPL v3.
+----------------------------------------------------*/
require_once "../../maincore.php";
require_once THEMES."templates/admin_header.php";
require_once INCLUDES."sendmail_include.php";

if (!checkrights("IP")) redirect("../index.php");

if (file_exists(INFUSIONS."pd_mailtoall/locale/".$settings['locale'].".php")) {
include_once INFUSIONS."pd_mailtoall/locale/".$settings['locale'].".php";
} else {
include_once INFUSIONS."pd_mailtoall/locale/English.php";
}

if (isset($_POST['send']))
{
$subject = stripslash($_POST['subject']);
if ($_POST['format'] == "plain") {
$content = stripslash($_POST['content']);
} else if ($_POST['format'] == "html") {
$content = "<html>
<head>
<style type=\"text/css\">
<!--
a { color: #0000ff; text-decoration:none; }
a:hover { color: #0000ff; text-decoration: underline; }
body { font-family:Verdana,Tahoma,Arial,Sans-Serif; font-size:10px; }
p { font-family:Verdana,Tahoma,Arial,Sans-Serif; font-size:10px; }
.td { font-family:Verdana,Tahoma,Arial,Sans-Serif; font-size:10px; }
-->
</style>
</head>
<body>
".stripslashes($_POST['content'])."
</body>
</html>";
}
//Send to   
$msg_to_group = $_POST['msg_to_group'];
if ($msg_to_group == "101" || $msg_to_group == "102" || $msg_to_group == "103")
{
$result = dbquery("SELECT user_name, user_email FROM ".DB_USERS." WHERE user_level>='".$msg_to_group."'");
while ($data = dbarray($result))
{
sendemail($data['user_name'],
$data['user_email'],
$settings['siteusername'],
$settings['siteemail'],
$subject,
$content,
$_POST['format'],
$cc="",
$bcc="");
}
} else {
$result = dbquery("SELECT user_name, user_email FROM ".DB_USERS." WHERE user_groups REGEXP('^\\\.{$msg_to_group}$|\\\.{$msg_to_group}\\\.|\\\.{$msg_to_group}$')");
while ($data = dbarray($result))
{
sendemail($data['user_name'],
$data['user_email'],
$settings['siteusername'],
$settings['siteemail'],
$subject,
$content,
$_POST['format'],
$cc="",
$bcc="");
}
}


opentable($locale['mta101']);
echo "<center><br />\n";
$error = "";
if (!$error) {
echo ($locale['mta102']),"<br /><br />\n";
} else {
echo ($locale['mta103']),"<br /><br />\n".$error."<br /><br />\n";
}
echo "<a href='mailtoall.php'>".$locale['mta104']."</a><br /><br />
<a href='".ADMIN."index.php'>".$locale['mta105']."</a><br /><br />
</center>\n";
closetable();
}
if (isset($_POST['preview'])) {
$subject = phpentities(stripslash($_POST['subject']));
$content = phpentities(stripslash($_POST['content']));
$plain = ($_POST['format'] == "plain" ? " checked" : "");
$html = ($_POST['format'] == "html" ? " checked" : "");
if ($_POST['format'] == "plain") {
$contentpreview = nl2br(stripslash($_POST['content']));
} else {
$contentpreview = stripslash($_POST['content']);
}
opentable($subject);
echo "$contentpreview\n";
closetable();
tablebreak();
}

if (!isset($_POST['preview'])) {
$subject = "";
$content = "";
$html = "";
$plain = " checked";
}

if (isset($_POST['listaddr'])) {
$msg_to_group = $_POST['msg_to_group'];
if ($msg_to_group == "101" || $msg_to_group == "102" || $msg_to_group == "103") {
$result = dbquery("SELECT user_name, user_email FROM ".DB_USERS." WHERE user_level>='".$msg_to_group."'");
}
else {
$result = dbquery("SELECT user_name, user_email FROM ".DB_USERS." WHERE user_groups REGEXP('^\\\.{$msg_to_group}$|\\\.{$msg_to_group}\\\.|\\\.{$msg_to_group}$')");
}
while ($data = dbarray($result))
{
echo $data['user_email'];
echo ";";
echo "<br>";
}
}
$action = FUSION_SELF;
//Usergroups & Levels
$user_groups = getusergroups();
$user_types = "";
while(list($key, $user_group) = each($user_groups)){
if ($user_group['0'] != "0") {
$sel = ($msg_to_group = $user_group['0'] ? " selected" : "");
$user_types .= "<option value='".$user_group['0']."'$sel>".$user_group['1']."</option>\n";
}
}

opentable($locale['mta106']);
echo "<form name='inputform' method='post' action='$action' onSubmit='return ValidateForm(this)'>
<table align='center' cellspacing='0' cellpadding='0' class='tbl'>
<tr>
<td width='100'>".$locale['mta107']."</td>
<td><select name='msg_to_group' class='textbox'>\n".$user_types."</select></td>
</tr>
<tr>
<td width='100'>".$locale['mta108']."</td>
<td><input type='text' name='subject' value='$subject' maxlength='54' class='textbox' style='width:250px;'></td>
</tr>
<tr>
<td valign='top' width='100'>".$locale['mta109']."</td>
<td><textarea name='content' cols='95' rows='15' class='textbox'>$content</textarea></td>
</tr>
<tr>
<td>".$locale['mta110']."</td>
<td>
<input type='button' value='p' class='button' style='font-weight:bold;width:25px;' onClick=\"addText('content', '<p>', '</p>');\">
<input type='button' value='br' class='button' style='font-weight:bold;width:25px;' onClick=\"insertText('content', '<br />');\">
<input type='button' value='b' class='button' style='font-weight:bold;width:25px;' onClick=\"addText('content', '<b>', '</b>');\">
<input type='button' value='i' class='button' style='font-style:italic;width:25px;' onClick=\"addText('content', '<i>', '</i>');\">
<input type='button' value='u' class='button' style='text-decoration:underline;width:25px;' onClick=\"addText('content', '<u>', '</u>');\">
<input type='button' value='link' class='button' style='width:35px;' onClick=\"addText('content', '<a href=\'http://\' target=\'_blank\'>', '</a>');\">
<input type='button' value='img' class='button' style='width:35px;' onClick=\"insertText('content', '<img src=\'".$settings['siteurl']."fusion_images/\' style=\'margin:5px;\' align=\'left\'>');\">
<input type='button' value='center' class='button' style='width:45px;' onClick=\"addText('content', '<center>', '</center>');\">
<input type='button' value='small' class='button' style='width:40px;' onClick=\"addText('content', '<span class=\'small\'>', '</span>');\">
<input type='button' value='small2' class='button' style='width:45px;' onClick=\"addText('content', '<span class=\'small2\'>', '</span>');\">
<input type='button' value='alt' class='button' style='width:25px;' onClick=\"addText('content', '<span class=\'alt\'>', '</span>');\">
</td>
</tr>
<tr>
<td><br />".$locale['mta111']."</td>
<td><br /><input type='radio' name='format' value='plain'$plain>".$locale['mta112']." <input type='radio' name='format' value='html'$html>".$locale['mta113']."</td>
</tr>
<tr>
<td align='center' colspan='2'><br />
<input type='submit' name='preview' value='".$locale['mta114']."' class='button'>
<input type='submit' name='send' value='".$locale['mta115']."' class='button'>
<input type='submit' name='listaddr' value='Lista valda mejladresser' class='button'>
</td>
</tr>
</table>
</form>\n";
closetable();
echo "<script language=\"JavaScript\">
function ValidateForm(frm) {
if(frm.subject.maxlength.value=='') {
alert('".$locale['mta116']."');
return false;
}
}
</script>\n";


require_once THEMES."templates/footer.php";
?>

HobbySite.nu
"Bättre att vara långsam och noggrann än att ha bråttom och slarva"
 
etxgmg
Du ?ndrade bara p? tv? st?llen, va?

F?rutom

"if(frm.subject.value=='') {"

till

"if(frm.subject.maxlength.value=='') {"

s? ?ndrade du

" <td><input type='text' name='subject' value='$subject' class='textbox' style='width:250px;'></td>"

till

"<td><input type='text' name='subject' value='$subject' maxlength='54' class='textbox' style='width:250px;'></td>"

?
 
etxgmg
Nja, detta funkar inte riktigt. Dels testar den nu endast p? maxl?ngden (det g?r inte att fylla i mer ?n 54 tecken, vilket ?r bra; fast den g?r aldrig n?got alert!!! (fast det kvittar kanske)) och inte l?ngre att det ?r n?got ifyllt (den ska n?mligen fortfarande br?ka om man gl?mmer ?mnet, men nu g?r den inte det l?ngre). Dels funkar det inte l?ngre med ??? - fast det beror nog p? att du har en annan editor (med annan teckenupps?ttning) ?n jag - d?rf?r ?r det viktigt att jag inf?r alla ?ndringar sj?lv i min ursprungsfil, och h?ller 100% koll p? alla ?ndringar.

Ska det inte vara n?got typ s? h?r:
if(frm.subject.value=='') OR if(frm.subject.maxlength.value=='') {
alert('".$locale['mta116']."');
return false;
}
 
etxgmg
@DrunkeN. Jag fixade nu allting (tror jag) helt enkelt genom att ta bort din ?ndring i JavaScript-funktionen men beh?lla maxlength='54' i formul?ret. D? fixar JavaScript-funktionen valideringen att n?got v?rde inskrivits, medan formul?rf?ltet i sig stoppar vid 54 tecken.
 
etxgmg
@DrunkeN. Gl?mde s?ga Tusen tack f?r hj?lpen, utan dig hade jag inte l?st detta, ?tminstone inte s? snabbt!
 
DrunkeN
Lugnt :) Bra att du fick ordning p? de :)
HobbySite.nu
"Bättre att vara långsam och noggrann än att ha bråttom och slarva"
 
Gå direkt till forum: