For example, there is an addnews.php page with a form for adding news to the site. There is an editnews.php page with the same form for editing a specific news. How do I make one form for both pages so as not to duplicate? Suppose if on the addnews.php page I need to remove / add some kind of thread field, I will have to change the editnews.php page too ... and this somehow does not work out nicely ... 21st century fsyo-currents)

Of course, you can do this:

<input type="text" name="title" value="<?php echo !empty($title) ? $title : null; ?>" /> 

But this is not very beautiful ... Maybe there is a more flexible way?

    1 answer 1

    Option A: select the static part of the form in a separate file and connect it where necessary.
    Option B: write a function that will generate the form in the desired format based on the parameters passed to it.
    Select this function in a separate file and connect it where necessary.

    • one
      in the editnews file in the form I need to substitute the value of the selected news. for example, <input type = "text" name = "title" value = "<? php echo $ title;?>" />. And if in the form.php file I register it, addnews.php will swear at the type there is no variable $ title - vinnie
    • Corrected the answer. - VenZell