【问题标题】:Using one form to fill in two other forms使用一张表格填写另外两张表格
【发布时间】:2014-08-17 14:37:49
【问题描述】:

好的,所以我有两种不同类型的表单,我想使用一个表单来提交它们。我正在为 form1 字段 = 第一个、最后一个和电子邮件使用自动回复表单。我的第二个表格是联系我表格字段=名称。电子邮件和正文字段。我试图一次性使用这两种形式。我有一个将字段发布到每个表单(INDEX.PHP)的表单,问题是我不确定如何设置表单一以按照我想要的方式将字段发布到表单 1 和表单 2。我想使用从表单 index.php 匹配到其他表单(form1、form2)的字段。所以姓名和电子邮件将进入两个表单,而正文字段将进入 form2。主表单将在 form2 的 name 字段中首先和最后发布....从表单 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>

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

<?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 的经验,我对它还是很陌生,需要帮助。我想将表单数据解析为两种表单。和产品名称形成两个。对此的任何帮助将不胜感激..我希望这已经足够清楚,有人可以提供帮助.....

Ok 新代码 三个表单 1.main表单向form1和form2提交信息。 我已经设置了使用会话,所以我有: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;
?>

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>

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

【问题讨论】:

    标签: php jquery forms scripting


    【解决方案1】:

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

    您可以将所有三个表单放在同一个页面中,只显示正确的一个 根据发布到同一页面的数据。这是做事的老方法。 使用 Ajax 调用、模板和 javascript,它可能会更简单,但这取决于 你的经验。

    【讨论】:

    • 我正在尝试能够使用一个表单来提交信息以自动回复注册,并将包含产品名称的电子邮件发送到我收到来自 form2 a 的电子邮件的地方与表格二正文匹配的过滤器设置将通过电子邮件将相应的电子邮件发送给填写表格的人...
    【解决方案2】:

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

    【讨论】:

    • 你能说得更具体一点吗?我对 php 还是有点陌生​​。我不需要像 css 文件一样引用 form1 和 form2 的文件吗?
    【解决方案3】:
    <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>
    

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

    【讨论】:

    • 我不明白这是在做什么。?你能评论他们以帮助我更好地理解我在用这段代码做什么。?我还需要两种后门表格的表格一中的值..谢谢
    • 当您对 form2.elementname 有有效引用时,将在 form1 下添加的任何值都将添加到 form2 的元素中
    • 你能举个form2.elementname的例子吗
    • 尝试执行上面的html内容。你会知道的。感觉有些误会需要解开。简要介绍问题。
    • 当它具有这样的复杂性时,不能简短地回答问题,因为我无法找到我的设计的有效答案......必须更加清晰地让读者理解什么我正在尝试做。也执行它没有做任何事情。可能是因为我需要知道为“form2.somename.value=this.value”的值添加什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-30
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 2021-10-22
    相关资源
    最近更新 更多