News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Post from website outside smf forum to forum script problem

Started by james78, May 20, 2010, 10:17:12 PM

Previous topic - Next topic

james78

Hi I was given this script kindly by Arantor which i am very grateful for,
there is a html form which posts to this php file which gathers the textfields and textarea and posts to a board on forum which works great and echos out the message  but above this is an error.

Warning: Invalid argument supplied for foreach() in /home/******/public_html/***/forum/Sources/Subs-Post.php on line 2992
This has been posted.

here is the form code on website outside forum
<?php
require('forum/SSI.php');

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>post form test</title>
</head>

<body>

<form action="postform.php" method="post">
<p>Your Name: <input type="text" name="subject" /><br />




<p>Your comments:<br />
<textarea name="message" rows="10" cols="40"></textarea></p>

<p><input type="submit" value="Send it!"></p>
</form>

</body>
</html>


and here is the script that the form posts too which does post to forum just gives that error

<?php
require('forum/SSI.php');
require(
'forum/Sources/Subs-Post.php');

// 0. If the user isn't logged in, boot them.
if (empty($context['user']['id']))
die('Sorry, you must be logged in.');

// 1. Get the subject. Sanitise it.
$_POST['subject'] = empty($_POST['subject']) ? 'No subject' $_POST['subject'];
$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => ''"\n" => ''"\t" => ''));

// 2. Get the main message. I don't know if you're using the bbc editor or not, presuming you are/want to at some stage.
if (!empty($_REQUEST['message_mode']) && isset($_REQUEST['message']))
{
// If we came from WYSIWYG, we need to convert from HTML to bbc, then unhtml it; then push to $_POST for everything else
$_REQUEST['message'] = un_htmlspecialchars(html_to_bbc($_REQUEST['message']));
$_POST['message'] = $_REQUEST['message'];
}

if (!isset(
$_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
$_POST['message'] = 'No message'// this prevents errors in a minute

// 3. Set up the arrays we need for createPost()
$board 2// I don't actually know what board this should be.

$msgOptions = array(
'id' => 0,
'subject' => $_POST['subject'],
'body' => $_POST['message'],
'icon' => 'xx',
'smileys_enabled' => true,
);
$topicOptions = array(
'id' => 0,
'board' => $board// Id # for the board the topic is going into
'mark_as_read' => true,
);
$posterOptions = array(
'id' => $user_info['id'], // everything else can be set from this.
'ip' => $user_info['ip'],
'update_post_count' => true,
);

createPost($msgOptions$topicOptions$posterOptions);

// 4. Tell the user we're done.


echo 'This has been posted.';


?>



could somebody help correct my mistakes or something or if Arantor is around , I would just like to make this work without errors.

I also wanted to ask if this could go to a thankyou page after posted rather than just echo out text and wondered if the form was ment to be written diffrently than i have done.

sorry for all the questions I am trying to learn just keep stumbling over 1 hurdle after another

many thanks in advance

forum version is 2.0 RC3

Allusion

Find this line in the script code:

$board = 2; // I don't actually know what board this should be.


After that line, add this:


// We're coming from SSI, so we have to set this up explicitly.
$board_info = array();
$board_info['parent_boards'] = getBoardParents($board);


Save and upload.

james78

Thankyou that worked a treat.

I also have a more detailed form with more textfields, could someone help me write the code so that like the above script gets the subject and message.

I would like it to get all textfields and enter them as a single message, here is a sample of form code and here is a screenshot of what i mean when it is posted and displayed on forum
<form id="cmatch_form" name="cmatch_form" action="postform.php" method="post">
<table width="530" border="0" cellpadding="5">
  <tr>
    <td><strong>General Details</strong></td>
    <td align="right">&nbsp;</td>
    </tr>
  <tr>
    <td>Title of topic: (eg. Your clan vs Our Clan)</td>
    <td align="right"><input type="text" name="subject" id="subject" /></td>
    </tr>
  <tr>
    <td>Gamer Tag:</td>
    <td align="right"><input type="text" name="cgtag" id="cgtag" /></td>
    </tr>
  <tr>
    <td>Clan Name:</td>
    <td align="right"><input type="text" name="cname" id="cname" /></td>
    </tr>
  <tr>
    <td>Clan Website:</td>
    <td align="right">http://<input type="text" name="cweb" id="cweb" /></td>
    </tr>
  <tr>
    <td>Date Of Proposed Can Match:<br />
(dd/mm/yyyy)</td>
    <td align="right"><input type="text" name="cdate" id="cdate" /></td>
    </tr>
  <tr>
    <td>Time Of Proposed Clan Match</td>
    <td align="right"><input type="text" name="ctime" id="ctime" />
    <select name="ampm" size="1" id="ampm">
    <option value="AM/PM">AM/PM</option>
    <option value="AM">AM</option>
    <option value="PM">PM</option>
  </select></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right">&nbsp;</td>
    </tr>
  <tr>
    <td><strong>Clan Match Details</strong></td>
    <td align="right">&nbsp;</td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right">&nbsp;</td>
    </tr>
  <tr>
    <td>Game Type: (Hardcore/Noral, etc.)</td>
    <td align="right"><input type="text" name="ctype" id="ctype" /></td>
  </tr>
  <tr>
    <td>Game Mode: (S&amp;D, Headquarters, etc.)</td>
    <td align="right"><input type="text" name="cmode" id="cmode" /></td>
    </tr>
  <tr>
    <td>Team Size: (6vs6, 5vs5, etc)</td>
    <td align="right"><input type="text" name="csize" id="csize" /></td>
    </tr>
  <tr>
    <td>Exclusions</td>
    <td align="right"><input type="text" name="cexcl" id="cexcl" /></td>
    </tr>
  <tr>
    <td>Additional Info</td>
    <td align="right"><textarea name="message" id="message" cols="30" rows="5"></textarea></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right">&nbsp;</td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right"><input type="submit" value="Submit challenge" id="submit_post">
</td>
    </tr>
</table>
</form>


many thanks in advance

Advertisement: