Keyword

Text field in plugin won't save

  • Dominic Danson
  • Dominic Danson's Avatar Topic Author
  • Offline
  • New Member
More
9 years 7 months ago #131559 by Dominic Danson
Text field in plugin won't save was created by Dominic Danson
Hello K2 world!

I'm trying to write my first basic plugin for K2. I need to create a text field on items. But although the field appears just fine and the data renders on the frontend, when I go back to edit the item the data is gone, so it disappears on the frontend.

Is there a way I can save this information so I don't have to get users to put it in fresh each time?

Thanks!

Please Log in or Create an account to join the conversation.

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
9 years 7 months ago #131560 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Re: Text field in plugin won't save
Can you copy and paste the code here?

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

Please Log in or Create an account to join the conversation.

  • Dominic Danson
  • Dominic Danson's Avatar Topic Author
  • Offline
  • New Member
More
9 years 7 months ago #131561 by Dominic Danson
Replied by Dominic Danson on topic Re: Text field in plugin won't save
Hi Mohamed,

Sure:

video.xml:

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="k2" method="upgrade">
<name>Video Backgroud plugin</name>
<author>Dominic Danson</author>
<creationDate>September 5th, 2014</creationDate>
<version>1.2</version>
<license>www.gnu.org/licenses/gpl-2.0.html GNU/GPL
<description>A plugin to place a video background onto pages.</description>
<files>
<filename plugin="video">video.php</filename>
</files>
<config>
<fields name="params">
<fieldset name="basic">
</fieldset>
</fields>
</config>
<fields group="item-content">
<field name="videoURL" type="textarea" size="60" label="URL to the mp4 source file" description="" />
<field name="image" type="media" directory="images" label="Fallback image" description="" />
</fields>
</extension>

video.php:

<?php
defined('_JEXEC') or die ;

JLoader::register('K2Plugin', JPATH_ADMINISTRATOR.'/components/com_k2/lib/k2plugin.php');

class plgK2Video extends K2Plugin
{

// Some params
var $pluginName = 'video';
var $pluginNameHumanReadable = 'Video Background plugin';

function plgK2Video(&$subject, $params)
{
parent::__construct($subject, $params);
}

function onK2PrepareContent(&$item, &$params, $limitstart)
{
$mainframe = JFactory::getApplication();
//$item->text = 'It works! '.$item->text;
}

function onK2BeforeDisplay(&$item, &$params, $limitstart)
{
$mainframe = JFactory::getApplication();

// Get the output of the K2 plugin fields (the data entered by your site maintainers)
$plugins = new K2Parameter($item->plugins, '', $this->pluginName);

$videoURL = $plugins->get('videoURL');
$image = $plugins->get('image');

// Check if we have a value entered
if (empty($videoURL))
return;

// Output
$output = '
$image
<script>
$(function() {
var BV = new $.BigVideo({container: $("#video-wrap")});
BV.init();
BV.show("'.$videoURL.'", {ambient:true});
BV.getPlayer().on("durationchange",function(){
$("#video-wrap").fadeIn();
});
});
</script>
';

return $output;
}

}


Thanks!

Please Log in or Create an account to join the conversation.

  • Dominic Danson
  • Dominic Danson's Avatar Topic Author
  • Offline
  • New Member
More
9 years 7 months ago #131562 by Dominic Danson
Replied by Dominic Danson on topic Re: Text field in plugin won't save
Hi world,

Any able to help me on this one?

Really appreciate it!

Thanks!

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum