wkilc Posted July 30, 2008 Share Posted July 30, 2008 Howdy, My website has about a dozen different application forms, which are used annually for festival registrations. Each year, I manually go in to each form and change dates, names, etc... It's a pain... because these names and dates appear in each form itself, the "browser-out" page, the e-mail templates, etc... I figure this year, I'll create includes where I define $form_1date, $form2_date, $form3_date... that way I only have to edit one page per year. My question is just that... can I create a single include with a dozen dates, names, etc,... or I am better off making a dozen "include" php pages, each with one date, one name, etc... Does that make sense? I'd rather keep it all in one file, making it easier to edit each year.... but is it more efficient to create an "include" for each form? Thanks. ~Wayne Link to comment https://forums.phpfreaks.com/topic/117273-php-includes/ Share on other sites More sharing options...
Goldeneye Posted July 30, 2008 Share Posted July 30, 2008 You can just define all the variables in one file (assuming they're all unique), we'll call 'variables.php'. <?php $form1_date = 'July 28, 2008'; $form1_name = 'Foo Bar'; $form1_contact = '[email protected]'; $form2_date = ... $form2_name = ... $form2_contact = ... // And so on... ?> And then you go through all your forms and replace and the information with those variable names. Example: <?php echo 'Welcome to registration! This is Foo Bar speaking!'; ?> Would be replaced with: <?php echo 'Welcome to registration! This is' . $form1_name . 'speaking!' ?> You could also use double quotes <?php echo "Welcome to registration! This is $form1_name speaking!" ?> Personally, I prefer using single quotes because I use double quotes for my HTML attributes (Just so I don't have to escape those HTML-Attribute quotes with a '\'. Link to comment https://forums.phpfreaks.com/topic/117273-php-includes/#findComment-603248 Share on other sites More sharing options...
vikramjeet.singla Posted July 30, 2008 Share Posted July 30, 2008 i would suggest use these: define('FORM_ONE_DATE', 'July 28, 2008'); define('FORM_ONE_NAME', 'ABC'); define('FORM_ONE_CONTACT', '[email protected]'); so that to protect them to override... you may also save these entries in table. In this way you can create a interface for your own to change them every year or so and get these values in your forms Link to comment https://forums.phpfreaks.com/topic/117273-php-includes/#findComment-603282 Share on other sites More sharing options...
MasterACE14 Posted July 30, 2008 Share Posted July 30, 2008 you could always make a function which generates a form for you. function myform($formname,$action) { echo <<<_FORM <form name="{$formname}" action="{$action}"> </form> _FORM; } something along those lines. However there is better ways of doing this. Link to comment https://forums.phpfreaks.com/topic/117273-php-includes/#findComment-603323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.