Thanx Andrew,
But saving isn't the issue, that's not the problem.
The controller saves all the fields.
My problem is, that the attributes of the datafields are only set for
the model given in the form.
Example:
Model Customer with
customer_name (varchar(40))
Model Address with
street (varchar(80))
<?php
print $form->create('Customer');
print $form->input('Customer.customer_name');
print $form->input('Address.street');
print $form->submit();
print $form->end();
?>
prints out something like
<form ...>
<input name="data[Customer][customer_name]" ... maxlength="40"/>
<input name="data[Address][street]" .../> <!-- No real
automagic here (no maxlength for example) -->
....
</form>
if i change the main model for the form to Address
($form->create('Address');)
i'll get something like this:
<form ...>
<input name="data[Customer][customer_name]" ... /> <!-- No real
automagic here (no maxlength for example) -->
<input name="data[Address][street]" ... maxlength="80" />
....
</form>
so it seems that the whole automagic only applies to the model choosen
in the $form->create() method.
So anybody with an idea to accomplish the task with full automagic on
all the fields if there are different models per form (without using
the $options array)?
It's only a view issue (not a controller or model problem) but it
would be nice to accomplish it without the $options array... (because
that's what all the automagic is for...isn't it)
Any Idea?
Cheers,
Joachim
On 28 Apr., 17:36, Andrew Assarattanakul <[EMAIL PROTECTED]> wrote:
> Forms can only submit to one location, but you can put all of the
> fields together in form.
>
> Example View:
> <form action="<?php echo $this->here; ?>" method="post" class="form">
> <?php foreach($form_fields as $section_name => $field_section): ?>
> <?php echo $form->inputs($field_section); ?>
>
> <?php endforeach; ?>
>
> <div class="controls">
> <?php echo $form->submit('Save');?>
> </div>
> </form>
>
> The value of $form_fields is:
> Array
> (
> [Product] => Array
> (
> [legend] => Product
> [Product.id] => Array()
> )
>
> [Binocular] => Array
> (
> [legend] => Binocular
> [Binocular.id] => Array()
> )
> )
>
> Then in the controller you can call the saves for the different models
> assuming they are associated together. I'm sure there's a cleaner way
> to save them all in one call but I didn't spend the time to do it.
>
> On Apr 28, 10:10 am, "J. Eckert" <[EMAIL PROTECTED]> wrote:
>
> > Good evening ladies and gentlemen,
>
> > I have an issue about different models in one view (to be precise: one
> > form).
>
> > In the current case i have three Models:
> > Customer, BillingAddress, DeliveryAddress
>
> > The system i am working on is a small shop system.
>
> > At the end of the checkout i gather the needed information of the
> > Customer. The data of the customer is splitted over three Models (see
> > above) saving in two database tables (DeliveryAddress and
> > BillingAddress both use the same table).
>
> > Now i want all the Automagic of cake, especially the definition of the
> > textfields (like maxlength if there is a varchar etc.)
>
> > I have the following form:
>
> > <?php
> > print $form->create('Customer', array(
> > 'url' => array(
> > 'language' => $LANG,
> > 'controller' => 'orders',
> > 'action' => 'index'
> > )
> > ));
>
> > print $form->input('Customer.firstname_en');
> > print $form->input('Customer.lastname_en');
> > print $form->input('Customer.firstname_ja');
> > print $form->input('Customer.lastname_ja');
> > ....
>
> > print '<h2>'.__('billingAdress', true).'</h2>';
>
> > print $form->input('BillingAddress.address');
> > print $form->input('BillingAddress.zip');
> > ....
> > print '<h2>'.__('deliveryAdress', true).'</h2>';
>
> > print $form->input('DeliveryAddress.address');
> > print $form->input('DeliveryAddress.zip');
> > .....
> > print $form->submit();
> > print $form->end();
>
> > This works fine in the controller (validation etc. is no prob), but
> > only the Customer inputs are formatted correctly (especially the
> > maxlength attribute). This is because of the connection to the
> > Customer model (invoked by the $form->create method).
>
> > I tested it using 3 different forms on the same page and there it
> > works, but it doesn't in only ONE form.
>
> > Is there any way to change the model the form is connected to so that
> > the correct attributes of the input fields will apply?
>
> > For sure i can use the options array to set the attributes, but that
> > wouldn't be the nice way.
>
> > I can't see a way to accomplish that at the moment, can somebody open
> > my eyes on that or verify that there is no way (except the options
> > array) to set the tag attributes correctly?
>
> > Thanks in advance,
> > Joachim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---