Ver Mensaje Individual
  #3 (permalink)  
Antiguo 31/12/2005, 02:45
Casuis
 
Fecha de Ingreso: septiembre-2005
Mensajes: 142
Antigüedad: 18 años, 8 meses
Puntos: 3
Foro OOP

Bueno yo te recomendaria HTML_QuickForm que se puede usar para PHP4 y PHP5 no esta nada mal, HTML_QuickForm es un paquete PEAR solo tienes que hacer un :
Código:
pear install HTML_QuickForm
luego prueba en ejecutar el siguiente codigo
Código PHP:
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
      <title>A simple form</title>
  </head>

  <body>
  <?php
      
require_once "HTML/QuickForm.php";

      
$form = new HTML_QuickForm('frmTest''get');
      
$form->addElement('header''hdrTesting''Un simple formulario');
      
$form->addElement('text''txtnombre''Tu nombre?');
      
$form->addElement('text''txtapellidos''Tu apellido?');
      
$form->addElement('text''txtedad''edad?');
      
$form->addElement('text''txtTelf''numero de telefono?');
      
$form->addElement('reset''btnClear''Limpiar');
      
$form->addElement('submit''btnSubmit''Enviar');
      if (
$form->validate()) {
          
// If the form validates then freeze the data
          
$form->freeze();
      }
      
$form->display();
  
?>
  </body>
</html>
si programas con un MVC y utilizas Smarty que seria lo más habitual como motor de templates puedes procesar los formularios de la siguiente manera
Código PHP:
<?php
      
require_once "HTML/QuickForm.php";
      require_once 
'HTML/QuickForm/Renderer/ArraySmarty.php';
      require_once 
'Smarty.class.php';

      
$form = new HTML_QuickForm('frmTest''get');
      
$form->addElement('header''hdrTesting''Testing Smarty');
      
$form->addElement('text''txtFirstName''First name?');
      
$form->addElement('text''txtLastName''Last name?');
      
$form->addElement('text''txtAge''Age?');
      
$form->addElement('text''txtTelephone''Telephone number?');
      
$form->addElement('reset''btnClear''Clear');
      
$form->addElement('submit''btnSubmit''Submit');
      if (
$form->validate()) {
          
# If the form validates then freeze the data
          
$form->freeze();
      }

      
// Create the template object
      
$tpl =& new Smarty;
      
$tpl->template_dir '.';
      
$tpl->compile_dir  '/tmp';

      
// Create the renderer object    
      
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl);

      
// build the HTML for the form
      
$form->accept($renderer);

      
// assign array with form data
      
$tpl->assign('form_data'$renderer->toArray());

      
// parse and display the template
      
$tpl->display('smarty1.tpl');

  
?>
y el template
Código PHP:
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  <!--  
$Idsmarty-guide.tpl,v 1.1 2005/03/03 19:26:54 kae Exp $ -->
  <
html>
  <
head>
    <
title>Smarty template demonstration</title>
    <
style type="text/css">
      {
literal}   
        
th {
          
text-alignright;
        }
      {/
literal}
    </
style>
  </
head>

  <
body>
  <
h2>
    {
$form_data.header.hdrTesting}
  </
h2>
  <
form {$form_data.attributes}>
    <!-- 
Display the fields -->
    <
table>
      <
tr>
        <
th>{$form_data.txtFirstName.label}</th>
        <
td>{$form_data.txtFirstName.html}</td>
        <
th>{$form_data.txtLastName.label}</th>
        <
td>{$form_data.txtLastName.html}</td>
      </
tr>
      <
tr>
        <
th>{$form_data.txtAge.label}</th>
        <
td>{$form_data.txtAge.html}</td>
        <
th>{$form_data.txtTelephone.label}</th>
        <
td>{$form_data.txtTelephone.html}</td>
      </
tr>
      <!-- 
Display the buttons -->
      <
tr>
        <
td align="center" colspan="4">
          {
$form_data.btnClear.html}&nbsp;{$form_data.btnSubmit.html}
        </
td>
      </
tr>
      <!-- 
Display the copyright -->
      <
tr>
        <
td style="font-size:11px; color: navy; text-align: center" colspan="4">
          &
copy;2004 Tiger Computing Ltd
        
</td>
      </
tr>
    </
table>
  </
form>
  </
body>
  </
html
En fin es un comienzo muy bueno.

Última edición por Casuis; 31/12/2005 a las 03:50