News:

Want to get involved in developing SMF, then 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

.Vapor

Love the mod, but i have 1 question.

After i submit a form, it goes to the appropriate forum...but the post is empty?

I am using smf 1.1.9 with a custom theme.

Garou

I just set this up fresh on my test server and it works fine on the default theme. The only Theme Edits are     './Themes/default/languages/Help.english.php' and './Themes/default/languages/Modifications.english.php'.

Have you tried using the mod with the default theme? That will tell us if your problem is theme specific or it installed improperly.

.Vapor

i will test this on default theme, and get back to you.

Garou

Also do you have all the data set up properly in the form, both the Form Output and the Form Fields? Did you follow the suggested format for field names?

alfzer0

an update...I've been able to add another set of {} to the output syntax for better control of the output when fields are empty (talked about a few pages back).  I just started working on it again since I last posted, and the coding prob I previously had was easily fixed.

Here's the relevant section of code (aside from declaring the $vars_blank and $vars_non_blank arrays).  My additions have comments starting with "{{ }} Syntax:"...

SMF 1.17 (probably 1.1.x?)
Sources\CustomForm.php

                //    Add this fields value to the list of variables for the output post.
                $vars[] = '/\{'.$field['title'].'\}/';
                $replace[] = $value;

                //    {{ }} Syntax: Setup REGEX for removing entire {{ }} string or just stripping the outermost { }, depending upon the replacement value being blank or not
                if($value == '')
                {
                    $vars_blank[] = '/\{[^\{\}]*\{'.$field['title'].'\}[^\{\}]*\}/';
                    $vars_non_blank[] = '//';
                }
                else
                {
                    $vars_blank[] = '//';
                    $vars_non_blank[] = '/\{[^\{\}]*\{'.$field['title'].'\}[^\{\}]*\}/';
                }

                //    Also add this data back into the data array, just in case we can't actually submit the form.
                $data[$i]['value'] = $value;
               
                //    Do a small fix for the last line, if this is a checkbox.
                if($field['type'] == 'checkbox')
                    $data[$i]['value'] = isset($_REQUEST[$field['title']]) ? $_REQUEST[$field['title']] : false;
                //    Do a small fix for the last line, if this is a largetextbox.
                if(($field['type'] == 'largetextbox'))
                    $data[$i]['value'] = isset($_REQUEST[$field['title']]) ? $_REQUEST[$field['title']] : '';
            }

            //    Do we have completly valid field data?
            if(!$fail_submit)
            {
                require_once($sourcedir.'/Subs-Post.php');

                //    {{ }} Syntax: Strip out everything in {{ }} if value is blank
                $output = preg_replace($vars_blank, '', $output);
                $subject = preg_replace($vars_blank, '', $subject);

                //    {{ }} Syntax: Remove outside brackets if value is not blank
                $output = preg_replace_callback($vars_non_blank, create_function('$matches','return substr($matches[0],1,-1);'), $output);
                $subject = preg_replace_callback($vars_non_blank, create_function('$matches','return substr($matches[0],1,-1);'), $subject);

                //    Replace all vars with their correct value, for both the message and the subject.
                $output = preg_replace($vars, $replace, $output);
                $subject = preg_replace($vars, $replace, $subject);


Garou...I think this would be a great feature to add to the release for everyone.  If you need any additional info on how the code works or how the optional {{ }} syntax is used in the body and subject outputs, just let me know.  And no worries, AFAIK this still leaves the original syntax intact so it's completely optional if someone wants to use the double brackets or not.  Sadly, I don't have SMF 2.0 installed so I couldn't do any testing for it.  Hopefully these additions can easily be added to the CustomForm.php for SMF 2.0 (hell, I'm not even sure if it's different from 1.1.x version).


Also, I'm trying to add a couple other things to this mod...
* An option for large text boxes to be "post boxes" complete with bbcode buttons and smileys.
* An error redirect back to the form page for the subject being larger than what SMF normally allows (80 chars), showing which fields contribute to the subject length, and how many characters need to be trimmed off to be within limits

Garou, if you think you can do either of these easily and would like to, please let me know and I'll leave those for you to code.  Else I'll code them myself (or at least try) and if successful share the code again (unfortunately still only for 1.1.7) .  I've already took a look at whats needed for the second one and I'm sure I can do it, but it will probably take me a lil while cause I'm still not fluent with PHP.  Not sure how easy/difficult the first will be, but I don't think it'll be too difficult to tackle.

Thanks again,
-Jeff


Garou

Ok Just so I can make sure I understand this...
If the admin sets it up so the forum output is
Your answers are: {{question1},{question2},{question3}}

Then the user only answers 1 and 3 then it would post...
Your answers are: question1, question3

Instead of...
Your answers are: question1,  , question3
Correct?

alfzer0

no, it's like this...

let's say you have 3 fields, *{name}, {age}, {weight}
(age and weight are optional)
and in the form output you do...
Name: {name}
{Age: {age}}
{Weight: {weight} lbs.}

If the user enters all values, the output would be like...
Name: Jeff
Age: 27
Weight: 195 lbs.

...but if the user didn't enter {age} or {weight}, the output would be...
Name: Jeff

The best one could do without this feature is...
Name: Jeff
Age:
Weight:  lbs.

is that more clear?

Garou

Yeah I got it. I had the right idea just the wrong syntax. Now would the user have to add anything different in their form fields or does this work by default as long as the proper syntax is used in the form output? I just want to get it straight for my notes and then later, the help files. I haven't had the chance to test it out. If it works or I can modify it to work on both the 1.1.x and the 2.x versions (there are some variations in the code)  Ill get it in the next release.

I have about a dozen test forums up right now with stuff I'm testing just for this mod. I'm hoping I can get some of them finished and into an update when I get my next vacation. It also depends on where SMF is at with their next release because I'm probably going to have to make a bunch of changes to make this work with the next major release of SMF.

Another thing to keep in mind Nathanial has stated his next release of this mod will completely rewrite the way this mod is coded and will be for 2.x only. As there are many features to build off of in 2.x that do not exist in 1.1.x, it may not be possible to realistically port it backwards.

alfzer0

#568
yup, user has to do nothing special when filling out the form. The admin just has to use the proper syntax in the form output (subject or body)

when/if Nathanial rewrites the mod I imagine it would still be easy to add this in as well (if there is no better functionality added that would trump this), and I'd gladly help with it if need be.

I do need to do some more testing on it as well, didn't check out int/float fields or if the outside brackets are on a different line from the inside brackets.

alfzer0

#569
btw, I just got a post box working in place of a large text field, except that it's screwing up the theme CSS formatting.  If I can get that ironed out...for giving the admin a choice of what to show, do you think it's better to add a Type Parameter to the Large Text Box (probably 'postbox') or add a new Type specifically just for Post Box?

edit: woohoo, got the theme formatting fixed. Now just to decide on how to present the option to display a Post Box

alfzer0

also, I'm noticing that if I have a "$" in a text field, it and everything after it is stripped out.  Haven't looked into the code yet, but I'm guessing this is for security purposes...is there anyway to get around this without sacrificing security?

Garou

Its one of the things Im working on. The mod is using the smf internal text editor and I havent been able to track it down.

For now Ive been recomending that questions be set up using the css for align right which places the $ next to the input field. The actual code to do so is a couple of pages back. Its just not easy to cut and paste using my cellphone. LOL

.Vapor

Quote from: V@POR on May 25, 2009, 11:10:01 PM
i will test this on default theme, and get back to you.

Resolved...thank you.

alfzer0

#573
Quote from: Garou on May 26, 2009, 02:19:19 PM
Its one of the things Im working on. The mod is using the smf internal text editor and I havent been able to track it down.

For now Ive been recomending that questions be set up using the css for align right which places the $ next to the input field. The actual code to do so is a couple of pages back. Its just not easy to cut and paste using my cellphone. LOL

lol!  I'm already right aligning the questions (I think they look better that way).  If I find any solution I'll let ya know.

btw, I'm from Portage, IN (living in CA currently though)  Nice to know a fellow hoosier is working on this  ;D

Garou

Ive been through there a few times. If you make a trip home let me know.

Glad ya got it fixed V@POR, what wound up being wrong? It helps me when someone else has similar problems.

FragaCampos

Hello there.
I've just read the 29 pages of this thread carefully, cause i wanted to know the ins and outs of this.
I think it's one of the best mods around, a bit hard to get know it, but after you know how to used it, it's just brilliant.
Thanks to Nathaniel for thinking about it and all his support, and Garou for keeping this alive.

All my requests for this mod were already asked, but i'll put them in a list to make sure they don't stay out of the next update (hopefully there will be one :P)

1. When an user press "New Topic" on the board where the form is going to post, it should go to the Form Page instead.

2. An attachment field. This would make this mod even greater.

3. Option to select the post icon.

Also, i noticed the problem with the urls. Garou, i tried your suggestion but it keeps putting the http:// behind, i.e., after i put the parse_bbc in the "Extra Type Parameters:" field it keeps showing this:

[url=http://{link}]Test[/url]
[img]http://{link}[/img]



Quote from: Garou on February 22, 2009, 10:34:12 AM
I figured this one out this morning. You have to enter parse_bbc in the Extra Type Parameters field for this to work right.

Example...
Title: image
Text: Please enter the link to your image here.   
Type: Text Box (String)
Extra Type Parameters: parse_bbc

Then in the Form Output: you would enter
[img]{image}[/img]

Images will post from the form to your forum this way, no changes to the mod necessary.  :)

Any thoughts about this?

Thanks in advance.

Garou

FragaCampos #3 is in the works for my next update, #1 and 2 are on the to do list once I figure out how to do them. #1 I have made several attempts at and every time I broke the post function for the entire forum. For now its just going to have to wait I get time to figure it out or someone more knowledgeable about the post function lends me the code.  In the mean time there are several other functions planed for my next few updates that I can do.

As for where you quoted me, I just double checked in 2.0 RC1-1 and it works perfectly.

FragaCampos

Thanks Garou. I appreciate your effort and perseverance on this.
All of the "to do" items for this mod are great, but i think the attachment one would bring the mod to an all new level ;) Still, i understand it's not easy to workaround with the code, i'm a code newbie myself, and i keep giving all the credits to the people who work so hard on SMF and related mods.


Quote from: Garou on May 28, 2009, 11:03:37 PM
As for where you quoted me, I just double checked in 2.0 RC1-1 and it works perfectly.

I'm using 1.1.9. Could it be because of that?

FragaCampos

Hi there.

After trying the mod and play around with some forms I came up with two more suggestions:

1 - The "Text" field in the "Form Fields" section should accept more characters, so that we can use it for explaining things better to users and bypass the mod's limitations.

2 - When we choose "Selection box" in the "Form Fields" section, and put two strings on the "Extra Type Parameters" like for example "This is good.,This is better" we should be able to use it like this: "The is good.," so that instead of returning a "No" we could return nothing if the checkbox wasn't selected.
Why this? It would make possible to make several checkboxes (or just one from a list) and return only the "true value", i.e., the first one. This would be particularly helpful with images, to select from a list and insert inside a img tag.
Hope i made some sense :P

Enders

It would also be nice if this mod can post its form content on a separate page rather than a forum page...

Advertisement: