Solved

communication between two php pages

Posted on 2006-06-13
3
407 Views
Last Modified: 2011-10-03
Hi experts,

actually i am not sure is this a php question, or it's a javascript question...

for example, i have a page called form.php, basically it's a form asking for user's input

then i have another page called call.php, it contains a list of names....  what i want is that when a user clicked on the list of name in call.php, the value of that name will be passed into form.php, and form.php should be updated by itself ...    i saw this somewhere on the web actually, but i am not sure how to get this done, either via php or javascript?

thanks a lot!!

airok
0
Comment
Question by:airok
  • 2
3 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16892741
You can use javascript to pass the value from call.php to form.php and then let the form in form.php submit itself to refresh the page. (You can also just refresh the page, but I expect you need to submit the form).

Are your pages within a frameset or do they have an opener/popup relationship?

-r-
0
 

Author Comment

by:airok
ID: 16892791
it's a opener/popup relationship

do u have a example javascipt can let me take a look for reference?

i would like to know how to do this if it's a frameset too...  ;)
many thanks!!

sorry i am not familiar with javascript at all...
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 16892825
When call.php is the popup you can have this script:
[form.php]
<form name="mainForm">
  <input type="text"  name="callField" />
  <input type="button" onclick="window.open('call.php');" value="Load call.php" />
</form>
[call.php]
<script type="text/javascript">
function setFormField(field, value, submit) {
  frm = window.opener.document.forms.mainForm;
  frm.elements[field].value = value;
  if(submit) frm.submit();
}
</script>

<a href="javascript:setFormField('callField', 'Name 1', true);">Name 1</a><br/>
<a href="javascript:setFormField('callField', 'Name 2', true);">Name 2</a><br/>
<a href="javascript:setFormField('callField', 'Name 3', true);">Name 3</a><br/>
<a href="javascript:setFormField('callField', 'Name 4', true);">Name 4</a><br/>
<a href="javascript:setFormField('callField', 'Name 5', true);">Name 5</a><br/>
<a href="javascript:setFormField('callField', 'Name 6', true);">Name 6</a><br/>
<a href="javascript:setFormField('callField', 'Name 7', true);">Name 7</a><br/>

When you are having frames you only have to change the javascript:

<script type="text/javascript">
function setFormField(field, value, submit) {
  frm = parent.otherFrameName.document.forms.mainForm;
  frm.elements[field].value = value;
  if(submit) frm.submit();
}
</script>

Hope this helps,

-r-
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question