Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Adding a new field to discussion form

edited July 2008 in Vanilla 1.0 Help
I'd like to develop a extension that will (1) add a new field to the original post of a discussion that (2) saves to the database and (3) can be called back into a variable.

To be more specific, I'd like the user to be able to list comma-separated numbers that will be passed into an array that will create a sparkline graph from a script.

I'm quite willing to read up on whatever documentation that I need to do so, but was hoping Minisweeper or another vet could give me some general advice to point me in the right direction. (I know PHP, but am a complete novice at Vanilla extension development.)


  • edited June 2008
    OK, I hacked an old extension and I've now got a new text field appearing on the discussion posting page.

    Next step: Process the field and add to database

    Coming up: adding to comment page (currently commented out), but displaying the field only for post author.

    Any ideas?

    Code so far:

    <?php /* Extension Name: Sparkline Progress Extension Url: Description: Adds a sparkline to the dicusssions page Version: 0.1 Author: Taylor Buley Author Url: */ $Configuration["Sparkline_PATH"] = 'extensions/Sparkline/'; $Context->Dictionary['sparklabel'] = '% complete'; if (in_array($Context->SelfUrl, array("post.php", "comments.php"))) { class Sparkline { var $Name; var $Context; function Sparkline(&$Context) { $this->Name = "Sparkline"; $this->Context = &$Context; } function Sparkline_Create() { $result = mysql_query("SELECT DefaultFormatType FROM GTD_User WHERE UserID = '".$this->Context->Session->UserID."'"); $row = mysql_fetch_row($result); if ($row[0] == 'NULL' OR $row[0] == 'Text') { echo '<div id="Sparkline" style="display:none;">'; } else { echo '<div id="Sparkline">'; } echo '<label for="PercentageComplete">How much have you completed so far? <small>(optional)</small></label><input id="PercentageComplete" name="PercentageComplete" type="text" value="" maxlength="20" /><br><br>'; echo '</div>'; } } function AddSparklineFormtoCommentForm(&$DiscussionForm) { $Sparkline = new Sparkline($DiscussionForm->Context); $Sparkline->Sparkline_Create(); } if( $Context->Session->UserID > 0) { //$Context->AddToDelegate("DiscussionForm", "CommentForm_PreCommentsInputRender", 'AddSparklineFormtoCommentForm'); $Context->AddToDelegate("DiscussionForm", "DiscussionForm_PreCommentRender",'AddSparklineFormtoCommentForm'); } } ?>
  • if you want to make this extension public, you shouldn't hardcode the database prefix on your queries (get it from the Configuration array) or use the Database class, so more DBs will be compatible.
  • If you look at the CountCharacters extension, you may get some clues to help you.
  • edited July 2008
    Thanks for the heads up, guys. Let me regroup, and I'll keep y'all updated on the progress.
  • I've also played around with sparkline graphs in an old extension I wrote but never distributed. If you would like to see it, let me know.
This discussion has been closed.