Re: Re: [QuickForm] Rules for a costum Form?
| From: | Bertrand Mansion | Date: | Thu, 30 May 2002 16:49:11 +0000 |
| Subject: | Re: Re: [QuickForm] Rules for a costum Form? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-1524@lists.php.net to get a copy of this message | ||
le 30/05/02 18:16, Frank Thiel à thier6@gmx.de a écrit :
> Here is the Code:
>
> <?php
> if(DB::isError($db))
> {
> die("Couldn't connect to database");
> }
> else
> {
>
>
> file://function HTML_QuickForm($formName="", $method="POST",
> $action="",
> $target="_self", $attributes=null)
> $form = new HTML_QuickForm('frmTest', 'POST', $PHP_SELF);
>
> // clear all templates so we can give it a custom look
> $form->clearAllTemplates();
>
> // Fills with some defaults values
> $defaultValues['BannerIMG'] = $uRow[1];
> $defaultValues['BgIMG'] = $uRow[2];
> $defaultValues['MainCategory'] = array('default');
> $defaultValues['Category2nd'] = $uRow[4];
> $defaultValues['LinkTitle'] = $uRow[5];
> $defaultValues['ArticleHeadline'] = $uRow[6];
> $defaultValues['ArticleMain'] = $uRow[7];
> $defaultValues['EanNumber'] = $uRow[8];
> $defaultValues['Position'] = $uRow[9];
>
> $form->setDefaults($defaultValues);
>
> // Elements will be displayed in the order they are declared
> file://$form->addHeader('Normal Elements');
> $form->addData('<table border="1" cellpadding="0"
> cellspacing="0">');
>
> // Classic form elements
> // $form->addElement('Art', 'Name', 'Label', Attributes);
> $form->addData('<tr>
> <td>BannerIMG</td>
> <td>');
> $form->addElement('text', 'BannerIMG', 'BannerIMG:',
> 'size="22"
> style="WIDTH:183 px"');
> $form->addData('</td><td>BannerIMG</td></tr>');
>
> $form->addData('<tr>
> <td>BgIMG</td>
> <td>');
> $form->addElement('text', 'BgIMG', 'BgIMG:',
> 'size="22" style="WIDTH:183
> px"');
> $form->addData('</td><td>BgIMG</td></tr>');
>
> // MainCategory SelectField with DbResult
> $form->addData('<tr>
> <td>CategoryMain</td>
> <td colspan="2">');
> $query = "SELECT * FROM CategoryMain";
> $result = $db->query($query);
> $form->addElement('select', 'CategoryMain', 'CategoryMain');
> $select = &$form->getElement('CategoryMain');
> $select->loadDbResult($result,'CategoryMain', 'FileName');
> $form->addData('</td></tr>');
>
> $form->addData('<tr>
> <td>Category2nd</td>
> <td colspan="2">');
> $query2 = "SELECT * FROM Category2nd";
> $result2 = $db->query($query2);
> $form->addElement('select', 'Category2nd', 'Cate
> gory2nd');
> $select = &$form->getElement('Category2nd');
> $select->loadDbResult($result2,'Category2nd', 'FileName');
> $form->addData('</td></tr>');
> }
> #$form->addElement('select', 'MainCategory', 'MainCategory',
> array(''=>'default','Haarpflege'=>'hair',
> 'Körperpflege'=>'body','Kosmetik'=>'cosmetic'));
> /*$form->addElement('select', 'MainCategory', 'MainCategory',
> "'".array(
> while($uRow=$uResult->fetchRow())
> { $uRow[1]=>$uRow[2],."'"}
> $result = $db->query($sql);
> }
>
> ));*/
> $form->addData('<tr>
> <td>LinkTitle</td>
> <td colspan="2">');
> $form->addElement('text', 'LinkTitle', 'LinkTitle:',
> 'size="22"
> style="WIDTH:183 px"');
> $form->addData('</td></tr>');
>
> $form->addData('<tr>
> <td>ArticleHeadline</td>
> <td colspan="2">');
> $form->addElement('text', 'ArticleHeadline',
> 'ArticleHeadline:', 'size="22"
> style="WIDTH:183 px"');
> $form->addData('</td></tr>');
>
> $form->addData('<tr>
> <td>ArticleMain</td>
> <td colspan="2">');
> $form->addElement('textarea', 'ArticleMain', 'ArticleMain:',
> 'cols=60
> rows=10 wrap=hard');
> $form->addData('</td></tr>');
>
> $form->addData('<tr>
> <td>EanNumber</td>
> <td colspan="2">');
> $form->addElement('text', 'EanNumber', 'EanNumber:',
> 'size="22"
> style="WIDTH:183 px"');
> #$form->addElement('text', 'Position', 'Position:',
> 'size="22"
> style="WIDTH:183 px"');
> // Creates a checkboxes group
> $checkbox[] = &HTML_QuickForm::createElement('checkbox', '1', null,
> 'Wird
> erst freigeben, sobald abgehakt');
> #$checkbox[] = &HTML_QuickForm::createElement('checkbox', '2', null,
> 'Wird
> erst freigeben, sobald freigschaltet');
> $form->addData('</td></tr>');
>
> $form->addData('<tr>
> <td>Publish</td>
> <td colspan="2">');
> $form->addElementGroup($checkbox, 'Publish:', 'Publish',
> '<br>');
> $form->addData('</td></tr>');
>
> $form->addData('<tr>
> <td> </td>
> <td>');
> $form->addElement('submit', null, 'Submit');
> $form->addData('</td><td>');
> $form->addElement('reset', null, 'Reset');
> $form->addData('</td></tr>');
>
> $select = &$form->getElement('MainCategory');
>
> // Adds some validation rules
> file://$form->addRule('ArticleMain', 'Test TextArea must be at least 5
> characters', 'minlength', '5');
> file://function addRule($element, $message="", $type="",
> $format="",
> $validation="server")
> $form->addRule('BannerIMG', 'Dies ist ein Pflichtfeld',
> 'required');
> $form->addRule('BgIMG', 'Dies ist ein Pflichtfeld',
> 'required');
> $form->addRule('MainCategory', 'Dies ist ein Pflichtfeld',
> 'required');
> $form->addRule('Category2nd', 'Dies ist ein Pflichtfeld',
> 'required');
> $form->addRule('LinkTitle', 'Dies ist ein Pflichtfeld',
> 'required');
> $form->addRule('ArticleHeadline', 'Dies ist ein Pflichtfeld',
> 'required');
> $form->addRule('ArticleMain', 'Dies ist ein Pflichtfeld',
> 'required');
> $form->addRule('EanNumber', 'Dies ist ein Pflichtfeld',
> 'required');
> $form->addRule('EanNumber', 'Bitte hier nur Zahlen eingeben',
> 'numbersonly');
> $form->addRule('Position', 'Dies ist ein Pflichtfeld',
> 'required');
> $form->addRule('Position', 'Bitte hier nur Zahlen eingeben',
> 'numbersonly');
> // Tries to validate the form
> if ($form->validate()) {
> // Form is validated, then processes the data
> $form->freeze();
>
> }
> $form->addData('</table>');
> $form->display();
>
> ?>
Please, help me to help you.
You don't really think I will go thru this code ?
Just a few hints though:
You shouldn't use "" quotes in your attributes. When you need to do this :
> $form->addElement('text', 'ArticleHeadline',
> 'ArticleHeadline:', 'size="22"
> style="WIDTH:183 px"');
just pass an array like this instead:
$attributes = array('size' => 22, 'style' => 'WIDTH:183 px');
$form->addElement('text', 'ArticleHeadline', 'ArticleHeadline:',
$attributes);
Next, I don't see why you use addData here. You could just create a table,
then do $myform = $form->toHTML() and put the table where you want in your
page by using what is contained in $myform.
If you want to use your own rules, you first need to register them using
registerRule(). Then look at the way parameters are defined in addRule to
make sure they are in the good order. 'numbersonly' doesn't exist by
default. You can use 'numeric' instead.
You'd better try to isolate your problem by writing smaller tests.
Good Luck with your hairdressing site :-)
Bertrand Mansion
Mamasam