News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

another createPost question

Started by nosx, August 26, 2011, 12:14:20 AM

Previous topic - Next topic

nosx

Hello Again,

As anyone that has ever used the createpost function knows, the body element in the msgOptions array was designed to work from a single source such as a text area for example, but what if you have a form that has multiple fields that need to be combined to make up the body element such as a application form which could have dozens of fields. What should you do in a case such as this ?

For now I simply created an array called body_sections and I populate it with the various form fields that are needed to make up the full body element in the msgOptions array and then I use the following code to join it all together



$body_sections = array(
$_POST['firstname'],
$_POST['lastname'],
...
...
...
);

$msgOptions = array(
'id' => 0,
'subject' => $_POST['subject'],
'body' => implode('<br>',$body_sections),
'icon' => 'xx',
'smileys_enabled' => false,



This works, but it seems extremely inefficient so I thought I would ask how others are handling this problem.

TIA,
Nosx

IchBin™

That seems basically the way to do it. Since the createPost function is expecting a predefined set of parameters, there's really no good way off the top of my head that I could think of to do it differently. And what you're doing is not that "inefficient" IMO. Make sure you are sanitizing your data that you're putting into it though.
IchBin™        TinyPortal

nosx

Already have the sanitizing and validation stuff taken care of, just figured there was an easier way to add the fields up but if this is the best way, then that is what I will use.

Thx,
Nosx

Advertisement: