我在开发joomla(2.5)模块时遇到了问题。我有xml文件,其中包含自定义字段类型addlocation。
<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字段类型值都会保存,但自定义字段类型不会保存到数据库参数列中。为什么?如果我的问题不明确,请告知我上传完整档案。 谢谢。
答案 0 :(得分:0)
Joomla只会存储来自输入字段的结果,其中包含您在xml定义中提供的名称:因此您的jquery应绑定到更改或表单&#39;提交并连接/加入您添加的值并将其存储在名为&#34; location&#34;的字段中。 Onload,你应该反过来,即根据location的值填充自定义字段(这可以通过php轻松实现)。
答案 1 :(得分:0)
如果在定义字段时将addlocation.php中的字段名称设置为 name =&#34; jform [first_block_loc]&#34; ,则必须将值存储在params中专栏..