2010/12/20 Andrés Manikis <[email protected]>:
>
> I do need different fields for passport and National document. For
> example, the passport has an expiration date whereas the national
> document has not. So I think I should extend the Credential model.
> How could I do that? I know how to do it at the PHP side but I don't
> know how I should create the tables for that to work.

Extending might not be necessary. See below.

> Let's say I require the following:
> For passport: An alphanumeric code and an expiration date.
> For national document: A numeric code, no letters.
> I would like to be able to change the available view fields at
> runtime. For example, if I check the checkbox, the passport fields
> would appear and the national document fields dissapear.
> I could do it with JQuery or maybe with multipage forms, but the
> latter is another problem, isn't it?

You could do it with radio buttons. They needn't be created with
FormHelper (in fact, it'd be simpler to do it manually). Add a
listener with JQuery to hide/show the appropriate fields for
Passport/NationalDocument depending on the radio button selected.
Then, when the form submits, remove the hidden field altogether. You
could then create validation rules in the Person model to ensure that
only one was included in the submitted data before saving. You can
access eg. $this->data['Passport'] from within your custom validation
method. Then you could have rules in both Passport and
NationalDocument to handle validation for their respective values.

Actually, because you may have more than one field required for
Passport, instead of hiding/showing form elements, you could put them
in their model-specific fieldsets. Give both of them IDs and hide/show
the fieldsets. Again, before the form submits, remove the entire
hidden fieldset from the DOM.

<fieldset id="passport_info">
<?php
echo $this->Form['Passport']['code'];
echo $this->Form['Passport']['expiration'];
?>
</fieldset>



> Apart from that, when you say, "create the association array" what do
> you mean?

Sorry, that wasn't very clear. I meant that you could update
$this->data with whatever values you needed, depending on which was
chosen. But that shouldn't be necessary if you go the route I
suggested above.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

Reply via email to