Firefox PHP

Custom drop-down list of forums

Posted by RosieL 
Custom drop-down list of forums
October 03, 2012 04:06AM
Hi folks.

For this particular website all forums are private/closed/invisible until the visitor logs in, after which they will see only the forums of which they are a member.

On the Registration Form I want the applicant to specify which forum they are applying to join (Moderator will approve or disapprove). For this purpose I'd like them to make a selection from a drop-down list box of the available forums. Then the moderator doing the approval should be able to see their selection along with their membership application and decide if the applicant is eligible for that particular forum.

Such drop-down lists exist in the Phorum Admin (and maybe other places), but I haven't been able to figure out how to create one on the Registration Form, and then pass it on to the moderator.

Any assistance with this would be greatly appreciated. Sorry, but my PHP is only beginner level.

TIA
- Rosie
Re: Custom drop-down list of forums
October 11, 2012 04:31AM
OK, no answers, so maybe I haven't explained clearly. I'll break it down further, starting with getting a list of forums.

If necessary I can query the database directly with PHP and extract a list of forums from the table phorum_forums.

But I was thinking that hopefully there might be a much faster/easier way to get a list of forums using the Phorum Template Language (PTL).

So is there already a globally-available PTL variable that contains an array of the existing forums, so that I can iterate the individual elements into a HTML SELECT statement?

And by the way, is there anywhere I can find a list of all the predefined PTL variables?

TIA

- Rosie
Re: Custom drop-down list of forums
October 11, 2012 10:40AM
Quote

So is there already a globally-available PTL variable that contains an array of the existing forums, so that I can iterate the individual elements into a HTML SELECT statement?

No, there isn't. You'll have to write a module to fill in a template variable with the data you want and this could also handle showing the information saved there again for the moderator.


Thomas Seifert
Phorum Development Team / Mysnip-Solutions.de
Custom Phorum and general software development
worry-free Phorum Hosting
Re: Custom drop-down list of forums
October 12, 2012 12:24AM
Well what I ended up doing was to write some code to query the database directly and populate a drop-down list with the results, then I dropped that code into register.tpl as shown in code fragment below.

As far as the appearance and functionality of the modified register.tpl is concerned, it works just fine.

My next challenge is how to pass the name of the selected forum to the moderators. I THINK part of the process is to add a Custom Profile Field in Phorum Admin, so I've done that and called the field forum_request.

But what next???

Just for the sake of full disclosure, here is the code fragment that creates a drop-down list of available forums. It's pretty standard stuff I believe, but I'm a PHP novice so suggestions always welcome.

Language: HTML
<!-- BEGIN TEMPLATE register.tpl -->   {IF ERROR}<div class="attention">{ERROR}</div>{/IF} {IF OKMSG}<div class="information">{OKMSG}</div>{/IF}   <div class="generic"> <form action="{URL->ACTION}" method="post" style="display: inline;"> {POST_VARS}   <table>   <!-- For this example I have omitted the other rows/cells for Username, Password, etc. -->   <tr> <td nowrap="nowrap">Request access to:&nbsp;</td> <td> <!-- ***************************************** --> <!-- Create drop-down list of available forums --> <!-- ***************************************** --> <?PHP   /* Open a connection to database */ $user_name = "xxxxxxxxxxx"; $password = "yyyyyyyyyyy"; $database = "zzzzzzzzzzz"; $server = "domainname.com"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "SELECT * FROM phorum_forums"; $result = mysql_query($SQL);   /* Create & populate drop-down list of forums. */ echo "<select>"; while ($db_field = mysql_fetch_assoc($result)) { /* Exclude the Announcements forum from the selection list. */ If ($db_field['name'] != 'Announcements') { echo "<option value='" . $db_field['name'] . "'>" . $db_field['name'] . "</option>"; } } echo "</select>";   /* Close the database. */ mysql_close($db_handle); } else { print "Database NOT Found "; } ?> <!-- ***************************************** --> <!-- End drop-down list --> <!-- ***************************************** -->   <br><span style="font-size:0.8em;">Please select the forum you think you are eligible for.</span> </td> <td style="font-size:small;"></td> </tr> </table>
Sorry, only registered users may post in this forum.

Click here to login