Skip to content

Commit

Permalink
feat: Add support for SMF 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
live627 committed Feb 25, 2022
1 parent 0a7408a commit 3a7f063
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 189 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
id: release
with:
release-type: php
draft: true
package-name: ${{ env.MOD_NAME }}
- uses: actions/github-script@v3
id: vars
Expand Down
62 changes: 30 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
## Custom Form
[![MIT license](http://img.shields.io/badge/license-MIT-009999.svg)](http://opensource.org/licenses/MIT)
[![GitHub issues](https://img.shields.io/github/issues/live627/smf-custom-forms.svg)](https://github.com/live627/smf-ultimate-menu/issues)
[![Latest Version](https://img.shields.io/github/release/live627/smf-custom-forms.svg)](https://github.com/live627/smf-ultimate-menu/releases) [![Support](http://img.shields.io/badge/PayPal-$-009966.svg)](https://www.paypal.me/JohnRayes)
[![Latest Version](https://img.shields.io/github/release/live627/smf-custom-forms.svg)](https://github.com/live627/smf-ultimate-menu/releases)
[![Total Downloads](https://img.shields.io/github/downloads/live627/smf-custom-forms/total.svg)](https://github.com/live627/elk-um/releases)
[![Support](http://img.shields.io/badge/PayPal-$-009966.svg)](https://www.paypal.me/JohnRayes)

### Overview
This Mod allows you to create custom forms for your forum which your users can access at "index.php?action=form", these forms are essentially a structured way of allowing your users to submit posts to certain boards, meaning that you can get them to enter certain information into a form and then you can chose how you want that information to be presented within the final outputted post.

You can access a list of your forms and the links to the actual forms themselves by going to "index.php?action=form".
Package name | SMF version | Minimmum PHP version
--- | --- | ---
Custom Form Mod 2.1.0 | SMF 2.0.x, SMF 2.1.x | PHP 7.4
Custom Form Mod 2.0.3 | SMF 2.0.x | PHP 7.4
Custom Form Mod 1.7 | SMF 1.1.x, 2.0.x | PHP 4.3 – PHP 7.4

Possible uses for this Mod could include, Support Forms, Staff Application Forms, Error Reporting Forms and etc.
[View changelog](https://github.com/live627/smf-custom-forms/blob/master/CHANGELOG.md)

**Settings are found in the Admin panel:** "Configuration"-> "Modifications" -> "Custom Form" or `index.php?action=admin;area=modsettings;sa=customform`
### Overview
This Mod allows you to create custom forms for your forum which your users can access at `index.php?action=form`, these forms are essentially a structured way of allowing your users to submit posts to certain boards, meaning that you can get them to enter certain information into a form and then you can chose how you want that information to be presented within the final outputted post.

### Requirements:
You can access a list of your forms and the links to the actual forms themselves by going to `index.php?action=form`.

- SMF 2.0 or greater
- PHP 7.4 or greater
Possible uses for this Mod could include, Support Forms, Staff Application Forms, Error Reporting Forms and etc.

### Features Explained:
#### Creating/Editing Forms:
This is done in the settings area for this mod, you just need to create a new form by clicking on `Add New Form`, and then set up the information for that form making sure that you have entered in the relevant data for each setting, you will also need to add some fields to the form, otherwise it will be ignored.

#### Viewing a list of forms that you can post:
This is done at the `form` action `index.php?action=form`, you will be able to view a list of forms that you can view and post, as well as a link to the board they belong to and etc.

#### Posting a form:
This is done at the `form` action `index.php?action=form;n=#`, Replace `#` with the actual number of the form. Once the user has filled out the form and saved/submitted, the results will be posted to the appropriate board. You can change the look of this page by creating a Custom Template Function.
Settings are found in the admin panel: Administration Center » Configuration » Modifications » Custom Form (or `index.php?action=admin;area=modsettings;sa=customform`).

#### Custom Template Functions:
This is a feature allows you to create your own custom template function for each form, to do this we suggest that you make a duplicate of the `form_template_example()` function within the 'CustomForm.template.php' file. You can then use the documentation from that function to see how information is passed to it by the Mod, allowing you to change it for your purposes.
- **Creating/Editing Forms:** This is done in the settings area for this mod, you just need to create a new form by clicking on `Add New Form`, and then set up the information for that form making sure that you have entered in the relevant data for each setting, you will also need to add some fields to the form, otherwise it will be ignored.

Please remember that you have to name the new template function in this format `form_template_{Custom Template Name}`, and you will have to put the correct value from `{Custom Template Name}` into the `Custom Template Function` setting for the form that you wish to use you new template. Further explanation for custom templates can be found in the 'CustomForm.template.php'.
- **Viewing a list of forms that you can post:** This is done at the `form` action `index.php?action=form`, you will be able to view a list of forms that you can view and post, as well as a link to the board they belong to and etc.

#### CAPTCHA Visual Verification:
Visual verification often referred to as CAPTCHA and used by SMF for registration and posting, is included in the mod to help prevent against bots from using forms as a way to post your forum. Visual verification requires that the user type letters or digits from a distorted image that appears on the screen in order for a form to submit correctly.
- **Posting a form:** This is done at the `form` action `index.php?action=form;n=#`, Replace `#` with the actual number of the form. Once the user has filled out the form and saved/submitted, the results will be posted to the appropriate board. You can change the look of this page by creating a Custom Template Function.

By default all forms require visual verification when being filled out by guests and can not be turned off. Alternatively registered members will also be required to use visual verification based on existing settings in SMF.
- **Custom Template Functions:** This is a feature allows you to create your own custom template function for each form, to do this we suggest that you make a duplicate of the `form_template_example()` function within the `CustomForm.template.php` file. You can then use the documentation from that function to see how information is passed to it by the Mod, allowing you to change it for your purposes.

To access verification settings in for SMF 1.1.x: go to Admin => Registration => Settings or index.php?action=regcenter;sa=settings
Please remember that you have to name the new template function in this format `form_template_{Custom Template Name}`, and you will have to put the correct value from `{Custom Template Name}` into the `Custom Template Function` setting for the form that you wish to use you new template. Further explanation for custom templates can be found in the `CustomForm.template.php`.

To access verification settings in for SMF 2.x: go to Admin => Configuration => Security and Moderation => Anti-Spam or ?action=admin;area=securitysettings;sa=spam.
- **CAPTCHA Visual Verification:** Visual verification often referred to as CAPTCHA and used by SMF for registration and posting, is included in the mod to help prevent against bots from using forms as a way to post your forum. Visual verification requires that the user type letters or digits from a distorted image that appears on the screen in order for a form to submit correctly.
- All forms require visual verification when being filled out by guests and can not be turned off
- Registered members will also be required to use visual verification based on existing settings in SMF.
- To access verification settings in for SMF 1.1.x: go to Admin » Registration » Settings or `index.php?action=regcenter;sa=settings`.
- To access verification settings in for SMF 2.x: go to Admin » Configuration » Security and Moderation » Anti-Spam or `?action=admin;area=securitysettings;sa=spam`.

Further explanation of a settings functionality can be found by clicking on the [?] help button next to each setting.
Further explanation of a setting's functionality can be found by clicking on the [?] help button.

### Tutorial:
Linked below is a step by step tutorial on how to make the 'New Topic' Button re-direct to the form you wish the user to use for posting in that forum.
### Tutorial
**[View more tutorials](https://github.com/live627/smf-custom-forms/tree/main/docs)**
#### Redirect the 'New Topic' button to a form
http://www.simplemachines.org/community/index.php?topic=248871.msg3726297#msg3726297

### Version Changes:
- https://github.com/live627/smf-custom-forms/blob/development/CHANGELOG.md
- https://github.com/live627/smf-custom-forms/blob/master/CHANGELOG.md
#### Adding menu buttons for your actions
Download [Ultimate Menu](https://custom.simplemachines.org/index.php?mod=3674) for your menu building needs
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Tutorials
- [Custom template functions](./custom-template-functions.md)
- [Redirect the "New topic" button](./rediect-new-topic-button.md)
5 changes: 5 additions & 0 deletions docs/custom-template-function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Tutorial
### Custom template functions
This is a feature allows you to create your own custom template function for each form, to do this we suggest that you make a duplicate of the `form_template_example()` function within the `CustomForm.template.php` file. You can then use the documentation from that function to see how information is passed to it by the Mod, allowing you to change it for your purposes.

Please remember that you have to name the new template function in this format `form_template_{Custom Template Name}`, and you will have to put the correct value from `{Custom Template Name}` into the `Custom Template Function` setting for the form that you wish to use you new template. Further explanation for custom templates can be found in the `CustomForm.template.php`.
2 changes: 2 additions & 0 deletions docs/rediect-new-topic-button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Tutorial
### Redirect the "New topic" button
152 changes: 14 additions & 138 deletions src/CustomForm.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,107 +201,12 @@ function template_submit_form()
call_user_func('form_' . $context['template_function']);
}

// Template Function to show the Custom Form Mod Admin Settings section.
function template_customform_FormSettings()
function template_callback_output()
{
global $context, $txt, $settings, $scripturl;

// Show the main settings for this form.
// Note: The next part of the template is based of the template_show_settings() function from 'Admin.template.php'.
// Its similar except that it is static and it has a wysiwyg editor in it.
echo '
<form action="', $context['post_url'], '" method="post" accept-charset="', $context['character_set'], '">
<table width="80%" border="0" cellspacing="0" cellpadding="0" class="tborder" align="center">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="4" width="100%">
<tr class="titlebg">
<td colspan="3">', $context['settings_title'], '</td>
</tr>
<tr>
<td class="windowbg2" valign="top" width="16"><a name="setting_form_title" href="', $scripturl, '?action=helpadmin;help=customform_form_title" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt['help'], '" border="0" align="top" /></a></td>
<td class="windowbg2" valign="top"><label for="board_id">', $txt['title'], '</label></td>
<td class="windowbg2" width="50%">
<input type="text" name="form_title" id="form_title" value="', $context['custom_form_settings']['form_title'], '" />
</td>
</tr>
<tr>
<td class="windowbg2" valign="top" width="16"><a name="setting_form_board_id" href="', $scripturl, '?action=helpadmin;help=customform_board_id" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt['help'], '" border="0" align="top" /></a></td>
<td class="windowbg2" valign="top"><label for="board_id">', $txt['customform_board_id'], '</label></td>
<td class="windowbg2" width="50%">
<select name="form_board_id">';
foreach ($context['categories'] AS $category)
{
echo '
<optgroup label="', $category['name'], '">';
foreach ($category['boards'] as $board)
echo '
<option value="', $board['id'], '"', (!empty($context['custom_form_settings']['form_board_id']) && $context['custom_form_settings']['form_board_id'] == $board['id']) ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat(
'==',
$board['child_level'] - 1
) . '=&gt;' : '', $board['name'], '</option>';
echo '
</optgroup>';
}

echo '
</select>
</td>
</tr>
<tr>
<td class="windowbg2" valign="top" width="16"><a name="setting_form_icon" href="', $scripturl, '?action=helpadmin;help=customform_icon" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt['help'], '" border="0" align="top" /></a></td>
<td class="windowbg2" valign="top"><label for="icon">', $txt['message_icon'], '</label></td>
<td class="windowbg2" width="50%">
<select name="icon" id="icon" onchange="showimage()">';

// Loop through each message icon allowed, adding it to the drop down list.
foreach ($context['icons'] as $icon)
echo '
<option value="', $icon['value'], '"', $icon['value'] == $context['custom_form_settings']['icon'] ? ' selected="selected"' : '', '>', $icon['name'], '</option>';

echo '
</select>
<img src="', $context['icon_url'], '" name="icons" hspace="15" alt="" />
</td>
</tr>
<tr>
<td class="windowbg2" valign="top" width="16"><a name="setting_template_function" href="', $scripturl, '?action=helpadmin;help=customform_template_function" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt['help'], '" border="0" align="top" /></a></td>
<td class="windowbg2" valign="top"><label for="template_function">', $txt['customform_template_function'], '</label></td>
<td class="windowbg2" width="50%">
<input type="text" name="template_function" id="template_function" value="', $context['custom_form_settings']['template_function'], '" />
</td>
</tr>
<tr>
<td class="windowbg2" valign="top" width="16"><a name="setting_permissions" href="', $scripturl, '?action=helpadmin;help=customform_permissions" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt['help'], '" border="0" align="top" /></a></td>
<td class="windowbg2" valign="top"><label for="permissions">', $txt['edit_permissions'], '</label></td>
<td class="windowbg2" width="50%">
', theme_inline_permissions($context['custom_form_settings']['permissions']), '
</td>
</tr>
<tr>
<td class="windowbg2" valign="top" width="16"><a name="setting_subject" href="', $scripturl, '?action=helpadmin;help=customform_subject" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt['help'], '" border="0" align="top" /></a></td>
<td class="windowbg2" valign="top"><label for="subject">', $txt['subject'], '</label></td>
<td class="windowbg2" width="50%">
<input type="text" name="subject" id="subject" value="', $context['custom_form_settings']['subject'], '" />
</td>
</tr>
<tr>
<td class="windowbg2" valign="top" width="16"><a name="setting_exit" href="', $scripturl, '?action=helpadmin;help=customform_submit_exit" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt['help'], '" border="0" align="top" /></a></td>
<td class="windowbg2" valign="top"><label for="Form_exit">', $txt['customform_exit'], '</label></td>
<td class="windowbg2" width="50%">
<input type="text" name="form_exit" id="form_exit" value="', $context['custom_form_settings']['form_exit'], '" />
</td>
</tr>
<tr>
<td class="windowbg2" valign="top" width="16"><a name="setting_output" href="', $scripturl, '?action=helpadmin;help=customform_output" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt['help'], '" border="0" align="top" /></a></td>
<td class="windowbg2 valign="top"><label for="output"><u><strong>', $txt['customform_output'], ':</strong></u></label></td>
<td class="windowbg2" width="50%"></td>
</tr>
<tr>
<td class="windowbg2" style="hieght:12px;" colspan="3"></td>
</tr>
<tr>
<td class="windowbg2" colspan="3">
</dl>
<table>
<tr>
<td class="windowbg2" style="width:50px;"></td>
Expand All @@ -327,52 +232,28 @@ function template_customform_FormSettings()
<td class="windowbg2" style="width:50px;"></td>
</tr>
</table>
</td>
<tr>
<td class="windowbg2" colspan="3" align="center" valign="middle"><input type="submit" value="', $txt['save'], '" /></td>
</tr>
</table>
</td>
</tr>
</table>
<input type="hidden" name="sc" value="', $context['session_id'], '" />
</form>
<br /><br />';

// Finally show the list of fields.
template_show_list('customfield_list');
<dl>';
}

// Simple fucntion to connect two templates for the General Settings area.
function template_customform_GeneralSettings()
{
// Show the confiq_vars.
template_show_settings();

// Put in a spacer to make it look better.
echo '
<br />';

// Show the list.
template_show_list();

}

// Template function for the thank you page.
function template_ThankYou()
{
global $context, $modSettings, $txt, $settings, $scripturl;
global $context, $modSettings, $scripturl, $txt;

// Show the Starting part of the template.
echo '
<table style="width:100%;">
<tr>
<td style="width:20%;"></td>
<td class="tborder" style="margin-top: 1ex;width:50%;">
<div class="titlebg" style="padding: 4px;">', (isset($modSettings['customform_view_title']) && ($modSettings['customform_view_title'] != '')) ? $modSettings['customform_view_title'] : $txt['customform_tabheader'], '</div>
<div style="padding: 2ex;" class="windowbg2">
<div class="cat_bar">
<h3 class="catbg">
', isset($modSettings['customform_view_title']) && ($modSettings['customform_view_title'] != '')) ? $modSettings['customform_view_title'] : $txt['customform_tabheader'], '
</h3>
</div>
<span class="upperframe"><span></span></span>
<div class="roundframe">
<table style="width:100%;background-color:#000000;" align="center">
<tr class="windowbg">
<td style="padding:4px;" colspan="3" align="center">
Expand All @@ -387,14 +268,9 @@ function template_ThankYou()
<td style="padding:4px;" style="width:45%;" align="center">
<a href="' . $scripturl . '?action=form;"> ', $txt['customform_list'], '</a>
</td>
</tr>';
// Finsh off the template.
echo '
</tr>
</table>
</div>
</td>
<td style="width:20%;"></td>
<tr>
</table>
</div>
<span class="lowerframe"><span></span></span>
';
}

0 comments on commit 3a7f063

Please sign in to comment.