我在开发 joomla(2.5) 模块时遇到了问题。我有具有自定义字段类型添加位置的 xml 文件。
<fieldset name="addLocations" label="Add Locations" addfieldpath="/modules /mod_pr_weather/elements">
<field type="addlocation" name="locations"></field>
</fieldset>
并且有 addlocation.php 文件,
<?php
defined('JPATH_BASE') or die;
jimport('joomla.form.formfield');
class JFormFieldAddlocation extends JFormField {
protected $type = 'Addlocations';
protected function getInput() {
$addFrom = '<div id="pr_maindiv"> <h1>'.JText::_('MOD_PR_WEATHER_HEADER_ADD_LOCATION').'</h1>'.$this->getForm("single").'</div>';
$addFromBlock = '<div id="pr_maindiv_b" style="clear:both;"><h1>'.JText::_('MOD_PR_WEATHER_HEADER_ADD_LOCATION').'</h1>'.$this->getForm("multi").'</div>';
$doc = JFactory::getDocument();
$doc->addScriptDeclaration('
jQuery(document).ready(function(){
jQuery("#pr_maindiv_b").css("display","none");
jQuery("#jform_params_slideshow_style").change(function(){
if(jQuery(this).val()==2){
jQuery("#pr_maindiv").css("display","none");
jQuery("#pr_maindiv_b").css("display","block");
}else{
jQuery("#pr_maindiv").css("display","block");
jQuery("#pr_maindiv_b").css("display","none");
}
});
});
');
return $addFrom . $addFromBlock;
}
private function getForm($type = 'single') {
$form_type_tooltip = 'class="hasTip" title="' . JText::_('MOD_PR_WEATHER_ADDLOCATION_TOOLTIP') . '"';
$from='';
if ($type=='single') {
$from = '<p><label'.$form_type_tooltip.'>'.JText::_('MOD_PR_WEATHER_ADDLOCATION_LABEL').'</label></p><p><input type="text" value="GEOLOCATION" placeholder="GEOLOCATION" name="single_location"/></p>
<p><input type="button" id="addMore" value="more"></p>';
}else{
$from = '<div style="clear:both;" id="first"><h3>Frist Block</h3><p><label'.$form_type_tooltip.'>'.JText::_('MOD_PR_WEATHER_ADDLOCATION_LABEL').'</label></p><p><input type="text" value="GEOLOCATION" placeholder="GEOLOCATION" name="first_block_loc"/></p>
<p><input type="button" id="addMoreFrist" value="more"></p></div>';
$from .= '<div style="clear:both;" id="second"><h3>Second Block</h3><p><label'.$form_type_tooltip.'>'.JText::_('MOD_PR_WEATHER_ADDLOCATION_LABEL').'</label></p><p><input type="text" value="GEOLOCATION" placeholder="GEOLOCATION" name="second_block_loc"/></p>
<p><input type="button" id="addMoreSecond" value="more"></p></div>';
$from .= '<div style="clear:both;" id="third"><h3>Third Block</h3><p><label'.$form_type_tooltip.'>'.JText::_('MOD_PR_WEATHER_ADDLOCATION_LABEL').'</label></p><p><input type="text" value="GEOLOCATION" placeholder="GEOLOCATION" name="third_block_loc"/></p>
<p><input type="button" id="addMoreThird" value="more"></p></div>';
$from .= '<div style="clear:both;" id="fourth"><h3>Fourth Block</h3><p><label'.$form_type_tooltip.'>'.JText::_('MOD_PR_WEATHER_ADDLOCATION_LABEL').'</label></p><p><input type="text" value="GEOLOCATION" placeholder="GEOLOCATION" name="fourth_block_loc"/></p>
<p><input type="button" id="addMoreFourth" value="more"></p></div>';
}
return $from;
}
}
以及用于按钮类型触发的 js 文件:
jQuery("#addMore").click(function(){
jQuery("#pr_maindiv").append("<p style='clear:both;'><input type='text' value='GEOLOCATION' placeholder='GEOLOCATION' name='single_location[]'/></p>");
});
jQuery("#addMoreFrist").click(function(){
jQuery("div#first").append("<p style='clear:both;'><input type='text' value='GEOLOCATION' placeholder='GEOLOCATION' name='first_block_loc[]'/></p>");
});
jQuery("#addMoreSecond").click(function(){
jQuery("div#second").append("<p style='clear:both;'><input type='text' value='GEOLOCATION' placeholder='GEOLOCATION' name='second_block_loc[]'/></p>");
});
jQuery("#addMoreThird").click(function(){
jQuery("div#third").append("<p style='clear:both;'><input type='text' value='GEOLOCATION' placeholder='GEOLOCATION' name='third_block_loc[]'/></p>");
});
jQuery("#addMoreFourth").click(function(){
jQuery("div#fourth").append("<p style='clear:both;'><input type='text' value='GEOLOCATION' placeholder='GEOLOCATION' name='fourth_block_loc[]'/></p>");
});
当按钮类型的点击事件发生时,完美地追加到后端表单中。但是当保存点击时,每个xml字段类型值都保存了,但自定义字段类型不保存到数据库参数列中。为什么?如果我的问题不清楚,请通知我上传完整文件。谢谢。