【问题标题】:Submitting a form in new window with php使用php在新窗口中提交表单
【发布时间】:2014-11-17 04:26:30
【问题描述】:

尝试使用 php.ini 提交表单。当表单完成并点击“提交”时,我希望加载一个新网页,显示客户的所有凭据和选择以及客户的注册号。我想使用“post”方法使用外部 .php 文件创建新页面。

这是我的表格:

<form name="form1" method="post" action="confirmation.php">

    What is your name? <input type="text" name="fullname" size="25" /><br />
    Your address: <input type="text" name="address" size="25" /><br />
    Your email: <input type="text" name="email" size="25" /><br />
    Your phone number (home/mobile): <input type="text" name="phonenumber" size="25" />


    What type of apartment are you willing to rent?:<br />
    <input type="checkbox" name="1Bedroom" /> 1 bedroom<br />
    <input type="checkbox" name="2Bedroom" /> 2 bedroom<br />
    <input type="checkbox" name="3Bedroom" /> 3 bedroom<br />


    Rental Type:<br />
    <input type="radio" name="type" value="weekly" /> Weekly <br />
    <input type="radio" name="type" value="monthly" /> Monthly <br />

    Starting Date for Rental <input type="date" name="startingdate" size="25" />
    <br />

    <input type="submit" value="Submit Form" />


</form>

到目前为止我已经尝试过了(没有公寓类型、租赁类型、开始日期):

<?php 
 echo $_POST["fullname"]; <br />
 echo $_POST["address"]; <br />
 echo $_POST["email"]; <br />
 echo $_POST["phonenumber"]; <br />
?> 

但是来自表单的输入没有在新窗口中出现。

【问题讨论】:

  • 你能展示一下你的
    标签是什么样子的吗?还请发布您处理请求的php代码
  • 我将我的php文件命名为confirmation.php @binderbound
  • 你的意思是在一个新窗口中,你只想打印表单中的值?
  • 是的,将打开一个新窗口,其中包含表单中的值和选项以及注册号。最终我想创建一个文本文件来存储客户端的所有信息。 @Rizier123

标签: php html forms post


【解决方案1】:

如果您想在提交时打开新窗口。试试这个

<form target="_blank" action="confirmation.php" method="post">

    -- Your code here --

</form>

【讨论】:

  • 欢迎。如果我的答案是您想要的,请点赞或选择最佳答案。
  • 好吧,它在提交时帮助我打开了新窗口,但是 php 代码仍然没有打印表单中输入的值
  • 试试这个 if(isset($_POST["fullname"])){ echo $_POST["fullname"]; }else{ echo 'fname 未设置'; } 然后告诉我结果是什么。
【解决方案2】:

我假设您正在尝试通过重定向在 confirmation.php 上获取这些值,并且根据您提供的内容,您只需要修复回声。

<?php 
 echo $_POST["fullname"]. '<br />';
 echo $_POST["address"]. '<br />';
 echo $_POST["email"]. '<br />';
 echo $_POST["phonenumber"]. '<br />';
?>

如果您尝试在 confirmation.php 以外的地方访问这些值,则需要使用会话。

【讨论】:

  • 我修复了编码,但它仍然没有将值提交到 php 文件。 @EternalHour 它只是作为租赁名称出现:地址:电子邮件地址:电话号码:
  • @Sassn 添加您的确认.php 文件的内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-04
  • 1970-01-01
  • 2013-05-04
  • 2013-10-18
  • 1970-01-01
  • 2012-08-30
  • 2013-04-24
相关资源
最近更新 更多