Parse Form from xml using input objects, maintaining data integrity

SnorneWeini

New Member
I'm creating a system form building a form processing an xml.Form Layout is almost the same, so depending on url I will load a different xml that will generate different form.I use 3 diffrent classes:
  • Form manages all form infos (action, enctype, upload dir for files), values (if in update), language and input creation
  • Input manages everything concerning Input (name, id, ...)
  • Language manages labels
When I create Form obj I create instance of language class (input labels are Language instance key), get values from db and parse XML to create input as Input class instance (passing the input xml object in the constructor).An excerpt for Form class in creating input\[code\] if(count($obj->input)): foreach($obj->input as $input): $Input = new Input($input); $val = !empty($this->arValues['normal'][(string)$Input->getname()]) ? $this->arValues['normal'][(string)$Input->getname()] : ''; $Input->setvalue($val); $label = !empty($input['label']) && !empty($this->Language->getTranslation((string)$input['label'])) ? $this->Language->getTranslation((string)$input['label']) : ''; $Input->setlabel($label); $Input->setlgTag($lgTag); $this->arInputs[(string)$Input->getname()] = $Input; endforeach; endif;\[/code\]Xml input can be:\[code\] <input type="text" label="label_name" name="name" ...></input>\[/code\]but also:\[code\] <input type="image" label="image_name" name="img" usecaption="true" ...></input>\[/code\]In the first case no problem, I get my input;in the second case the situation is trickier: - I define the file upload dir in Form, but for input value I'd need it also in input instance (this is pretty easy, but as I define input type in Input class, I would populate a value even when this is not needed)- basing on attribute 'usecaption' I would like to create an input type text for associate caption to image: in fact I'm going to have 2 html inputs (type file & type text) in one xml input (type image) and I lose data as values and language are dfined in Form.I thought of using Form instance inside input, but as Input instances are defined in Form class, there can be recursive problems, and this is not DRY.My question is:HOW CAN I PASS AND REUSE SPECIFIC DATA IN INPUT COMING FORM FORM INSTANCE?Any answer is appreciated...For sure I'm missing something but it's days I'm looping...
 
Back
Top