Re: Re: setting Flexy form error messages

From: Date: Mon, 01 Dec 2003 16:06:20 +0000
Subject: Re: Re: setting Flexy form error messages
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-9244@lists.php.net to get a copy of this message
Hi Alan thanks for the tip, i tried the following from your example code and it worked fine: $this->elements['input']->setValue('Hello'); HTML_Template_Flexy_Factory::setRequired($this->elements, array('input' => 'There was an error with input')); but the other utility function, setRequired() that seems to have the same format, didn't work. i'm looking for a way to achieve similar functionality to quickform, but without that class which i found on the slow side. on a different tack, what do you think of a global ini setting to disable parsing of forms altogether, allowing the developer to handle forms independently without inserting flexy:ignore each time. currently with the 'elements' approach i have to use quite a lot of code to pre-check boxes: require_once 'HTML/Template/Flexy/Element.php'; $input->flexyElements['section[is_enabled]'] = ($input->section->is_enabled) ?
    new HTML_Template_Flexy_Element('input', array('checked' => true)) :
    new HTML_Template_Flexy_Element('input', false);
this may not the best way to go, previously being able to insert an {isChecked} variable inside the input tags was quite clean to code, but Flexy doesn't accept variables that are not in quotes like this: <input name="name" type="checkbox" {isChecked}> cheers demian Alan Knowles wrote:
Those docs are horrifically out of date... The introduction has been updated a bit.. http://pear.php.net/manual/en/package.html.html-template-flexy.intro.php // template has this on it .. <input name="input" size="12"> $this->elements['input'] = new HTML_Template_Flexy_Element; // assign a value to it $this->elements['input']->setValue('Hello'); // to set errors: HTML_Template_Flexy_Factory::setErrors(array(
        'input' => 'There was an error with input'
    ));
the factory class is really a set of static methods to manipulate multiple elements. Getting these docs fixed is on my major TODO list.. Regards Alan Demian Turner wrote:
hi alan Can you give an example of how you've used Flexy's error message handling. From the flexy docs the example shows how this template html : <form name="theform"> <input name="theinput"> </form> gets transformed into: <FORM NAME="theform"> <INPUT NAME="theinput" VALUE="<?php echo htmlspecialchars($t->theform->theinput); ?>"><?php if (isset($this->errors['theform.theinput'])) { echo
    htmlspecialchars($this->errors['theform.theinput']); } ?>
</FORM> and in your examples file in CVS: <form name="test">
    Input<input name=test123
        ruleA="Test Text is a required field|required"
        ruleB="Test TextArea must be at least 5 characters|minlength|5">
gets transformed into: <?php echo $this->elements['test']->toHtmlnoClose();?>
    Input<?php echo $this->elements['test123']->toHtml();?>
Do you have an example showing the full sequence, from PHP object to template html, say with a typical User DataObject ? thanks demian


« previous php.pear.general (#9244) next »