OK starting to get somewhere
this is what I have in my plugin so far.
<?php
/**
* Register a form field to forms
*/
switch ($modx->event->name) {
case 'OnDocFormPrerender':
/* if you want to add custom scripts, css, etc, register them here */
break;
case 'OnDocFormRender':
/* Get the TV */
$tv = $modx->getObject('modTemplateVar',array('name'=>'mp3file'));
$v = '';
if (isset($scriptProperties['resource'])) {
/* on the update screen, so set the value */
/* get the raw content of the TV */
$v = $tv->getValue($id);
}
/* now do the HTML */
$fields = '
<div class="x-form-item x-tab-item">
<label class="x-form-item-label">MP3 File</label>
<div class="x-form-element" style="padding-left:205px;">
<input type="text" name="mp3_file" value="'.$v.'" class="x-form-text x-form-field" />
</div>
</div>
';
$modx->event->output($fields);
break;
case 'OnDocFormSave':
/* do processing logic here. */
$resource =& $scriptProperties['resource'];
$resource->set('mp3file',$_POST['mp3_file']);
$resource->save();
break;
}
return;
?>
The first bit works on update the value of the TV is retrieved and put into the form. I can’t get the OnDocFormSave section to work.
An additional complecations that I hadn’t thought about is that the tv is a file based tv and opens the built in file browser to create it’s value. Can someone point me in the direction to work out how to do this with the form field this code is generating.