php_self表单传递值

时间:2015-09-17 08:51:05

标签: php html forms

HTML

<form action="procces.php" target="_blank" method="post">
<input type="hidden" name="filename" value="myfile.zip" />
<input type="hidden" name="filesize" value="20GB" />
<input type="hidden" name="id" value="1.1.1.1" />
<input type="button" name="button" value="procces"/>

procces.php

 <?php
    $filename = '';
    $filesize = '';
    $id = '';
    if (isset($_POST)) {
    $filename = $_POST['filename'];
    $filesize = $_POST['filesize'];
    $id = $_POST['id'];
    }

    // 1.1.1.1 = http://domainA.com
    // 2.2.2.2 = http://domainb.com
    // 3.3.3.3 = http://domainB.com

    echo "<form action='$_SERVER[PHP_SELF]".$id."' target='_blank' method='POST'>
    <input name='filename' type='hidden' value='".$filename."'/>
    <input name='filesize' type='hidden' value='".$filesize."'/>
    <input name='id' type='hidden' value='".$id."'/>
    <input type='button' name='button' value='procces'/>
    </form>";
    ?>

我想生成$id以使用网址填充<form action='$_SERVER[PHP_SELF]".$id."'。 可以帮我?谢谢 。 。

提交后的示例procces.php

<form action="http://domainA.com" target="_blank" method="post">
    <input type="hidden" name="filename" value="myfile.zip" />
    <input type="hidden" name="filesize" value="20GB" />
    <input type="hidden" name="id" value="1.1.1.1" />
    <input type="button" name="button" value="procces"/>

2 个答案:

答案 0 :(得分:1)

.
.
.
   $id = $_POST['id'];
}
$domains = array[
'1.1.1.1' => 'http://domainA.com',
'2.2.2.2' => 'http://domainA.com',
'3.3.3.3' => 'http://domainA.com',
];
    echo "<form action='$domains[id]' target='_blank' method='POST'>
.
.
.

答案 1 :(得分:0)

写一个条件语句来改变域名,这里是代码

<?php
$filename = '';
$filesize = '';
$id = '';
if (isset($_POST)) {
$filename = $_POST['filename'];
$filesize = $_POST['filesize'];
$id = $_POST['id'];
}
$actionUrl = '';

if($id == '1.1.1.1'){
    $actionUrl = 'http://domainA.com';
}
else if($id == '2.2.2.2'){
    $actionUrl = 'http://domainb.com';
}
else if($id == '3.3.3.3'){
    $actionUrl = 'http://domainB.com';
}
else{
    // if nothing matches default action url
    $actionUrl = 'process.php'; // default
}

echo "<form action='$actionUrl' target='_blank' method='POST'>
<input name='filename' type='hidden' value='".$filename."'/>
<input name='filesize' type='hidden' value='".$filesize."'/>
<input name='id' type='hidden' value='".$id."'/>
<input type='button' name='button' value='procces'/>
</form>";
?>