Best practice: Define form field name in backend or the template

Posted by AbcAeffchen on Stack Overflow See other posts from Stack Overflow or by AbcAeffchen
Published on 2014-08-14T21:49:54Z Indexed on 2014/08/21 22:20 UTC
Read the original article Hit count: 153

Filed under:
|
|
|

If you designing a webpage you should separate the backend from the frontend. But if you use forms you have to name them. But where should you set this name?

e.g.

PHP:
$fieldName = 'email';
$template->setVar('field_name', $fieldName)
...
if(!empty($_POST))
    validate($_POST[$fieldName]);

Template:
<input type="text" name="{$field_name}">

Or just

PHP:
if(!empty($_POST))
    validate($_POST['email']);

Template:
<input type="text" name="email">

Or should I write a function that can be called from the template an converts an array of field data (name, type, value, id, class, ...) into html code?

Is there a best practice where to define fieldnames (types,etc.)?

Notice: I used php and smarty like pseudocode (and tags), but its a general question.

© Stack Overflow or respective owner

Related posts about php

Related posts about forms