trouble w/ IFRAMES - why does IE keep losing iframe target?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
egomez
Forum Newbie
Posts: 2
Joined: Tue Mar 22, 2005 10:30 am
Location: Austin, Texas

trouble w/ IFRAMES - why does IE keep losing iframe target?

Post by egomez »

Okay, so I'm doing some heavy DBM - I've coded a page that will allow our users to run queries against our DB through a browser interface. We're talking about being able to select which fields to return, setting conditions (eg, 'Where variable_name = so_and_so AND ..). So the interface is made up of two iframes and div box elements. One IFRAME contains a query history (name queryHistory), stored in $_SESSION variables, the other IFRAME is the target in which the results are displayed (queryResponse). The entire interface works on three scripts:
1.) queryLookup.php (which builds the div elements, which are hidden and are displayed when user selects query they which to run from a drop down (eg, Search Prospective Student Query), upon selecting the query, a table is displayed w/ the fields for this query as well as the option of setting conditions). It also generates two IFRAMES, one called queryHistory which is a small little iframe that sits inline w/ the div box element whose url is pointed to the same script w/ flags (ie, queryLookup.php?queryFlag=1). I added some code at the very top of this script that handles this IFRAME;
$_SESSION['queryCount'] holds the number of queries user has run.

Code: Select all

if(isset($_GET['queryFlag'] ))
{?>
                <meta http-equiv="refresh" content="60">
	<div class=readTxt>
	<span class=emphasizedRed>Query History</span><br>
<?php
           $queryList = getQueryId();
           for($i = 0; $i < $_SESSION['queryCount']; $i++)
           {
               for($c = 0; $c < count($queryList); $c++)
               { 
                      if($queryList[$c] == $_SESSION['querylookupid'.$i])
                      {
                          echo $i . ') <a href=queryResult.php?queryFlag=1&queryCount='.$i.' target=queryResponse>'. $queryList[$c]['name'];
                        }
                 }
            }
         exit();
}
as you can see, the exit function prevents the script from going any further thus preventing the rest of the php code from being executed.
It also keeps refreshing itself which allows for new queries to be displayed. As it stands I only allow 3 queries to be displayed. $_SESSION variables keeps count of queries. $_SESSION variables are created and primarily dealt w/ in queryResult.php. Anyways, the next IFRAME it generates is queryResponse. This is the iframe that the form in queryLookup.php targets (form name=queryForm id=queryForm action=queryResult.php method=post target=queryResponse), I've also used this variation to set the target (onsubmit="document.getElementById('queryForm').target = 'queryResponse'"). This IFRAME is the last of the code in the script as it sits below the queryForm and queryHistory IFRAME and takes up 70% of the browser. So the skeleton structure of this script is as follow:

Code: Select all

if(flag_to_generate_html_for_query_history_is_set)
{
        generate_html_for_queryhistory
        exit()
}

<script>
     script to handle the hidden elements in queryLookup.php, also handles the switching back and forth from hidden to block or inline
</script>

<?php 
    <code that generates form queryForm>
                 code ...
     <iframe for queryHistory></iframe>
      <iframe for queryResult></iframe>
      </form>
      </html>
?>
queryResult.php (the script builds a table w/ results, also, depending on which query they select, will display buttons to perform other functions such as exporting into CSV, generating a report or a balance Due Invoice). It takes in $_POST variables from queryLookup.php, runs getQueryResponse(), passes into it all neceassry values, and then displays results in table. The code for this isnt too necessary. But these are important to mention. If the $_SESSION variables for query arent set, then they are set, it passes into session variables all necessary variables needed to generate the response for getQueryResponse(). See, what happens is this. If say for example, the user runs prospective student query, he she can open an access style report in php, this doesnt resubmit the script, but its rather a button type w/ js to hadnel a new window whos url is pointed to the same script set w/ flags and uses $_SESSION variables to generate report. It work much in the same way as the queryHistory if statement in queryLookup.php (if isset($_GET['flag_name']){ code; exit();}) - well I have this one query that the user can interact w/ to keep track of prospective students. Each table row contains a check box next to it, allowing a rep to check it if he/she contacts this person by phone. When they are done, they click on 'Update Prospective Student' - now what happens is this, the form calls on itself - on top of the script (queryResult.php, in case you forgot) is this snippet of code:

Code: Select all

if(isset($_POST['contactPhone']))
	{
		$query = "SELECT personid FROM prospectivestudent";
		$result = retrieveRows($query);
		$k = 0;
		for($i = 0; $i < count($result); $i++)
		{
			$string = 'check'.$result[$i]['personid'];

			if($result[$i]['personid'] == $_POST[$string])
			{
				$person[$k] = $result[$i]['personid'];
				$k++;
			}
		}
		updateProspectiveStudent($person);
	}
As you can see, it gets a list of personids from the DB, it checks this against the check boxes that have been checked whose values are the values of personid (this is done in queryResult.php when it generates the table w/ results, each row contains person info) - if it is set, it throws them into an array and then calls on a function which simply updates the fields in prsopectivestudent table, indicating theyve been contacted by phone- if you notice there is not an exit function. Because, since I've submitting the form and called upon the same script to handle it, I need for the updated rows to be displayed in the table. This is were the $_SESSION variables are used to re-generate the table, except that this time those students who have been updated will have been displayed as such (i use a fill method in css to fill in the table data either blue for having been contacted by phone or red for contacted by email (done w/ a cron script who sends out emails to students who have already been contacted by phone) - this allows the rep to instantly see who they selected and to show theyve been updated.

The last script is queryHandler.lib which is a library file w/ function calls used by both queryLookup and queryResult.php - an explanation of this script is not important.

What happens is this, once I submit the form from queryResult.php (the update prospective students) I can no longer target the IFRAME queryResponse that was created in queryLookup.php, the same IFRAME which displays results from queryResult.php- instead what happens if I run another query from queryLookup.php is that it opens up a new window instead, same thing for queryHistory, which display an href link whose target is also queryResult. I cant understand why, I've tried so many things to fix it, but it just doesnt work after I click on updated prospective student. MOZILLA based browsers have no problem w/ it, they keep targeting queryResponse successfully. I'm on a deadline for work and I really really need some help here. Why isnt IE targeting this IFRAME any longer and MOZILLA can?? I know it has something to do when I submit the form in IFRAME queryResult. Hopefully, I have provided enough information and code example to help u guys out - if not lemme know. I know I prob didnt explain myself correctly so please follow up w/ any questions you might have. I thank you for your help, guys. I greatly appreciate any sort of comment.


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

understand the concept of white-space much? :lol:

I'm sorry, I don't have the patience to try to read all that at a go.
egomez
Forum Newbie
Posts: 2
Joined: Tue Mar 22, 2005 10:30 am
Location: Austin, Texas

Post by egomez »

Sorry Feyd - but I just came on here to see if I could get some help - its hard to explain script that consists of over 500 lines of code, not to mention 3 all working on uI Handlers and classes. I could write a 3 page essay on the design and functionality of the scripts, but I tried to condense it as much as possible. Like I said, I'm on a 24hr deadline and did not take time to read the php post outlines, my bad. Trust me, I did my homework, but I did not find any thread, anywhere that matched the problem I was having. I wish I could post all scripts on here, but that would be too long and I really can't do it since the code is property of ISA. So, forget the code above and the rather long explanation as well. Short version: I have a script (script1.php) that builds an IFRAME (frameName) - script1.php has form that calls on script2.php and targets it to frameName - script2.php also has a form that calls on itself. After doing so, script1.php no longer targets frameName, but rather opens up a new window. Any ideas as to why?? This only occurs in IE, MOZILLA browser have no trouble w/ it.
Methods tried:

Code: Select all

echo '<form name=formName id=formName action=script2.php method=POST onsubmit="document.getElementById('formName').target='frameName'">';

echo '<form name=formName id=formName action=scsript2.php method=POST target=frameName>';
Note: I didnt echo the html but rather embedded it withing the php code.
Post Reply