1

I must be missing something incredibly simple, but I can't see it. I have a function that generates a simple form that should be displayed several times within a table. Whenever I try to call the function with in a table cell, the form is displayed above the table for some reason.

Here's a simplified version of the code:

Php function that generates a form to be displayed multiple times

private function addTaskForm()
{
   // display add task form
   echo "<form method='post' action='#'>
           <select name='task'>
             <option value='1'>Clean</option>
             <option value='1'>Shop</option>
           </select>
           <input type='submit' name='btnSubmit'>
         </form>";
}

Table

echo "<table>
        <tr>
          <td>".addTaskForm()."</td> 
          <td>".addTaskForm()."</td>
          <td>".addTaskForm()."</td> 
          <td>".addTaskForm()."</td>
        </tr>
      </table>";
mrjimoy_05
  • 3,452
  • 9
  • 58
  • 95
Zachary
  • 183
  • 2
  • 15

1 Answers1

2

you dont need to echo on function just return string and i am sure you know about public/private/protected function

codepad


Good Read

  1. PHP: Public, Private, Protected
  2. For comprehensive information : Visibility
Community
  • 1
  • 1
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143