Is there a way to fill out a form and have it post?

Started by fox0r, February 05, 2010, 11:41:21 PM

Previous topic - Next topic

fox0r

I tried to sum it up in the title.  What I am wanting to do (I have TP installed!) is make something like an article with a form in it for people to fill out and submit.  Once this has been submitted I'd like for it to post to a specific area on the forum.

Does anyone know of a way to do this?  Or if there's a mod for it?  I tried looking, but I had no luck.

Kays

Hi, that is possible. I wouldn't want to make it public though.

However, what's your comfort level with php?

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

fox0r

I know some basic stuff.  I've done PHP forms before where they have sent out email.  So I could do the form field part easy, it'd be the.. making it post on the forums part that'd be hard.

Kays

Creating the post//topic isn't that difficult as there's a SMF function to do that. You just need to feed it the proper parameters.

That can be used either in a separate page with SSIphp included. Or create a page with a function to do what you want in the sources folder and access it using ?action=function_name.

I'll move this to SMF Coding Discussion.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

fox0r

Could you give me a bit more info?  I feel lost already. :(

Kays

Actually, in thinking about it it might be easier just to use the post2() function (the one which handles all of the posting) then you only need to create the form.

Where or what are you adding this to?

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Arantor

Actually would be a lot easier to just use createPost rather than invoking Post2() because of the way that can call back to the Post template (and it permission checks, which createPost won't)

As many details as you can give would be awesome.

fox0r

Basically, the forum I run is for an organization in an online game.  We need an application.  To avoid drama I figured it would be easiest to have applicants fill out this application and have it post directly to the proper section on the forum.

This is what I would be making into a form to be submitted:
http://ootbf.com/index.php?page=5

And then I would need for it to post here:
http://ootbf.com/index.php?board=6.0  (This wont show since it's locked down to a specific member group.)

I would also need for it to create a title using the "Character Name" field.  So, basically, whatever a person puts for there would be the topic's title.

What other info do you guys need?

Arantor

So, presumably, the user filling in the form is the 'topic starter'?

And what are the field names there? Do you want any particularly formatting going into the page? Ultimately these are questions that we can't answer.

What I can tell you is the mechanics of it.

When the button is pressed - assuming you have done any error checking you're going to do for missing fields (and throwing it back to the user), you need to do pretty much the following. This assumes you bundle the entire thread post into $post, i.e. assembling the form contents into a single string including any bbcode you want (hence my question about formatting).

global $sourcedir, $user_info; // if it's not already

require_once($sourcedir . '/Subs-Post.php');

$posterOptions = array(
  'id' => $user_info['id'], // if it's a member, SMF will look up the rest
  'update_post_count' => false, // never update post count
);

$msgOptions = array(
  'id' => 0,
  'body' => $post,
  'subject' => $_POST['character_name'], // or whatever the field is called!
);

$topicOptions = array(
  'id' => 0,
  'board' => 6,
  'mark_as_read' => true,
);

createPost($msgOptions, $topicOptions, $posterOptions);


And then it's done.

fox0r

It really doesn't need any pretty formatting, at most I'd prolly have it follow how it looks now.

Though I think I may run into problems with the person posting being the topic started.  The section is more of a 'staff' section that general members cannot see.  So it may have to post from myself, or maybe an account specific to that?

For fields I would do, in order:

character_name
circle
guild
race
gender
time_played
location
current_member
aware
other_order
heard
recruited
why_join
aim
email
enjoy
time_contact
locked_out


Thanks so much for the help!

Arantor

It doesn't really matter - createPost doesn't care about permissions. Surely you'd want it to post as the person applying, so it actually lists that member as the topic starter? (They won't be able to see the topic, unless they can access the board)

So... what happens if any of the fields are blank? Return as an error to the user? (Hint: this is why I was leaving it to you and giving you the SMF specific stuff)

fox0r

Yeah.  All fields would have to be filled out for the form to be submitted.

If it posts from the person applying and works okay then I have no problem with it.  I was just thinking it wouldn't work because of the permissions.

Arantor

That's why I specifically said createPost doesn't check permissions, and everything else holds to normal.

So... should it just block clicking the button until all the fields are full (Javascript) or return an error?

Though bearing in mind I have no idea at all what code is in action=page... if you've made forms before that can send emails, this is really no different.

fox0r

It's been a REALLY long time since I've made a forum to submit emails, and I've never done it with SMF/Tiny portal before.

Yeah, it should just block it from going through if all forms are not filled out.

I'm not even sure if this is right at the moment.  It's been a while.  Thankfully I have Dreamweaver. LOL

<div align="center">
  <p><strong>Order of the Black Fox<br />
  Membership Application</strong></p>
  <p>By filling out this application you acknowledge and agree to the terms,  conditions, and guidelines stated within our Charter and Bylaws.<br />
    </p>
</div>
<form id="form1" name="form1" method="post" action="">
  <label>
  <div align="left">   
    <p><strong>Character Info
      </strong><br />
      <br />
      Character Name
      <input name="character_name" type="text" id="character_name" value="" />
    </p>
    <p>
      <label>Circle
      <input name="circle" type="text" id="circle" />
      </label>
    </p>
    <p>
      <label>Guild
      <input name="guild" type="text" id="guild" />
      </label>
    </p>
    <p>
      <label>Race
      <input name="race" type="text" id="race" />
      </label>
    </p>
    <p>
      <label>Gender
      <input name="gender" type="text" id="gender" />
      </label>
    </p>
    <p>
      <label>Time playing this character
      <input name="time_played" type="text" id="time_played" />
      </label>
    </p>
    <p>
      <label>What is this character's usual location?
      <input name="location" type="text" id="location" />
      </label>
    </p>
    <p>&nbsp;</p>
    <p><strong>Group Information</strong></p>
    <p>
      <label>Are you currently a member of another Order or Organization?
      <input name="current_member" type="text" id="current_member" />
      </label>
    </p>
    <p>
      <label>If so, would you be willing to leave said Order or Organization?
      <input name="leave" type="text" id="leave" />
      </label>
    </p>
    <p>
      <label>Are you aware that only one character per account may be a member of an Offical Order?  (Note this does not apply to non-sanctioned orders or Official Player Run Organizations such as the Locksmith Union.)<br />
      <textarea name="aware" cols="100" id="aware"></textarea>
      </label>
    </p>
    <p>
      <label>Have you ever been a part of another Order?  If so, what were your reasons for leaving?
      <textarea name="other_order" cols="100" id="other_order"></textarea>
      </label>
    </p>
    <p><strong>Black Fox Information </strong></p>
    <p>
      <label>How did you hear about us?
      <input name="heard" type="text" id="heard" />
      </label>
    </p>
    <p>
      <label>Who recruited you?
      <input name="recruited" type="text" id="recruited" />
      </label>
    </p>
    <p>
      <label>What have you heard about us?
      <input name="about_us" type="text" id="about_us" size="100" />
      </label>
    </p>
    <p>
      <label>Why do you want to join?
      <input name="why_join" type="text" id="why_join" size="100" />
      </label>
    </p>
    <p>&nbsp;</p>
    <p><strong>Player Information </strong></p>
    <p>
      <label>AIM:
      <input name="aim" type="text" id="aim" />
      </label>
    </p>
    <p>
      <label>E-mail:
      <input name="email" type="text" id="email" />
      </label>
    </p>
    <p>
      <label>How important is it to you to stay in character?
      <input name="stay_ic" type="text" id="stay_ic" />
      </label>
    </p>
    <p>
      <label>What do you typically enjoy doing in the game?
      <input name="enjoy" type="text" id="enjoy" />
      </label>
    </p>
    <p>
      <label>When would be the best time for you to interview?
      <input name="time_contact" type="text" id="time_contact" />
      </label>
    </p>
    <p>
      <label>Have you ever been locked out?  If so, why?
      <input name="locked_out" type="text" id="locked_out" />
      </label>
    </p>
    <p>&nbsp;</p>
    <p>Plesae make sure you have filled in all fields before submitting!</p>
    <p>
      <label>Ready to submit your application?
      <input type="submit" name="Submit" value="Submit" />
      </label>
</p>
    <p>&nbsp;</p>
    <p>&nbsp;  </p>
  </div>
  </label>
</form>

Arantor

OK, so what code have you got in action=page then?

fox0r


Arantor

The page where your content is?

Ignore me, it's not an action.

OK, this just got more complex, because you have to have the form somewhere, and the result action somewhere...

fox0r

I figured the forum would be in one of the Tiny Portal articles.  Could there be an external like... submit.php to handle the forum submission/posting/etc?

Arantor

Yes, but the quickest route is actually to separate it out to its own action which is what I'm writing right now.


Advertisement: