News:

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

Main Menu

Custom Form Mod

Started by live627, July 09, 2008, 10:24:44 PM

Previous topic - Next topic

king kratos

Would this require a hearty overhaul of the mod? Or is this something I could simply add in the code for the form I want it on?

Garou

Im not sure off hand but Im going to guess that you would have to change stuff in the custom teplate an custom form php as well as the settings. So im guessing it might be complicated but I really havent had the chance to look at it yet.

Garou

#782
Ok This should work to use captcha and should be in the next version
This works using your Anti-Spam Verification settings, everyone that would normally have to use captcha to post to a board will also have to use it to post using a form.

In CustomForm.template.php
find...
// Output the save button, the end of the tables and the form.
add before...
         // Show CAPTCHA on the form     
   if ($context['visual_verification'])
   {
      echo '
      <tr><td class="windowbg2" colspan="3" align="center" valign="middle"><b>', $txt['verification'], ':</b></td><tr>
      <tr><td class="windowbg2" colspan="3" align="center" valign="middle">', template_control_verification($context['visual_verification_id'], 'all'), '</td></tr>';
   }


CustomForm.php
find...
// This function shows the custom forms and submits them.
function CustomForm()
{
global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info, $modSettings;

add after...

   // Generate a visual verification code to make sure the user is no bot.
      $context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1));
      if (!empty($modSettings['reg_verification']) && $context['user']['is_guest'])
      {
         require_once($sourcedir . '/Subs-Editor.php');
         $verificationOptions = array(
            'id' => 'register',
         );
         $context['visual_verification'] = create_control_verification($verificationOptions);
         $context['visual_verification_id'] = $verificationOptions['id'];
      }
      // Otherwise we have nothing to show.
      else
         $context['visual_verification'] = false;


The last piece of the code in the CustomForm.php should be...
// Check whether the visual verification code was entered correctly.
      $context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1));
      if ($context['require_verification'])
{
require_once($sourcedir . '/Subs-Editor.php');
$verificationOptions = array(
'id' => 'register',
);
$context['visual_verification'] = create_control_verification($verificationOptions, true);

if (is_array($context['visual_verification']))
{
loadLanguage('Errors');
foreach ($context['visual_verification'] as $error)
fatal_error($txt['error_' . $error], false);
}
}


the problem is everywhere I try to put it the form still posts even with out the captcha not filled in. I was thinking it should be around...
// Do we have completly valid field data?

Using this code the feature is always on but I plan to implement it in the next version as an option that you can turn off or on for each individual form.

I should also note that this only works for the 2.x version of SMF as its based on post verification. 1.1.x only verifies posts with the aid of additional mods but Im looking for some sort of work around seeing as how it does use captcha for PM's and registration.

ɔɔɔɔɔɔuɥoɾ

#783
Thanks, it took me quiet a while to figure this mod out lol..

Im having one issue, when filling in the forms, its all good, except that it creates a blank post with no data in it.

I dunno if this is a coding error, or its just me missing something ???

EDIT:
The form I'm filling to create the post is staying blank after clicking save, I'm suspecting its just not saving the data to the database


SMF 2.0 RC5

   
Webhost to New Webhost file transfer service, PM me - Fast transfers

king kratos

In your AC (where you make the form), make sure that the "Form output" is filled in. Use {****} (where *** is the name of the form field) to pull data form the form to the post.

Example form:

Name: (textbox named "user")
Date: (textbox named "date")

Example output:

On {date}, {user} filled out this form.

If you put Kratos in for the name and Monday for the date, it would post like this:

On Monday, Kratos filled out this form.

Hope that helps,
Kratos

ɔɔɔɔɔɔuɥoɾ

OK, its definiatly not saving to the database, I had tried your exact instructions several times

it only worked when I manually added that data to the database myself, is there any reason why it would not be saving?


SMF 2.0 RC5

   
Webhost to New Webhost file transfer service, PM me - Fast transfers

Garou

Yep there's some sort of bug with the WYSIWYG editor and the Form Output, its been covered here a few times but I haven't tracked it down yet.

To be honest its kinda low on my priority list as it works fine with the standard editor and personally I feel every form admin should be fluent in BBC. Of course I'm old and I was using the net long before WYSIWYG editors were created for message boards.  :-[

It is on the to do list and will be fixed eventually but there are other bugs and features that I feel are more important to get into the mod first.

Turn it off while creating forms for now and it should save just fine .  ;D

While were on the topics of quirks, be sure to make sure the Title field for your Form Fields does not contain capital letters, spaces, or any odd characters other then an underscore "_" as that can cause a variety of issues.

For instance usersname and users_name will work fine but UsersName, user's name, user'sname and a ton of other variations will cause your form or forms post to not display correctly. This is due mainly to the way HTML code works and there just isn't a decent way around it.

king kratos

Interesting! I usually try very hard (I mean I do everything) to use single words for the filed names as they are easier to check for accuracy when creating a form that contains more than 20 or 30 fields.

I'll keep that in mind though as I'm sure I will eventually need to use more than one word.

Kratos

ɔɔɔɔɔɔuɥoɾ

well its really weird,

I have the table open, its remembering all the columns, just not the output one ???


SMF 2.0 RC5

   
Webhost to New Webhost file transfer service, PM me - Fast transfers

king kratos

Like Garou said, it may be the WYSIWYG editor causing the issue.

Have you tried disabling the WYSIWYG editor temporarily in order to save the form output settings?

Also, when you say "all the columns", are you talking about the form field columns? I ask because the form output is located above those columns and is a large text box like what you see when making posts on this forum. It is located just underneath the "Subject" and "Form name" and "membergroup permissions" boxes.

Kratos

ɔɔɔɔɔɔuɥoɾ

Damn, sorry I was on the way out when reading the reply, I didnt see his reply, but yes, that is definitely the issue, I didnt disable the WYSIWYG on the main options, but rather just toggled it before saving.

So in theory you can use WYSIWYG editor, just toggle it before saving it :)

when I said columns, I mean in the database directly, within the database table


SMF 2.0 RC5

   
Webhost to New Webhost file transfer service, PM me - Fast transfers

king kratos

Gotcha.

Glad to hear that it was something as simple as the WYSIWYG! (We all know that database issues can be a major pain in the butt. LOL) And as for your theory, yes, that seems to be the case. I however (knock on wood) have not had these issues with the WYSIWYG editor. But just to be safe, I plan to do the same form now on. I really don't want to have to retype some of the form outputs (with upwards of 50 fields on some of my forms, it is a pain by itself).

Kratos

ɔɔɔɔɔɔuɥoɾ

yea, well this is a very nice mod and can be used for so many things.

You seem to know alot about this mod, is there anyway the title of the post can be controlled by the user filling the form?


SMF 2.0 RC5

   
Webhost to New Webhost file transfer service, PM me - Fast transfers

king kratos

The subject of the post made by the form is only controlled by what you add as variables.

For example, if you had fields for "user, date, and issue (select box: major, moderate, minor):

Enter in subject:

{user} has submitted a {issue} problem on {date}

If:
user= Kratos
date= Monday
issue= major

Then:
The subject will read:

Kratos has submitted a major problem on Monday.

There is no way (that I know of at least) to allow the user to control the subject. But, if you are creative (such as the example above), you can make relatively unique subjects for each individual user and post.

Kratos

ɔɔɔɔɔɔuɥoɾ

That's a shame, I wish there was a way for the form filler to control the title of the topic or at least add to it, that would be great, as some titles should be descriptive to the content in the post,

Maybe in the next update  ::) lol...


SMF 2.0 RC5

   
Webhost to New Webhost file transfer service, PM me - Fast transfers

king kratos

Well, you could add a field to your form for the subject, then just call that variable into the subject field.

Form:

Subject (field name= subject): .................

Form subject:

{subject}

That would allow a user to have full control in what goes in the subject field (I didn't think about this until just now).

Kratos

ɔɔɔɔɔɔuɥoɾ

#796
But would that be actual subject of the topic or something within the post its self?

I did think about that, about to try it actually, but its not coded for that though is it not?

EDIT:
just tested it

{subject} in the subject option.

then add the subject field, your sorted, that's so cool, thanks for the heads up

This mod is so great, congratulations on such a great mod creator :D


SMF 2.0 RC5

   
Webhost to New Webhost file transfer service, PM me - Fast transfers

king kratos

#797
In the Admin Panel, in the form creation area, edit the form you wish to have this functionality.

In the top part (just above the Form Output area) look for "subject".

As long as you reference the variable ({***}) in the subject section and not the large textbox Form Output section, the entered info will only show up in the topic subject line and not in the actual post itself.

P.S. See the attached screenshots showing examples of this. Do these help you better understand what to do to achieve this? I have a hard time verbally (with text) explaining what to do. I hope these screenshots help better tell my "story".

The first is showing the subject box itself, the second is showing the subject form field (the part the user fills in), the third is showing the subject with the form field title (variable) filled in, and the fourth is showing everything with extras in the form output field (the actual post).

Kratos

ɔɔɔɔɔɔuɥoɾ

Yep, I think I edited my post a few seconds before you posted yours, it works great :D


SMF 2.0 RC5

   
Webhost to New Webhost file transfer service, PM me - Fast transfers

Garou

Glad you got that figured out. One of the things I loved most about this mod even before Nathanial let me start helping with it was its versatility. There's only a couple more things I need to add to it to suit all of my own needs but there are many more that people have asked for on my to do list.

About the only thing I know for sure that people have asked for that I know will never make into the mod of is getting it to store the users input someplace other then a forum post. While I agree it would be handy in some cases but it just doesn't work well at all.

For instance in order to store the user input in a database you would have to either limit the amount of fields that can be be used in a form or create an entirely new database for every form. Either way it just isn't practical and extremely complicated to do using a program such as this and much better suited to a stand alone form.

Outside of that just about everything that has been asked for is doable except for a few things that are entirely subjective and would only benefit a few sites so I'm reluctant to add them. Then there are a few things that are just beyond my knowledge to do right now but I keep learning more everyday.  :)

Advertisement: