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.
Options

SQLBuilder AddFieldNameValue

ok here is the code and renders
if($Context->SelfUrl == 'post.php' && $Context->Session->UserID > 0 ){ function Render_DiscussionImageForm () { echo '<ul><li> <label for="txtDiscussionImage">Enter an image url to be used as Discussion Image <small>(optional)</small></label> <input type="text" value="" maxlength="255" class="DiscussionBox" name="DiscussionImageURL" id="txtDiscussionImage"/> </li></ul>'; } function DiscussionForm_SaveDiscussionImage (&$DiscussionForm) { $s = $DiscussionForm->Context->ObjectFactory->NewContextObject($DiscussionForm->Context, 'SqlBuilder'); $s->SetMainTable('Discussion', 'u'); $s->AddFieldNameValue('DiscussionImage', $_POST['DiscussionImageURL']); } $Context->AddToDelegate('DiscussionForm', 'DiscussionForm_PreButtonsRender', 'Render_DiscussionImageForm'); $Context->AddToDelegate('DiscussionForm', 'PostSaveDiscussion', 'DiscussionForm_SaveDiscussionImage'); }
The function Render_DiscussionImageForm renders this input field in the DiscussionForm Control on post.php
Picture 3

When I click save I need the url to be saved in a Field called DiscussionImage which is inside the Table LUM_Discussion. Can anyone tell me how to do that. what I'm doing isn't working,

Comments

  • Options
    edited April 2007
    Your SQL that you are building never gets sent to the database. Its better that way, because if it did, it would set the discussion image for every discussion because there is no where clause to tell the database which discussion the image belongs to.

    Here is a snippet taken from the bottom of SaveDiscussion() in Vanilla.Class.DiscussionManager.php, rewritten a bit to work in your function:
    function DiscussionForm_SaveDiscussionImage (&$DiscussionForm) { $s = $DiscussionForm->Context->ObjectFactory->NewContextObject($DiscussionForm->Context, 'SqlBuilder'); $Discussion = $DiscussionForm->DelegateParameters['Discussion']; // We need the discussion ID from this $s->SetMainTable('Discussion', 'd'); $s->AddFieldNameValue('DiscussionImage', ForceIncomingString('DiscussionImageURL', '')); $s->AddWhere('d', 'DiscussionID', '', $Discussion->Comment->DiscussionID, '='); $DiscussionForm->Context->Database->Update($s, 'SaveDiscussionImage', 'NewDiscussion', 'An error occurred while updating discussion properties.'); }
  • Options
    edited April 2007
    worked as expected thanks WallPhone One more question Do I need this functions FormatStringForDatabaseInput() plus i want this feature for new discussions and while the first comment of the discussion is being edited. not anywhere else I can use the $NewDiscussion as in the Discussion Manager SaveDiscussion class. one way to detect a first comment is to check if the CommentID being editted matches the FirstCommentID of the discussion, right?
  • Options
    Not sure how to limit it to those conditions--but yes you should use the database function too, to prevent SQL injection attacks.
  • Options
    edited April 2007
    one way to detect a first comment is to check if the CommentID being editted matches the FirstCommentID of the discussion. If yes then show the discussion image url field. if not hide it.


    what is the SQlbuilder equivalent of this
    $query = mysql_query("SHOW COLUMNS FROM LUM_Discussion LIKE 'DiscussionImage'"); if (mysql_num_rows($query) == 0) { mysql_query("ALTER TABLE `LUM_Discussion` ADD `DiscussionImage` text NOT NULL ;"); }
  • Options
    There isin't one. I guess SQLbuilder does just basic CRUD. To do any DDL queries I guess you would have to run them right into the database class (Framework.Class.MySQL.php) directly:$query = $Context->Database->Execute($query); if ($Context->Database->RowCount($query) == 0) { $Context->Database->Execute("ALTER TABLE `LUM_Discussion` ADD `DiscussionImage` text NOT NULL ;"); }

    For best results, you should also look up the database table prefix and the table names from where they are defined in appg/database.php
This discussion has been closed.