用一张表格填写另外两张表格



好的,所以我有两种不同类型的表单,我想用一种表单同时提交它们。我使用的是form1字段=第一个、最后一个和电子邮件的自动回复表单。我的第二个表单是联系人表单fields=name。电子邮件和正文字段。我试着同时使用这两种形式。我有一个表单,它会将字段发布到每个表单(INDEX.PHP(。问题是我不知道如何设置表单一,以我想要的方式将字段发布在表单1和表单2中。我想使用从表单index.php到其他两个表单(表单1、表单2(匹配的字段。因此姓名和电子邮件将同时进入两个表单,正文字段将进入表单2。主表单将在表单2的名称字段中发布第一个和最后一个……正如你从表单1和2中看到的,每个表单都有一个我需要处理的重定向页面。?我有主要形式:

索引.php

<html>
    <head>
    <title>Main Form</title>
    </head>
    <body>
        <h2>Winner Aution Item Request Form</h2>
        <p><span class="error"><FONT><font color="red">* required field.</font></span></p>
        <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
            First Name: <input type="text" name="first_name" value="<?php echo     $first_name;?>">        
            <FONT><font color="red"> *</font>
            <br>
            Last Name: <input type="text" name="last_name" value="<?php echo $last_name;?>">   <FONT><font color="red"> *</font>
            <br>
            E-mail: <input type="text" name="email" value="<?php echo $email;?>">
            <FONT><font color="red"> *</font>
            <br><br><i><b>Copy and paste auction item name below.</b></i><br>
            Product Name: <input type="text" name="product_Name" rows="1" cols="10">
            <?php echo   $product_Name;?><FONT><font color="red"> *</font>
            <input type="Submit" value="Submit" name="submit"></input>
        </form>
    </body>
</html>

上面的表格是在一个网站上找到的,非常接近我想要它做的,但并不完全。。。。Form1

<?php session_start(); ?>
<html>
    <head>
        <title>autoresponder</title>
    </head>
    <body>
        <center>
            <table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;">
                <tr><td>
                    <form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
                        <strong><font color="#660000">Your First Name:</font></strong>
                        <input type="text" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
                        <strong><font color="#660000">Your Last name:</font></strong>
                        <input type="text" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
                        <strong><font color="#000066">Email address:</font></strong><br>
                        <input type="text" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
                        <input type="image" src="http://blog.jeremyahenry.com/mailermanager/images/go-button.gif" name="submit" value="Submit"><br>
                        <input type="hidden" name="r" value="4">
                        <input type="hidden" name="a" value="sub">
                        <input type="hidden" name="ref" value="none">
                        <br>
                        <font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes  
                        <input type="RADIO" name="h" value="0" checked="checked">No<br>
                        </font>
                    </form>
                </td></tr>
            </table>
        </center>
    </body>
</html>

表格2

<?php session_start(); ?>
<html>
    <head>
        <title>request form</title>
        <style>p{font:10pt arial;}</style>
    </head>
    <body>
        <form action="contact_me/process.php" method=post>
            <table align=left border=0 height=300>
                <tr> 
                    <td nowrap> 
                        <p>&nbsp;&nbsp;&nbsp;&nbsp;Your name:&nbsp;&nbsp;
                        &nbsp;&nbsp;<input maxlength=25 name=name size=25>
                    </td>
                </tr> 
                <tr> 
                    <td nowrap> 
                        <p>&nbsp;&nbsp;&nbsp;&nbsp;Your email:&nbsp;&nbsp;
                        &nbsp;&nbsp;<input name=from size=25 maxlength=25>
                    </td>
                </tr>
                <tr>
                    <td colspan=2>
                        <center>
                        <p align=center>Enter your Auction item Name below:
                        <br>
                        <textarea cols=50 name=message rows=7></textarea>
                        <p align=center>
                        <input type=submit value="Send Message">
                        <input type=reset value=Reset name="reset">
                    </td>
                </tr>
            </table>
        </form>
    </center>
    </body>
</html>

你可以从我要使用会话的代码中看到。但由于不熟悉它,尽管我有php的经验,但我对它还是很陌生,需要帮助。我想将表单数据解析为两种表单。和产品名称形成二。如有任何帮助,我们将不胜感激。。我希望这一点足够清楚,有人可以帮忙。。。。。

好的,新代码三个表单1.主表单向表单1和表单2提交信息。我已经使用会话进行了设置,所以我有:session.php

    <?php
       session_start();
    // store session data
    $_SESSION['af_first_name'] = $af_first_name;
    $_SESSION['af_last_name'] = $af_last_name;
    $_SESSION['af_email'] = $af_email;
    $_SESSION['cf_address'] = $cf_item_name;
     ?>

它处理变量。我的index.php新代码

    <?php
       // including the session file
       require_once("session_start.php")
    ?> 
    <?php
function stripZlashes($string)
{
    //This function is to strip slashes for either array or a String
    if (!is_array($string)) return stripslashes($string);
    $nvar = array();
     foreach ($string as $key => $value)
     $nvar[stripslashes($key)] = stripZlashes($value);
     return $nvar;
     }
     ?>
     </head>
      <body>
     <h2>Winner Aution Item Request Form</h2>
     <p><span class="error"><FONT><font color="red">* required field.</font></span></p>
     <form name="form1">
     First Name: <input type="text" name="$af_first_name" id="af_first_name"    value="<?php if(isset($_SESSION['af_first_name'])){echo stripslashes($_SESSION['af_first_name']); unset($_SESSION['af_first_name']);               } ?>" /><br>
      Last Name: <input type="text" name="$af_last_name" id="af_last_name" value="<?php if(isset($_SESSION['af_last_name'])){echo stripslashes($_SESSION['af_last_name']); unset($_SESSION['af_last_name']); } ?>" /><br>
     E-Mail: <input type="text" name="$af_email" id="af_email" value="<?php  if(isset($_SESSION['af_email'])){echo stripslashes($_SESSION['af_email']); unset($_SESSION['af_email']); } ?>" /><br>
     </form>
     <form name="form2">Copy and Paste Auction Name Below!<br>
     Product Name <br><input type="text" name="$cf_item_name" id="cf_item_name" value="<?php if(isset($_SESSION['cf_item_name'])){echo stripslashes($_SESSION['cf_item_name']); unset($_SESSION['cf_item_name']); } ?>" /><br>
             <input type="Submit" value="Submit" name="submit" onsubmit="form2.submit(); form3.submit();"></input>

该表单接受输入并设置为会话。Session.php将它取起来并以可变形式放置。从这里开始,我使用了一条带作为下划线。当它进入form1和form2时,变量会把它捡起来并填写表格。这是我的新form1

   <?php
function stripZlashes($string)
{
    //This function is to strip slashes for either array or a String
    if (!is_array($string)) return stripslashes($string);
    $nvar = array();
     foreach ($string as $key => $value)
     $nvar[stripslashes($key)] = stripZlashes($value);
     return $nvar;
     }
    if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
   stripZlashes($_SESSION['_mf']);
endif;
     // including the session file
     require_once("session_start.php")
      ?>
     <center>
    <table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;">     <tr><td>
    <form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
    <strong><font color="#660000">Your First Name:</font></strong>
    <input type="text" id="$af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
     <strong><font color="#660000">Your Last name:</font></strong>
    <input type="text" id="$af_last_name" value="<?php echo (!empty($_SESSION['_af']['af_last_name'])?$_SESSION['_af']['af_last_name']:'') ?>" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
    <strong><font color="#000066">Email address:</font></strong><br>
   <input type="text" id="$af_email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
   <input type="image" src="http://newsletter.jeremyahenry.com/images/go-button.gif" name="submit" value="Submit"><br>
  <input type="hidden" name="r" value="4">
  <input type="hidden" name="a" value="sub">
  <input type="hidden" name="ref" value="none">
  <br>
  <font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes  
  <input type="RADIO" name="h" value="0" checked="checked">No<br>
   </font></form>
   </td></tr></table>
   </center>
    <?php
if(!empty($_SESSION['_mf'])):
   unset($_SESSION['_mf']);
endif;
?>

形式2:

    <?php
function stripZlashes($string)
{
    //This function is to strip slashes for either array or a String
    if (!is_array($string)) return stripslashes($string);
    $nvar = array();
     foreach ($string as $key => $value)
     $nvar[stripslashes($key)] = stripZlashes($value);
     return $nvar;
     }
     if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
   stripZlashes($_SESSION['_mf']);
endif;
     // including the session file
     require_once("session_start.php")
     ?> 
     <form action="process.php" method=post>
     <table align=left border=0 height=300>
     <tr> 
     <td nowrap> 
     <p>&nbsp;&nbsp;&nbsp;&nbsp;Your name:&nbsp;&nbsp;
     &nbsp;&nbsp;<input maxlength=25 name="af first name" id="af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" size=25> />
     </td</tr> 
      <tr> 
     <td nowrap> 
     <p>&nbsp;&nbsp;&nbsp;&nbsp;Your email:&nbsp;&nbsp;
      &nbsp;&nbsp;<input name=af email id="af email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" size=25 maxlength=25> />
     </td></tr>
     <tr>
     <td colspan=2>
     <center>
     <p align=center>Enter your Auction item Name below:
     <br>
     <input name="cf item name" id="cf item name" value="<?php echo (!empty($_SESSION['_cf']['cf_item_name'])?$_SESSION['_cf']['cf_item_name']:'') ?>"  rows="1" />
    <p align=center>
    <input type=submit value="Send Message">
    </td></tr></table>
    </form>
    </center>

好的,现在我有一个问题,它提交正确。。。

<form name="form1">
    <input type="text" value="" name="somename" onkeyup="form2.somename.value=this.value" />
</form>
<form name="form2">
    <input type="text" value="" name="somename" />
</form>

查看上面的代码。希望这能有所帮助。或者,如果这不是您所要求的结果。这样你就可以简单地回答你的要求。

我不知道您的实现的用途或需求:也许它就像一个3步注册表单?它可以用不同的方式来完成,而不会太复杂。

你可以把三张表格放在同一页上,只显示正确的一张根据被张贴到同一页面的数据。这是一种古老的做事方式。有了Ajax调用、模板和javascript,它可能会简单得多,但取决于您的体验。

在每个元素上,您可以根据它们的相关事件提及,例如例如onkeyup="form2.elementname.value=this.value"

最新更新