在php中将数据从新窗口发送到上一个窗口

发布于 2024-11-23 20:36:25 字数 1044 浏览 2 评论 0原文

我的 main.php 文件中有一个图像:

  <img src="..\images\image.gif" class="cur" onclick="imgWin();">

当我单击该图像时,下面的函数已调用:

function imgWin()
{
   imageWin=window.open("../pages/img.php","imageWin","toolbar=no,width=500,height=200,directories=no,menubar=no,SCROLLBARS=yes");
}

此函数在新窗口中打开 img.php

img.php 文件:

<HTML>
<HEAD>
    <TITLE>upload image</TITLE>
</HEAD>
<BODY>

    <FORM NAME="imgForm" method="get" action="#">
          address : 
          <INPUT type="file" name="imgUrl" size="50">
          description : 
          <INPUT type="text" name="description" size="50">
          <input type="submit" value="sumbit">
    </form>
</BODY>
</HTML>

我想当我单击上面表单中的 submit 按钮时,来自 imgUrl 的数据code> 和 description 文本框发送到 main.php 文件。

我怎样才能做到呢?

I have an image in the main.php file :

  <img src="..\images\image.gif" class="cur" onclick="imgWin();">

when I click on this image below function has called :

function imgWin()
{
   imageWin=window.open("../pages/img.php","imageWin","toolbar=no,width=500,height=200,directories=no,menubar=no,SCROLLBARS=yes");
}

this function opens img.php in a new window

img.php file :

<HTML>
<HEAD>
    <TITLE>upload image</TITLE>
</HEAD>
<BODY>

    <FORM NAME="imgForm" method="get" action="#">
          address : 
          <INPUT type="file" name="imgUrl" size="50">
          description : 
          <INPUT type="text" name="description" size="50">
          <input type="submit" value="sumbit">
    </form>
</BODY>
</HTML>

I want to when I click on submit button in above form , data from imgUrl and description textboxes send to main.php file.

How to I can do it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

节枝 2024-11-30 20:36:25

您应该命名您的窗口......

 <form action="foobar.php" method="get" target="foo">
 First name: <input type="text" name="fname" /><br />
 Last name: <input type="text" name="lname" /><br />
 <input type="submit" value="Submit" />
 </form>

这会将表单提交回名为“foo”的目标窗口,操作为 foobar.php ...当您使用 javascript 打开窗口时,指定“名称”,这是目标..

 window.open(URL,name,specs,replace)

You should be naming your windows.....

 <form action="foobar.php" method="get" target="foo">
 First name: <input type="text" name="fname" /><br />
 Last name: <input type="text" name="lname" /><br />
 <input type="submit" value="Submit" />
 </form>

This will submit the form back to the target window which is named "foo" and the action is foobar.php ... When you open the window, with your javascript, specify the "name" which is the target ..

 window.open(URL,name,specs,replace)
自找没趣 2024-11-30 20:36:25

我建议你使用 jQuery 来实现它!

// -------------------------- main.php
    <img src="..\images\image.gif" class="cur" id="imgButton">
    <div id="page"></div>

    <script type="text/javascript" >
    $('#imgButton').click(function(){
       $('#page').load('../pages/img.php');
    )}
    </script>


// ------------------img.php file :

    <form name="imgForm" method="post" action="#">
          address : 
          <INPUT type="file" name="imgUrl" size="50">
          description : 
          <INPUT type="text" name="description" size="50">
          <input type="button" value="sumbit" id="submit">
    </form>

        <script type="text/javascript" >
        $('#submit').click(function(){
           ........
           SEND YOUR DATA BY AJAX
           $.ajax({
           url:.......,
           data:(FORM VARIABLES),
           success:function(){
            // PRINT YOUR INPOUT VARIABLE HERE ;
            // $("input[name='imgUrl']").val();

           }
           })

        )}
        </script>

编辑

$.ajax({  
  type: "POST",  
  url: "YOUR ADDRESS HERE",  
  data: {var1:$("input#[INPUT NAME]").val(),var2:$("input#[INPUT NAME]").val(), ....}  
  success: function() {
  // Do something on success
  // alert ( 'Form Sent' );
  });  
  }  
}); 

I suggest you use jQuery to reach it!

// -------------------------- main.php
    <img src="..\images\image.gif" class="cur" id="imgButton">
    <div id="page"></div>

    <script type="text/javascript" >
    $('#imgButton').click(function(){
       $('#page').load('../pages/img.php');
    )}
    </script>


// ------------------img.php file :

    <form name="imgForm" method="post" action="#">
          address : 
          <INPUT type="file" name="imgUrl" size="50">
          description : 
          <INPUT type="text" name="description" size="50">
          <input type="button" value="sumbit" id="submit">
    </form>

        <script type="text/javascript" >
        $('#submit').click(function(){
           ........
           SEND YOUR DATA BY AJAX
           $.ajax({
           url:.......,
           data:(FORM VARIABLES),
           success:function(){
            // PRINT YOUR INPOUT VARIABLE HERE ;
            // $("input[name='imgUrl']").val();

           }
           })

        )}
        </script>

EDIT

$.ajax({  
  type: "POST",  
  url: "YOUR ADDRESS HERE",  
  data: {var1:$("input#[INPUT NAME]").val(),var2:$("input#[INPUT NAME]").val(), ....}  
  success: function() {
  // Do something on success
  // alert ( 'Form Sent' );
  });  
  }  
}); 
冬天旳寂寞 2024-11-30 20:36:25

目前我能想到的唯一方法是将 img.php 所需的字段存储到另一个文件(例如 img.xml)中,然后使用 AJAX 将其加载到主文件中。

ajax 代码将存储在主文件中。在 img.php 文件中,您将在提交按钮上有一个 onClick,该按钮会触发主文件中的 AJAX。

The only way I can think of at the moment is to store the required fields of img.php into another file, say img.xml, then load that in the main file using AJAX.

The ajax code would be stored in the main file. In the img.php file, you would have an onClick over the submit button which triggers the AJAX in the main file.

○愚か者の日 2024-11-30 20:36:25

更改:

action="#"

至:

action="main.php"

它将把参数发送到 main.php,您需要在那里编写代码来处理它。

Change:

action="#"

To:

action="main.php"

It will send the parameters to main.php and there you need to write code to process it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文