AotN
AotN

Reputation: 566

Should I write the form and processor in the same file or seperate them?

In terms of best practices of PHP, is it better practice to write the processing script and the form in the same file or have them separate in different files? How does each scale in proportion to each other for larger projects?

For example, should I write it as:

login.php

<?php
process_form_here();
?>
<form>
<input>
</form>

Or should I write it as:

processor.php

<?php
process_form_here();
?>

login.html

<form>
<input>
</form>

I've been trying to decide for a while between making it more abstract or more condensed... Is there a certain way that most web developers follow?

Upvotes: 3

Views: 62

Answers (3)

Rel
Rel

Reputation: 2814

In terms if scaling it's much better to keep the business logic separate from the view as stated already. This makes things much easier to adapt at a later time and cope with change and expansion. This also allows for reusability.

Upvotes: 1

Mark
Mark

Reputation: 1068

I think it is generally seen to be a better practice to separate them. Doing so gives you the added benefit of allowing you to guide alternate input routes into the same processor (making it more reusable).

Upvotes: 3

Smitesh Mangelkar
Smitesh Mangelkar

Reputation: 1

as matter of fact for PHP there is no specific practice such as inline, internel or external you can adapt whichever you are comfortable with. for example for form you can use inline if fields are few. but if you see CMS (wordpress, etc.) file structure you will come to know. think on it see the difference

Upvotes: 0

Related Questions