Reusing forms in php

Asked

Viewed 62 times

1

I’m working on a PHP site where I have about 20 different pages that have the same form. Currently this site has in the 20 pages the same code for the form (Ctrl+c/Ctrl+v). Is there a way to use the same form on these 20 pages in a simpler way? I’m not used to PHP.

  • http://php.net/manual/en/function.include.php

  • 1

    Can you show me an example within this scenario?

1 answer

4


What you need is to create a php file (for example formulario.php) only with the form code and then include it in the 20 files.

So you only need to change the code in one place, and in the 20 files you only need to do:

<?php include('/formulario.php' ); ?>

http://php.net/manual/en/function.include.php

This is very common in parts of the site that are common, such as headers, menus or footer. This technique is often used to include files that only have functions that are useful and common to specific pages.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.