News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Notification for Topics posted through a webform

Started by floppy01, February 04, 2007, 03:50:06 PM

Previous topic - Next topic

floppy01

SMF Version: SMF 1.1.1
First of all a big hi to everybody!

This Comunity was great help over the last weeks. But nevertheless there is still one big unsolved issue for me .
I am using SMF 1.1.1 with Dilber MC Theme.

With the help of many posts in this forum I suceeded in creating a webform which allows me to collect data from people and post it into a certain board on my forum. Everything is working fine except that notification doesnt work in this board. Ive read that the function NotifyMembersBoard() should bring the forum to send notifications, but dont know how to call the function as I always get error messages when trying so.

For all people that like to see the whole code necessary to post into a smf forum from outside (including checking whether necessary fields are filled in, redirecting a.s.o) and others to understand how they could may help me here is the code:

First of all the inputform - Fieldnames are in German but thats not important :) :



<form action="" method="POST">

<table width="450" border="0" cellspacing="0" cellpadding="0">

<tr>
<?php error_bool($error, "subject"); ?>Das Bundesland indem sich die Baustelle befindet:*</td>
<td><select name="recipient" size="1" >
 
  //the option values are the board ids


  <option value="26" >Nieder&ouml;sterreich </option>
  <option value="27">Ober&ouml;sterreich</option>
  <option value="28">Salzburg</option>
  <option value="29">Steiermark</option>
  <option value="30">Tirol</option>
  <option value="31">Wien</option>
  <option value="38" >Mein Bundesland befindet sich nicht in der Liste </option>
</select>
</td>
</tr>


    <tr>
     <?php error_bool($error, "subject"); ?> Thema/Produkt:* </td>
      <td><input name="subject" type="text" id="subject" size="40" value="<? echo $_POST["subject"]; ?>"></td>
    </tr>


    <tr>
     <?php error_bool($error, "name"); ?> Ihr Name:* </td>
      <td><input name="name" type="text" id="name" size="40" value="<? echo $_POST["name"]; ?>"></td>
    </tr>

<tr><td><em>Wohnadresse:</em></td>
</tr>
<tr>
     <?php error_bool($error, "strasse"); ?> Strasse:* </td>
      <td><input name="strasse" type="text" id="strasse" size="40" value="<? echo $_POST["strasse"]; ?>"></td>
    </tr>

  <tr>
     <?php error_bool($error, "plz"); ?> PLZ:* </td>
      <td><input name="plz" type="text" id="plz" size="20" value="<? echo $_POST["plz"]; ?>"></td>
    </tr>



  <tr>
     <?php error_bool($error, "ort"); ?> Ort:* </td>
      <td><input name="ort" type="text" id="ort" size="40" value="<? echo $_POST["ort"]; ?>"></td>
    </tr>


<tr><td><em>Baustellenadresse</em> (wenn abweichend von Wohnadresse):</td>
</tr>


<tr>
<td>BStrasse:</td>
<td><input name="BStrasse" type="text" size="40" align="top" /> </td>
</tr>

<tr>
<td>BPLZ:</td>
<td><input name="BPlz" type="text" size="20" /> </td>
</tr>


<tr>
<td>BOrt:</td>
<td><input name="BOrt" type="text" size="40" /> </td>
</tr>


<tr><td></td></tr>

  <tr>
     <?php error_bool($error, "tel"); ?> Telefon:* </td>
      <td><input name="tel" type="text" id="tel" size="25" value="<? echo $_POST["tel"]; ?>"></td>
    </tr>


  <tr>
     <?php error_bool($error, "email"); ?> Email:* </td>
      <td><input name="email" type="text" id="email" size="25" value="<? echo $_POST["email"]; ?>"></td>
    </tr>


<tr><td> <em>Wünsche:</em> </td>
</tr>


  <tr>
<td>Mein Ofen sollte fertig sein am:</td>
<td><input name="OfenFertigAm"  size="25" /></td>
</tr>


<tr><td><em>Ich möchte:</em></td>
</tr>


<tr>
<td>Infomaterial:</td>
<td>  <input name="infom" type="checkbox" value="Info-Material" $sf_infom /></td>
<tr>


    <tr>
<td>Beratungsgespräch: </td>
<td><input type="checkbox" name="uvberatung" value="unverbindliche Beratung" $sf_uvberatung /></td>
</tr>

<tr><td></td></tr>


<tr>
<td>Mein zusätzliches Kommentar:</td>
<td> <textarea name="comment" cols="35" rows="3"></textarea></td>
</tr>

<tr><td> <em>Fertigstellen:</em> </td>
</tr>

    <tr>
      <td><input type="submit" name="Submit" value="Anfrage abschicken"></td>
        <td><input type="reset" name="Reset" value="Formular zurücksetzen"></td>

      <td> </td>
    </tr>



  </table>


<p>Mit * gekennzeichnete Felder m&uuml;ssen ausgef&uuml;llt werden. </p>
</form>





Secondly - The Functions:




<?
}
if(isset($_POST["Submit"])) {
    check_form();
} else {
    show_form();
}

function check_email_address($email) {
  // First, we check that there's one @ symbol, and that the lengths are right
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
     if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
      return false;
    }
  }
  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}


function check_form()
{
global $HTTP_POST_VARS, $error, $print_again;
$error['name'] = false;
    if($_POST["name"]=="") {
        $error['name'] = true;
         $print_again = true;
        $message.="<p>Field Name is empty</p>";
    }


$error['recipient'] = false;
    if($_POST["recipient"]=="0") {
        $error['recipient'] = true;
         $print_again = true;
        $message.="<p>Please choose your country</p>";
    }



$error['subject'] = false;
    if($_POST["subject"]=="") {
        $error['subject'] = true;
         $print_again = true;
        $message.="<p>Field Thema is empty</p>";
    }

$error['strasse'] = false;
    if($_POST["strasse"]=="") {
        $error['strasse'] = true;
         $print_again = true;
        $message.="<p>Field street is empty</p>";
    }

//and so on ....

    if(!check_email_address($_POST['email'])) {
        $error['email'] = true;
         $print_again = true;
        $message.="<p>Sie haben vergessen Ihre Emailadresse anzugeben, oder sie wurde nicht korrekt eingegeben </p>";
    }
     if($print_again) {
         show_form();
       
       } else {
   
//everthing is filled in:   
     
           $message="<p>Vielen Dank! <br>
   All fields are filled in. <br>
        Your request has been sent!<br></p>";



include_once('./smf/SSI.php');
require_once('./smf/Sources/Post.php');
require_once('./smf/Sources/Subs-Post.php');


// take an htmlized $txt and turn it into a smf compatible msg
// no cr lf, no html tags, <br> turned into <br /> and <p>  made into <br /><br />
function prepBody( $txt)
{
// cr lf to spaces
$txt = str_replace( "\r", ' ', $txt);
$txt = str_replace( "\n", ' ', $txt);

// reduce blank spaces
$txt = preg_replace( '/[ ][ ]+/', ' ', $txt);

// turn <br> or <br /> into \n
$txt = preg_replace( '!\s*<br(\s*/)?>\s*!i', "\n", $txt);

// turn <p ...> and <p> into \n\n
$txt = preg_replace( '/\s*<p([^>]+|)>\s*/i', "\n\n", $txt);

// mercilessly strip all other html
$txt = preg_replace( '/<[^>]+>/', '', $txt);
$txt = preg_replace( '!</[a-z]+>!i', '', $txt);

// turn \n back to <br />
$txt = str_replace( "\n", '<br />', trim( $txt));

return addslashes($txt);
}


//prepare string

$msgBody = "Thema der Anfrage: " .$_POST['subject'] . "<br />"."<br />"."<br />"." Name: ".$_POST['name']. "<br />"."<br />" ."Wohnadresse: ". $_POST['strasse']." , ".$_POST['plz']." ".$_POST['ort']."<br />"."<br />".
"Baustellenadresse: ".$_POST['BStrasse']." , ".$_POST['BPlz']."  ".$_POST['BOrt']."<br />"."<br />".


"TelNr: ".$_POST['tel']. "<br />". "email: ". $_POST['email']."<br />"."<br />"."Wünsche: ".$_POST['infom']." , ".$_POST['uvberatung']."<br />"."<br />"."Zusätzliches Kommentar: ".$_POST['comment'];

$msgBody = prepBody( $msgBody);



//createpost() function



$topicOptions = array(
'id' => 0,   // 0 = New Topic otherwise Topic id to reply..
'board' => $forummsg['board'] = $_POST['recipient'],  //What board to post on.. User doesn't even need rights to view it..
'mark_as_read' => false,
);
$posterOptions = array(
'id' => $ID_MEMBER = 42,
'name' => $forummsg['name'] = $_POST['name'],
'email' => $forummsg['email']= $_POST['email'],
'ip' => $forummsg['IP'] = getenv('REMOTE_ADDR'),
'update_post_count' => true,
);
$msgOptions = array(
'id' => 0,
'subject' => $forummsg['title'] = "Anfrage: ". $_POST['subject'] . " von " .$_POST['name'],
'body' => $forummsg['body'] = $msgBody,
);

//$board = $_POST['recipient']
//$newTopic = empty($topic) || $topic == 0;

createPost ($msgOptions,$topicOptions,$posterOptions);

//the following part unfortunately doesnt work!!!!

    //if (isset($topicOptions['id']))
//$topic = $topicOptions['id'];
//if ($newTopic)
//notifyMembersBoard($board);
//else
//sendNotifications($topic, 'reply');

//redirectexit('topic=' . $topic);
   
}



echo "$message";




       }
   


?>







Could anyone help to implement the notifymembersboard function in this context. In the way that people that requested notification of the specific boards get one if someone posts from the webform.

Many thanks in advance!!! I hope the code is additionally helping someone searching for such functionality.

:) floppy

floppy01

Isn't there anyone who can help or least explain how to call the notifymembersboard() function correctly?

Many thanks!

floppy

SleePy

floppy01,

Where you able to solve this?

Did you look at the function database for more information on how to use this function correctly?
Jeremy D ~ Site Team / SMF Developer ~ GitHub Profile ~ Join us on IRC @ Libera.chat/#smf ~ Support the SMF Support team!


Advertisement: