Re: Uploaded Form Helper: FormationHelper

2006-06-12 Thread RosSoft

Looks promising,

I think that you can avoid $data parameter, it must be accessible in
the helper through $this-params['data']
(because HtmlHelper needs it)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Uploaded Form Helper: FormationHelper

2006-06-12 Thread RosSoft

mmm..but I think that  $this-params['data']=$data; is standard, see
first blog tutorial of wiki,
edit() action:

http://wiki.cakephp.org/tutorials:blog_tutorial_-_1?s=params+data

function edit($id=null)
{
if (empty($this-params['data']))
{
$this-Post-id = $id;
$this-params['data'] = $this-Post-read();
$this-render();
}
else
{
if ( $this-Post-save($this-params['data']['Post']))
{
$this-flash('Your post has been updated.','/posts');
}
}
}

In newer versions of cake, $this-data at controller is used instead, I
think that $this-data doesn't work in this case


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Uploaded Form Helper: FormationHelper

2006-06-12 Thread RosSoft

Ok now I'm documented.

If you use $this-params['data']=$data at your controller, then in the
helper is accessible through $this-params['data']

If you use $this-data at  your controller, then in the helper
$this-data

The correct way is to check where is the data. From HtmlHelper:

function tagValue($fieldName) {
$this-setFormTag($fieldName);
if (isset($this-params['data'][$this-model][$this-field])) {
return 
h($this-params['data'][$this-model][$this-field]);
} elseif(isset($this-data[$this-model][$this-field])) {
return h($this-data[$this-model][$this-field]);
}
return false;
}

You can use HtmlHelper in your own helper, and doing
$value=$this-Html-tagValue($fieldName) you will get the correct value


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Uploaded Form Helper: FormationHelper

2006-06-12 Thread RosSoft

You don't need to pass $data to the helpers: see the blog tutorial edit
action:

function edit($id = null)
{
if (empty($this-data))
{
$this-Post-id = $id;
$this-data = $this-Post-read();
}
else
{
if ($this-Post-save($this-data['Post']))
{
$this-flash('Your post has been updated.','/posts');
}
}
}

You always have $this-data at controller, then in your helper
(including the html helper) you can do
$value=$this-Html-tagValue($fieldname)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Uploaded Form Helper: FormationHelper

2006-06-12 Thread RosSoft

be careful, you're only using $this-data at helper, but it only works
if you put $this-data in controller. There's two ways at controller to
set the data,

$this-data or $this-params['data']. You must check these two at your
helper for ensure compatibility to all the users (if this is what you
want).

I repeat, use $value=$this-Html-tagValue($fieldName)   for maximum
compatibility


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: Uploaded Form Helper: FormationHelper

2006-06-12 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of RosSoft
 I repeat, use $value=$this-Html-tagValue($fieldName)   for maximum
 compatibility

Thanks for the pointer.

I actually ended up copying the HtmlHelper code into FormationHelper and
modifying it, because tagValue was calling h() (AKA htmlspecialchars() ) on
the value, which escapes HTML entities. Since I am using my database to store
HTML text, that's not what I wanted.

But the latest version of my posted code supports both $this-params['data']
and $this-data.

Regards,
Ryan

---
Ryan Ginstrom
[EMAIL PROTECTED] / [EMAIL PROTECTED] 
http://ginstrom.com 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Uploaded Form Helper: FormationHelper

2006-06-12 Thread brandags

I've also been working on a similar form helper. I just uploaded it at:
http://cakeforge.org/snippet/detail.php?type=snippetid=75

It extends Cake's Form helper and also takes the validation from the
model (using the advanced validation method - multiple rules per field)
so you don't have to retype the validation messages or which fields are
required, in your view.

It's still a work in progress and requires a few other components (the
advanced validator, and error helper), but maybe we can learn from each
other and get a really good form helper out there.

I'm all for as little typing as possible!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



RE: Uploaded Form Helper: FormationHelper

2006-06-12 Thread Ryan Ginstrom

 [mailto:[EMAIL PROTECTED] On Behalf Of brandags
 Wait - but don't I still need to send the validation rules, 
 etc. to the
 view? Can you change what parameters are sent to the 
 startup() function?

Well, here is your init function:

function init($validations=null, $data=null)
{
   $formData = array('validations' = $validations, 'data'=$data);
   $this-controller-set('formData', $formData);
}

And you are calling it like this:

function beforeFilter()
{
   $this-Myform-controller = $this;  
   $this-Myform-init($this-User-validate, $this-data);
}

So you should be able to do this:
// seemed to work with preliminary testing...
function startup( $controller )
{
   $validations = array() ;
   foreach( $controller-modelNames as $model )
   {
  $validations += $controller-$model-validate ;
   }

   $this-controller = $controller ;
   $this-controller-set( 'formData', array( 
'validations' = $validations,
'data' = $this-controller-data ) ) ;
}

--
Regards,
Ryan Ginstrom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Uploaded Form Helper: FormationHelper

2006-06-12 Thread brandags

Wow, that is awesome. Thank you.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---