将数据从 HTML 传递到 PHP,然后再传递回 HTML


Passing data from HTML to PHP and back to HTML

所以我想在id="id_input"中写一个链接,当我按下按钮name="b"时,我希望该链接转到第2.php行中的第$html->load_file((行;然后变量从page2.php$slbl传递到textarea name="desc_name"中的page1.php。

我是网络编程的新手,我正在学习,所以如果你愿意,请向我解释。我尝试了我能找到的一切,但没有成功。正因为如此,我需要解释这个例子。

页1.php

<html>
<body>
<?php   
include ("page2.php");
?>
<form action="page1.php" method="post" enctype="multipart/form-data">
                <div>
                <div><textarea name="desc_name" rows="7" cols="50" id="id_desc" value="<?php echo (isset($slbl))?$slbl:'';?>"></textarea></div>
                <div><input id="id_input" type="text" name="name_input" size="50">
                    <button name="b" type="button">Button</button></div>
<div>
                <div><input type="submit" name="submit" value="Publish"></div>
</div>
</form>
</body>
</html>
<?php
...code for saving in mysql...
?>

页2.php

<?php
        include ("simple_html_dom.php");
        // Create DOM from URL or file
        $html = new simple_html_dom();
        $html->load_file(<!--i need here url from id="id_input"--!>);
        $html = $html->find('.summary_text', 0);
        $html2 = strip_tags($html);
        $html2 = trim($html2);
        $slbl = $html2; 
?>

为什么不使用jquery来实现这个目的?

试试这个:

<html>
<body>
<form action="page1.php" method="post" enctype="multipart/form-data">
                <div>
                <div><textarea name="desc_name" rows="7" cols="50" id="id_desc"></textarea></div>
                <div><input id="id_input" type="text" name="name_input" size="50">
                    <button name="b" class="b" type="button">Button</button></div>
<div>
                <div><input type="submit" name="submit" value="Publish"></div>
</div>
</form>
</body>
</html>
<script>
$(".b").click(function () {
    var val = $("#id_input").val();
    $.post("page2.php",{a:val},function (data){
        $("#id_desc").val(data);
    });
});
</script>
<?php
...code for saving in mysql...
?>

页2.php :

<?php
    if(isset($_POST["a"])) {
        $a = $_POST["a"];
        include ("simple_html_dom.php");
        // Create DOM from URL or file
        $html = new simple_html_dom();
        $html->load_file(); //you can use $a here as per your need.
        $html = $html->find('.summary_text', 0);
        $html2 = strip_tags($html);
        $html2 = trim($html2);
        echo $slbl = $html2; 
        exit;
    }
?>