-2

I have the HTML and PHP code as below. I have code one file html2word.php:

<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>

What I need:

When the user checked on radio box it is also display the radio box is checked when I convert it to MS-Word.

The problem:

When I converted it to word document, it will display the radio box that I checked but it shows me the error message:

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

How do I fix this?

Avada Kedavra
  • 8,523
  • 5
  • 32
  • 48
user1629258
  • 39
  • 2
  • 7

1 Answers1

0

When user clicks on submit button, form data sends to server. It stores in $_POST array, so when u display this page, u must check for any data receiver earlier or not.
Try something like that (replace radio buttons html with this code) :

<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>

Check full solution: http://codepad.org/QThcTGdO

StasGrin
  • 1,800
  • 2
  • 14
  • 30
  • Many thanks, but it displays error message `Notice: Undefined index: 004 in C:\wamp\www\html to docv2\htmltortf.php on line 75`.When I convert it to word document it works. – user1629258 Sep 07 '12 at 01:19
  • this notice isn't critical error. this cozed coz i dont check if `isset($_POST['004'])`. If u'll show me your 75 line I'll say u with more exactly. – StasGrin Sep 07 '12 at 09:10
  • This is code on line 75 `/>1`. Thanks, – user1629258 Sep 07 '12 at 09:14
  • I use this one it works but when I check on the one radio box and I convert it to Ms word, it will show all radio box are checked.How do I fix this? Thanks. – user1629258 Sep 07 '12 at 10:14
  • dude, if u just copy that code to all radiobuttons... so i guess u dont understand how it works. – StasGrin Sep 07 '12 at 10:59
  • i changed answer, check this one. – StasGrin Sep 07 '12 at 11:00