dqrq93879 2014-06-26 16:24
浏览 51
已采纳

使用一个表单填写另外两种表格

OK so I have two different types of forms and I want to use one form to submit them both. I am using a auto-responder form for form1 fields= first, last and email. My second form is a contact me form fields= name. email and a body field. I am trying to use both these forms at one shot. I have a form that will post fields to each form (INDEX.PHP) the problem is I am not sure how to set up form one to post fields into form1 and form2 the way I want. I want to use the fields that match from form index.php to both the other forms (form1, form2). so name and email will go to both forms and the body field will go to form2. The main form will post first and last in the name field of form2....also as you can see from form 1 and 2 each form has a some sort of redirect page I need to work around.? I have main form:

Index.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>

the above form was found on a website and was pretty close to what I want it to do but not exactly.... 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>

Form 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>

ass you can see from the code I was going to use sessions. But not to familiar with it even though I have experience with php I am still quite new to it and need help. I want to pars form data to both forms. and the product name to form two. any help on this would be greatly appreciated.. I hope this is clear enough for some one out there to help.....

Ok New code Three forms 1.main form submits information to form1 and form2. I have set up using a session so I have: 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;

     ?>

That handles variables. My new code for 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>

That form takes input and sets to session. Session.php picks it up and places it in variable form. From here I used a strip for the underscores. and when it goes to form1 and form2 varables pick it up and fill in the form. Here is my new 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;
?>

form2:

    <?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>

Ok now i have an issue with it submitting correctly...

  • 写回答

3条回答 默认 最新

  • dongxian6285 2014-06-26 18:09
    关注
    <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>
    

    check out the above code. hope this could be helpful. Or if this is not the result which you require. so you can be brief with your requirements in reply.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系