dongpang2483 2013-12-22 05:01
浏览 53

创建一个在joomla中返回变量的弹出窗口或iframe

I really need help. I am a newbie programmer and really not sure how can i do this in joomla.

I need to create a pop up or iframe that pass variable from the parent page.

Basically what is to happen is this.

A user will enter a string in to a input box and click on search. When click on search button, a pop up will appear and allow him to select the closest match and return this chosen value back to the main page.

What i have done is something like that.

<input type="text" name="projectn" id="projectn" value="<?php echo $row->address?>" size="50" class="input-large" placeholder=" <?php echo JText::_('Project Name if any');?>" /> Enter to populate project info.
<input type="button" value="Search" onclick="JavaScript:makeSelection(this.form, document.getElementById('projectn').value);" />

In the makeSelection function it is like that.

function makeSelection(frm, proj) {
    alert(proj);
    if(!frm || !proj)
    return;
    targetElement = frm.elements[proj]
    var handle = window.open('http://www.abc.com/abc/child.php?name='+proj, 'Project-Selection', 'width=300,height=200,location=no,menubar=no,status=no,scrollbar=yes,toolbar=no');

In the child.php page it is as follows

<?php
define( 'DS', DIRECTORY_SEPARATOR );

//get root folder
 $rootFolder = explode(DS,dirname(__FILE__));

 //current level in diretoty structure
 $currentfolderlevel = 8;

 array_splice($rootFolder,-$currentfolderlevel);

 $base_folder = implode(DS,$rootFolder);


 define( '_JEXEC', 1 );

if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}

if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'../../../includes/defines.php';
}
require_once JPATH_BASE.'../../../configuration.php';
require_once JPATH_BASE.'../../../includes/framework.php';
require_once JPATH_BASE.'../../../includes/helper.php';
require_once JPATH_BASE.'../../../includes/toolbar.php';

require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
/* Create the Application */
 $mainframe =& JFactory::getApplication('site');
 $mainframe->initialise();
 $mainframe->route();
 $user =& JFactory::getUser();
 $userid = $user->get('id');
 ?>

 <?php 
  $a = $_GET['name'];
if($a != ""){
$db = JFactory::getDBO();
$db->setQuery("Select * from #__project where project_name like '%$a%'");
$prolists = $db->loadObject();
$npro = count($prolists);
echo $npro;
}
   ?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv"Script-Content-Type" content="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Expires" content="0"> <!-- disable caching -->
<title>Example</title>
<script type="text/javascript">
function makeSlection(frm, proj) {
  alert(proj);
  /*if(!frm || !proj)
    return;
  var elem = frm.elements[proj];
  if(!elem)
    return;
  var val = elem.options[elem.selectedIndex].value;
  opener.targetElement.value = val;*/
  this.close();
}
</script>
</head>
<body>

<form id="fsrm" name="fsrm" action="#">
<span>Names: </span>
<select name="nameSelection" id="nameSelection">
  <option value="holly">Holly</option>
  <option value="golly">Golly</option>
  <option value="molly">Molly</option>
</select>
<input type="button" value="Select Name" onclick="JavaScript:makeSlection(this.form,   document.getElementById('nameSelection').value);">
</form>
</body>
</html>

The problem now is the child page is not working and show this

No configuration file found and no installation code available. Exiting...

I am not sure why or somewhere is not correct. Most codes are sample codes found from the net so i am not sure how it should work.

What i need is a search button that pass a variable to a popup or a iframe, then in the popup it will access the database and give a list of values for user to choose. Once chosen, it will close the popup and pass the value back to the parent window.

Does anyone has any alternative or advise how this can be done? Thanks

  • 写回答

1条回答 默认 最新

  • donglang1894 2014-01-28 20:51
    关注

    What you need is a very simple ajax call to get a list of links which the user will be able to click, and display this list in a popup.

    This would be achieved with a component task (a public method you define in the controller.php or a subcontroller). You need to code this single method to return the list (or better, have it invoke a method in the model to retrieve the list, and then format it with a view; but makes little difference).

    In order to have Joomla return just the output of a component just add &tmpl=component to the request, no modules or template will be output.

    The jQuery.get() would be a nice way to start the ajax call, but it's a matter of taste.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100