gpt4 book ai didi

php - 提交表单时,使用 JavaScript 创建的表单元素不会在 php 中使用 $_POST

转载 作者:行者123 更新时间:2023-11-29 16:27:00 24 4
gpt4 key购买 nike

总览:

我有三个 php 页面:

  • 一个是数据输入页面,它有一个文本字段,onkeydown 更改 iFrame 的 URL,
  • iFrame 包含一个页面,用于在 LDAP 和 mySQL 数据库中搜索电子邮件地址。当点击搜索结果时,它会向数据输入页面添加一个禁用的文本输入。
  • 并且有一个接收表单信息并发送电子邮件的操作页面。

  • 问题是没有任何表单数据从静态表单元素或由 JavaScript 创建的动态表单元素传递到操作页面。

    form.php

    <SCRIPT type="text/javascript">
    // <!--

    function delRecipient(object) {
    var answer = window.confirm("Remove recipient?")
    if (answer){
    countChildren = object.parentNode.parentNode.childNodes.length;
    oldName = "recipient" + countChildren;
    newName = object.parentNode.id;
    object.parentNode.parentNode.removeChild(object.parentNode);
    document.getElementById(oldName).id = newName;
    }
    }

    function iFrameHeight(id) {
    var content_height=document.getElementById(id).contentWindow.document.body.scrollHeight;
    document.getElementById(id).height=content_height;
    document.getElementById(id).style.display='block';
    }

    function iFrameOpen(id) {
    document.getElementById(id).style.display='block';
    iFrameHeight(id);
    }

    function iFrameClose(id) {
    var dt = new Date();
    while ((new Date()) - dt <= 250) { /* Do nothing for 250 miliseconds. */ }
    document.getElementById(id).style.display='none';
    }

    var selectNum=-1;
    function iFrameSearch(e) {
    var keynum;
    var keychar;
    var numcheck;

    if(window.event) {
    keynum = e.keyCode;
    }
    else if(e.which) {
    keynum = e.which;
    }

    // Use up and down arrow keys to select recipient:
    // Keynum 38 is the up arrow key,
    // 40 is the down arrow key
    // 13 is the enter key (for future use...)
    if(keynum==38) { --selectNum; }
    else if(keynum==40) { ++selectNum; }
    else {
    selectNum=-1;
    }

    keychar = String.fromCharCode(keynum);
    keychar = keychar.replace(/([^- 'a-zA-Z])/gi,"");

    document.getElementById('members').src='iframe.php?keyword=' + document.getElementById('search').value + keychar + '&select=' + selectNum;
    iFrameHeight('members');

    return false;
    }

    // -->
    </SCRIPT>

    <div class="content">
    <form name="form" id="form" method="post" action="action.php">
    <h3>Select Recipients</h3>

    To:
    <div id="recipients" class="recipients"></div>
    <input type="text" id="search" class="search" autocomplete="off" onfocus="iFrameOpen('members'); iFrameHeight('members'); if(this.value=='Type name here to add a recipient...'||this.value=='Type name here to add another recipient...'){this.value='';}" onblur="if(this.value==''&&document.getElementById('recipients').getElementsByTagName('div').length>0){this.value='Type name here to add another recipient...';} else if(this.value==''){this.value='Type name here to add a recipient...';}" value="Type name here to add a recipient..." onkeydown="iFrameOpen('members'); iFrameSearch(event); iFrameHeight('members');" /><br>
    <iframe src="" id="members" width="400" height="0" frameborder="0" scrolling="no" onmouseout="iFrameClose('members')" style="display: none; position:relative; top:0px; left:0px;"></iframe>

    <input type="hidden" name="message" value="<?php $_REQUEST['var_from_previous_page'] ?>" />

    <input type="submit" value="Send" />

    </form>
    </div>

    iFrame.php

    <SCRIPT type="text/javascript">
    // <!--

    function newRecipient(name,email) {
    var recipientNumber = parent.document.getElementById("recipients").childNodes.length++;

    var recipient = document.createElement("DIV");
    recipient.id = "recipient" + recipientNumber;
    recipient.className = "recipient";
    recipient.innerHTML = "<INPUT type=\"text\" name=\"recipient" + recipientNumber + "\" value=\"" + name + " <" + email + ">\" disabled=\"disabled\" /><div class=\"delete\" onclick=\"javascript:delRecipient(this)\">&nbsp;</div>";
    parent.document.getElementById("recipients").appendChild(recipient);
    parent.document.forms[0].search.value = "";
    parent.document.forms[0].search.focus();
    parent.document.getElementById("members").style.display="none";
    }

    // -->
    </SCRIPT>

    <?php

    // CUT-OUT A BUNCH OF IRRELEVANT PHP which searches the LDAP and mySQL databases, sorts, formats, etc.

    echo "<TABLE cellspacing=\"0\" callpadding=\"0\" width=\"1000\">\n";

    for ($i=0; $i<$returned; $i++) {
    $row_type = ($i%2 == 0) ? "even" : "odd";
    $select = $_REQUEST['select'] % $returned;
    if($i == $select) { $row_type .= " selected"; $selected = true; }
    else { $selected = false; }
    $name = explode(" (",$info[$i]["cn"][0]);
    $name_boldkeyword = nameCapitalize(str_ireplace(strtolower($_REQUEST['keyword']), "<b>" . strtolower($_REQUEST['keyword']) . "</b>", $name[0]));
    $email_boldkeyword = strtolower(str_ireplace( $_REQUEST['keyword'], "<b>" . $_REQUEST['keyword'] . "</b>", $info[$i]["mail"][0]));
    echo '<tr class="' . $row_type . '" onclick="newRecipient(\'' . addslashes(ucwords($name[0])) . '\',\'' . $info[$i]["mail"][0] . '\');"><td height="20" style="overflow: hidden;">' . ucwords($name_boldkeyword) . ' &lt;' . $email_boldkeyword . "&gt;</td></tr>\n";
    }

    echo '<tr class="last"><td>Showing ' . $returned . ' of ' . $info["count"] . " entries.</td></tr>\n";
    echo "</table>";

    action.php

    var_dump($_REQUEST) 仅包含 session cookie 和广告 cookie。没有 $_POST 变量。

    如果您使用 URL,它将转储您添加的变量。

    最佳答案

    您似乎没有指定任何 name="" <form>以外的参数,它不是真正有用的地方。

    尝试这样做,你应该会很好。

    关于php - 提交表单时,使用 JavaScript 创建的表单元素不会在 php 中使用 $_POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5069782/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com