Subversion Repositories owmoduleforms

[/] [trunk/] [classes/] [formelements/] [owformsubmit.php] - Blame information for rev 32

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 fmagnan
<?php
2 3 fmagnan
 
3
class owFormSubmit extends owFormInput
4
{
5 32 fmagnan
    var $type='submit';
6
 
7 8 fmagnan
    public function __construct($options=array())
8
    {
9
        $this->setDefaultOption($options, 'name', 'submit');
10 16 fmagnan
        $this->setDefaultOption($options, 'class', 'button');
11 32 fmagnan
        $this->setDefaultOption($options, 'template_path', 'owmoduleforms/submit_confirm.tpl');
12 21 fmagnan
        $this->setDefaultOption($options, 'variables', array('confirm_message' => 'Form successfully submitted!'));
13 8 fmagnan
        parent::__construct($options);
14
    }
15 6 fmagnan
 
16 26 fmagnan
    public function getSubmittedButton()
17 8 fmagnan
    {
18 16 fmagnan
        return array_key_exists($this->getName(), $_REQUEST) ? $this : false;
19 8 fmagnan
    }
20
 
21 32 fmagnan
    public function setVariablesToTemplate($form, $tpl)
22 8 fmagnan
    {
23 20 fmagnan
        $submitted_data = array();
24
        foreach($form->getSubmittedData() as $element)
25
        {
26
            $name = $element->getName();
27
            $submitted_data[$name] = array(
28
                'label' => $element->getLabel() ? $element->getLabel() : $name,
29
                'type' => get_class($element),
30
                'value' => $element->getValue(),
31
            );
32 32 fmagnan
 
33 20 fmagnan
        }
34
        $tpl->setVariable('submitted_data', $submitted_data);
35 8 fmagnan
    }
36
 
37 32 fmagnan
    public function renderSubmit($form)
38
    {
39
        $tpl = $form->getFormTemplate();
40
        $variables = $this->getOption('variables');
41
        foreach ($variables as $variable_name => $variable_value)
42
        {
43
            $tpl->setVariable($variable_name, $variable_value);
44
        }
45
        $this->setVariablesToTemplate($form, $tpl);
46
        return $tpl->fetch('design:'.$this->getOption('template_path'));
47
    }
48
 
49 26 fmagnan
    public function submit($form)
50
    {
51
        $form->validate($form->getHttpFormMethod());
52
        if ($form->isValid())
53
        {
54
            $form->processSubmit();
55
            $form->doProcess();
56
            return $this->renderSubmit($form);
57
        }
58
        else
59
        {
60
            return $form->renderForm();
61
        }
62
    }
63
 
64 3 fmagnan
}
65
 
66
?>