Formularios HTML en menos de 5 minutos

Written on 10:13 a.m. by Jeiff

Este es otro pequeño HOW-TO basado en el framework PEAR, esta vez crearemos en menos de 5 minutos un formulario con su validación listo para ser enviado.

La librería a utilazar se llama HTML_QuickForm, para su instalación podriamos hacerlo así:

$ pear install HTML_QuickForm

O bien puedes descargar el paquete desde http://pear.php.net/package/HTML_QuickForm/download

Una vez que cuentas con la libreria es hora de crear nuestro formulario:

<?

require_once("HTML/QuickForm.php");

//Creamos nuestro formulario con el nombre de frmBuscar
$formulario = new HTML_QuickForm('frmBuscar');
//Asignamos los valores por deafault de nuestro elementos
$formulario->setDefaults(array('busqueda' => '',
'opcion'=>'1'));

//Creamos un encabezado para nuestro formulario
$formulario->addElement('header', null,
'<div align="center">B&uacute;squeda de Anuncio Clasificado</div>');

/*Agregamos un campo de texto con el nombre de busqueda y la
leyenda Palabra a Buscar, tamaño de 50 caracteres y solo se
permitira capturar 255 caracteres */
$formulario->addElement('text', 'busqueda', 'Palabra a Buscar',
array('size' => 50, 'maxlength' => 255));

//Agregamos un campo oculto en nuestro formulario
$formulario->addElement('hidden','opcion');

//Apartir de aquí crearemos un elemento de tipo SELECT
//Iniciaremos por crear las opciones para este elemento
$opts = array("0"=>"Todos","puebla"=>"PUEBLA","tlaxcala"=>"TLAXCALA",
"df"=>"DF Mexico","veracruz"=>"VERACRUZ");
/*Creamos el elemento select con nombre de estado, la leyenda Estado,
y agregamos la opciones*/
$s_estado=$formulario->createElement('select','estado','Estado:',$opts);
$formulario->addElement($s_estado);

//Agregamos nuestro boton para mandar la información
$formulario->addElement('submit', null, 'Buscar');

/*Aplicamos un filtro a nuestro campo busqueda para eliminar
espacios en blanco tanto a la derecha como a la izquierda */
$formulario->applyFilter('busqueda', 'trim');

/*Y pones la restricción, para que el usuario tenga que escribir algo
en nuestro campo busqueda antes de ser enviado */
$formulario->addRule('busqueda', 'Teclee la palabra a Buscar', 'required', null, 'client');

//Por ultimo solo despelgamos nuestro formulario
$formulario->display();
?>

Este código nos generara una página HTML que contendra un formulario de busqueda, el cual contendra un campo de texto validado, un select para seleccionar un estado, y un campo oculto con valor de 1.

En la segunda parte de este pequeño HOW-TO explicare cada una de las funciones utilizadas aqui, y escribire un ejemplo un poco mas completo.

If you enjoyed this post Subscribe to our feed

4 Comments

  1. Anónimo |

    [u][b]Xrumer[/b][/u]

    [b]Xrumer SEO Professionals

    As Xrumer experts, we secure been using [url=http://www.xrumer-seo.com]Xrumer[/url] quest of a sustained fix things being what they are and grasp how to harness the enormous power of Xrumer and turn it into a Banknotes machine.

    We also provender the cheapest prices on the market. Many competitors see fit charge 2x or temperate 3x and a end of the continuously 5x what we responsibility you. But we maintain in providing enormous mending at a tearful affordable rate. The unbroken incidental of purchasing Xrumer blasts is because it is a cheaper variant to buying Xrumer. So we plan to keep that thought in cognizant and yield you with the cheapest rate possible.

    Not only do we be suffering with the most successfully prices but our turnaround time for the treatment of your Xrumer posting is wonderful fast. We will secure your posting done before you distinguish it.

    We also provide you with a roundish log of successful posts on different forums. So that you can notice also in behalf of yourself the power of Xrumer and how we have harnessed it to benefit your site.[/b]


    [b]Search Engine Optimization

    Using Xrumer you can think to realize thousands upon thousands of backlinks for your site. Myriad of the forums that your Place you will be posted on oblige high PageRank. Having your association on these sites can categorically help establish up some top-grade dignity recoil from links and uncommonly aid your Alexa Rating and Google PageRank rating utterly the roof.

    This is making your put more and more popular. And with this developing in regard as familiarly as PageRank you can think to witness your site really rank gamy in those Search Engine Results.
    Conveyance

    The amount of see trade that can be obtained before harnessing the power of Xrumer is enormous. You are publishing your site to tens of thousands of forums. With our higher packages you may still be publishing your locale to HUNDREDS of THOUSANDS of forums. Create 1 collection on a stylish forum last will and testament by enter 1000 or so views, with say 100 of those people visiting your site. These days assume tens of thousands of posts on fashionable forums all getting 1000 views each. Your traffic will withdraw through the roof.

    These are all targeted visitors that are interested or bizarre in the matter of your site. Imagine how assorted sales or leads you can fulfil with this great gang of targeted visitors. You are literally stumbling upon a goldmine friendly to be picked and profited from.

    Remember, Traffic is Money.
    [/b]

    BECOME ENTHUSIASTIC ABOUT YOUR CHEAP ERUPTION TODAY:


    http://www.xrumer-seo.com

     
  2. Anónimo |

    [B]NZBsRus.com[/B]
    No More Laggin Downloads Using NZB Downloads You Can Rapidly Find HD Movies, PC Games, MP3 Singles, Applications & Download Them at Electric Speeds

    [URL=http://www.nzbsrus.com][B]Usenet Search[/B][/URL]

     
  3. Anónimo |

    [url=http://www.23planet.com]online casino[/url], also known as accepted casinos or Internet casinos, are online versions of celebrated ("buddy and mortar") casinos. Online casinos franchise gamblers to booze and wager on casino games to a t the Internet.
    Online casinos typically contract aside on the securities dealing odds and payback percentages that are comparable to land-based casinos. Some online casinos directing higher payback percentages payment responsibility gismo games, and some put exposed payout correlation audits on their websites. Assuming that the online casino is using an fittingly programmed unspecific assorted generator, catalogue games like blackjack coveted an established borderline edge. The payout incise up during these games are established to the gist the rules of the game.
    Assorted online casinos sublease or disgorge about their software from companies like Microgaming, Realtime Gaming, Playtech, Worldwide Contrivance Technology and CryptoLogic Inc.

     
  4. Anónimo |

    top [url=http://www.001casino.com/]free casino bonus[/url] check the latest [url=http://www.realcazinoz.com/]casino bonus[/url] free no deposit hand-out at the leading [url=http://www.baywatchcasino.com/]casino perk
    [/url].

     

Publicar un comentario