1

I've this file - t.php, which has an editable table with submit buttons at the end for the last row.

Now I just want the last row and a hidden input element as part of a form to be submitted to another file ts.php. This's what I'm doing. But the output isn't what I expected.

Here's d code of t.php:

<?php
$id = "id1";
$hid = "hidden msg";
print "<table width='100%' border='0' align='center' cellpadding='3' cellspacing='1'>";
print "<thead><tr><th>field1</th><th>field2</th><th>sub</th></tr></thead>";
print "<tr>";
for ($i = 0; $i<3; $i++) {
    print "<tr><td>qweert</td><td>sdfgdfg</td><td>SUB</td></tr>";
}
print "<form method='post' action='ts.php'>
        <tr><td name='edit1' contenteditable='true'> edit </td>
        <td name='edit2' contenteditable='true'> edit </td>
        <input type='hidden' name='table' value = {$hid} \>
        <td > <input type='submit' value='submit' name='rowSubmit'> </td></tr>
        </form>"
?>

In ts.php I'm just printing the post data like this :

<?php
    print_r ($_POST);
?>

I want the table cell data which I edited to come in the form post data, but what I get is this :

Array ( [table] => hidden [rowSubmit] => submit )

Can someone please help?

EDIT: replaced all double quotes in print statements with single quotes

user3248186
  • 1,518
  • 4
  • 21
  • 34
  • Use single quotes for all attribute encapsulation. `edit1` and `edit2` need to be `input`s. `table` needs its value in quoted as well, as is it splits on the space. – chris85 Mar 10 '17 at 11:54
  • You missed `value = {$hid}`, if addressing comments post in the comments, not as an update. Still the same issue exists. – chris85 Mar 10 '17 at 12:06
  • just giving a table the `contenteditable` attribute doesn't make the data in it get posted anywhere. As it stands there are only two inputs in your form that are getting passed to the next page ([table] and [hidden]). If you want to send other info using PHP, you'll need to add input fields. Otherwise, look into Jquery. – Lucas Krupinski Mar 10 '17 at 12:17
  • can you please write an answer, clearly i didn't understand your solution – user3248186 Mar 10 '17 at 12:18
  • how can i get whatever edit i make in table cell as value of input field? – user3248186 Mar 10 '17 at 12:19
  • `input`s are the only elements sent with a `form`. I don't know what `edit` does but it needs to populate an `input` in the `form`. Use the `@`s, notifications aren't sent otherwise. Also `value = {$hid}` needs to be quoted, `value ='{$hid}'`. – chris85 Mar 10 '17 at 12:30
  • 'edit' is just some sample data I wrote to fill up the table cell – user3248186 Mar 10 '17 at 12:38

1 Answers1

0

Content Editable does not work as a form element. Only javascript can allow it to work. See the below link for detail. Can div with contenteditable=true be passed through form?

Community
  • 1
  • 1