PDA

View Full Version : How do I populate editor from database?


Cadellin
11-13-2010, 10:26 PM
I'm working on a custom bug tracker for my site and as part of it I need to be able to edit items that have been previously entered into the system which I can do fine for all fields apart from the editor where I get stuck.

So my question is quite simple: How do I load a message into the vbeditor?

I have searched around quite extensively and thought about it but I can't think of an obvious solution so I thought I would ask in the hope someone can give me a point in the right direction.

Thanks

Lynne
11-14-2010, 03:18 AM
http://www.w3schools.com/tags/tag_textarea.asp

<textarea rows="10" cols="60">
Text here.
</textarea>

Cadellin
11-14-2010, 07:54 AM
Thanks Lynne but I don't think I explained my problem properly.

I know how to set the value of a textarea normally but I'm wondering how I do it for vbeditor as unlike the rest of my form it is being loaded from an external location using {vb:raw messagearea}.

Lynne
11-14-2010, 02:56 PM
I guess I don't understand then... if you look at the template for the editor you are using, you'll see something like this for the editor textarea:
<textarea name="message" id="{vb:raw editorid}_textarea" rows="10" cols="80" tabindex="1" dir="{vb:stylevar textdirection}">{vb:raw newpost.message}</textarea>
so, you'd set $newpost.message to be whatever text you have gotten from your query.

Cadellin
11-16-2010, 09:50 PM
Thanks once again Lynne - I'm closing in on the solution.

I'll try to explain my problem differently incase that helps.

I used this article (https://vborg.vbsupport.ru/showthread.php?t=228693) to include the WYSIWYG editor in my custom template. Using the method in that guide the editor is included by using {vb:raw messagearea} - which works fine for posting.

What I'm struggling is using the WYSIWYG editor to edit existing messages.

I've had a good search around the templates & functions but work out where to insert my value="x"

Lynne
11-16-2010, 09:59 PM
Do you have a custom page for editing this information? And have you written a query that gets the information from the database to edit?

Cadellin
11-16-2010, 10:10 PM
I've got a custom page, template and written the queries to populate the other fields and update the record on submission all I'm missing is the knowledge where to put the variable which outputs the unedited message.

Lynne
11-16-2010, 11:27 PM
What does the code look like right before (and including) you render the template? and what is the name of the messagetext variable?

Cadellin
11-17-2010, 07:45 AM
Sorry I'm not quite sure which bit of the code you mean - I think you mean this bit.


$templater = vB_Template::create('edittask');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('type_tasks_options', $type_tasks_options);
$templater->register('task_user_options', $task_user_options);
$templater->register('taskmanagerversion', $taskmanagerversion);
$templater->register('editorid', $editorid);
$templater->register('messagearea', $messagearea);
$templater->register('edittask_name', $edittask_name);
$templater->register('itemid', $itemid);
$templater->register('edittask_id', $edittask_id);
$templater->register('edittask_name', $edittask_name);
$templater->register('edittask_desc', $edittask_desc);
$templater->register('edittask_assigned', $edittask_assigned);
$templater->register('edittask_duedate', $edittask_duedate);
print_output($templater->render());


The message text variable is "$edittask_desc"

Lynne
11-17-2010, 01:35 PM
Now I see you making a custom template called "edittask", but I have no clue what is in there - how are you using the variable $edittask_desc in the template?

Cadellin
11-19-2010, 03:07 PM
I have a custom template called "edittask" in which I got the WYSIWYG editor using this article.

Using that method the editor is inserted using {vb:raw messagearea} which I have to register in my php file as well as including functions_editor.php

I have created a variable called $edittask_desc which contains the old message which has been created previously using a different form (which also has a WYSIWYG editor).

What I can't work out is how to set the textarea value.

My template is below:

{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw pagetitle}</title>
{vb:raw headinclude}
{vb:raw headinclude_bottom}

<script type="text/javascript" src="clientscript/vbulletin-editor.js?v={vb:raw vboptions.simpleversion}"></script>
<link rel="stylesheet" type="text/css" href="{vb:var vbcsspath}vbulletin-formcontrols.css" />
<link rel="stylesheet" type="text/css" href="{vb:var vbcsspath}editor.css" />
<link rel="stylesheet" type="text/css" href="{vb:var vbcsspath}bbcode.css" />
</head>
<body>

{vb:raw header}

{vb:raw navbar}

<div id="pagetitle">
<h1>{vb:raw pagetitle}</h1>
</div>
<div class="task_controls"><div class="task_control_left"><h2>User Panel</h2></div><div class="task_control_right"></div></div>
<h2 class="blockhead">Create New Task</h2>
<div class="blockbody">
<div class="wysiwyg_block">
<div class="blockbody formcontrols">
<div class="blockrow">
<form class="vbform block" action="edittask.php" method="post" name="vbform" onsubmit="return vB_Editor['{vb:raw editorid}'].prepare_submit(0,0)" ><br />
Name: <br /><input type="text" name="taskname" class="primary textbox full" value="{vb:raw edittask_name}" /><br /><br />
Type: <br /><select class="primary" name="tasktype"><option value="0">Select Type</option>{vb:raw type_tasks_options}</select><br /><br />
Description:<br />
{vb:raw messagearea}
<br />

<fieldset><legend>Assign Task: (optional)</legend>
Assign to User: <br />
<select name="taskuser" class="primary" cols="100"><option>none</option>{vb:raw task_user_options} </select><br /><br />
Due Date: <br /><input id="datepicker" class="primary textbox full" type="text" name="taskduedate" size="20" READONLY value="{vb:raw edittask_duedate}"/></fieldset>
</div>
</div>
</div>
<input type='hidden' name='taskid' value='{vb:raw edittask_id}'>
<input type='hidden' name='s' value='{vb:raw session.sessionhash}' />
<input type='hidden' name='securitytoken' value='{vb:raw bbuserinfo.securitytoken}' />
<div class="blockfoot actionbuttons">
<div class="group">
<input class="button" type="submit" value="Submit" />
</div></div>
</form>
</div>

<div style="width:100%;text-align:center;padding:10px;"><span class="copyright">Traction Wars Task Manager {vb:raw taskmanagerversion}</span></div>
{vb:raw footer}
</body>
</html>