2012-09-06 21 views
-2

我有如下的HTML和PHP代码。我有一个代码文件html2word.php使用PHP将所有html文件中的值转换为MS-Word

<form method="post" action="htmltortf.php">  
    <table> 
     <tr> 
      <td colspan="3">Convert html to doc</td> 
     </tr> 
     <tr> 
      <td colspan="3">Choose the answer</td> 
     </tr> 
     <tr> 
      <td><input type="radio" name="004" value="1" <?=($_POST['004']=='1' ? 'checked="checked"' : '')?>/>1</td> 
      <td><input type="radio" name="004" value="2" <?=($_POST['004']=='2' ? 'checked="checked"' : '')?>/>2</td> 
      <td><input type="radio" name="004" value="3" <?=($_POST['004']=='3' ? 'checked="checked"' : '')?>/>3</td> 
     </tr> 
     <tr> 
      <td colspan="3"><input type="submit" name="submit" value="submit" /></td> 
     </tr> 
    </table> 
    <?php 
     if(isset($_POST['submit'])) 
     { 
      header("Content-type: application/vnd.ms-word"); 
      header("Content-Disposition: attachment;Filename=html2doc.doc"); 
     } 
    ?>  
</form> 

我需要什么:

当用户在单选框选中它也显示,当我将其转换为MS-Word中的无线电框被选中。

问题:

当我将它转换为Word文档,它会显示我检查无线框,但它让我看到错误消息:

Notice: Undefined index: 004 in C:\wamp\www\html to docv2\htmltortf.php on line 51

我该如何解决这个问题?

回答

0

当用户点击提交按钮时,表单数据发送到服务器。它存储在$ _POST数组中,所以当你显示这个页面时,你必须先检查任何数据接收器。
尝试类似的东西(更换单选按钮HTML与此代码):

<td><input type="radio" name="004" value="1" <?=((isset($_POST['004']) && $_POST['004']=='1') ? 'checked="checked"' : '')?>/>1</td> 
<td><input type="radio" name="004" value="2" <?=((isset($_POST['004']) && $_POST['004']=='2') ? 'checked="checked"' : '')?>/>2</td> 
<td><input type="radio" name="004" value="3" <?=((isset($_POST['004']) && $_POST['004']=='3') ? 'checked="checked"' : '')?>/>3</td> 

检查完整的解决方案: http://codepad.org/QThcTGdO

+0

非常感谢,但它显示错误消息'注意事项:用C 004:未定义指数: \ wamp \ www \ html到第75行的docv2 \ htmltortf.php。当我将它转换为word文档时,它可以工作。 – user1629258

+0

此通知不是严重错误。这cozed我真的不检查'isset($ _ POST ['004'])''。如果你会告诉我你的75线,我会更确切地说你。 – StasGrin

+0

这是第75行的代码'​​ /> 1'。谢谢, – user1629258