I have something similar that may be useful to you,
its not the best way to do it but it gets the job done.

First, you need prototype and scriptaculous on your webroot/js/ folder

on your Controller:

class EventsController extends AppController {
        var $name='Events';
        var $uses=array('Event', 'EventDetails');

        function add() {
                $totalEventDetails = 1; // unless i have already posted some
                if (!empty($this->data)) {
                        if ($this->Event->validates()) {
                                // data for Event model has been validated
                                $error_in_details = false;
                                foreach ($this->data['EventDetails'] as 
$key=>$detail) {
(!$this->Event->EventDetail->validates()) {
                                                $error_in_details = true;
                                                $error_in_detail[$key] = true;
                                        } else {
                                                $error_in_detail[$key] = false;
                                // if there are no errors, save Event and 
                                if (!$error_in_details) {
                                        // set user id
$this->Event->save($this->data['Event'], false);
                                        foreach ($this->data['EventDetails'] as 
$key=>$detail) {
$detail['EventDetail']['event_id'] = $this->Event->id;
$this->Event->EventDetail->save($detail, false);
                                        $this->Session->setFlash(__('The Event 
and EventDetails have been
saved', true));
                                } else {
EventDetail could not be saved.
Please, try again.', true));
                        } else {
                                $this->Session->setFlash(__('The Event could 
not be saved. Please,
try again.', true));
                        $totalEventDetails = count($this->data['EventDetails']);

        function ajaxAddDetail($total_details) {
                $details = $this->data['EventDetails'];

on your View:

<?php echo $javascript->link('prototype'); ?>
<?php echo $javascript->link('scriptaculous'); ?>
                <legend><?php __('Add Event');?></legend>
                <!-- your form fields here -->
<a href="/events/ajaxAddDetail/<?php echo $totalEventDetails; ?>"
id="ajax_add_detail_updater" onclick=" event.returnValue = false;
return false;">click to add details field</a>

                <?php echo $ajax->div('ajax_detail_updater', array
('class'=>'last')); ?>
                <script type="text/javascript">
        Event.observe(  'ajax_add_detail_updater',
                                                function(event) {
        ,'/events/ajaxAddDetail/<?php echo $totalEventDetails; ?
                parameters: Form.serialize($('EventAddForm')),
                requestHeaders:['X-Update', 'ajax_detail_updater']})
        <?php echo $form->text('EventDetails.'.
$details[$c]['description'])); ?>
        <?php echo $ajax->divEnd('ajax_detail_updater'); ?>
<?php echo $form->end(array('label'=>__
('Submit',true),'class'=>'submit button'));?>

This code may contain errors, I copied it and modified it from a
working example but I didn't test it myself, I hope it helps

On Feb 6, 1:48 am, exo_duz <robin.jul...@gmail.com> wrote:
> Hi all,
> Just some quick questions and hoping to get pointed in the right
> direction. I have an events table which has many event_details and
> pictures.
> events --hasMany--> event_details
> events --hasMany--> pictures
> A couple of questions firstly with the event_details. Is there a way
> to create the the events and the event_details in 1 form. For the
> event_details section of the form I would like to ultimately be able
> to create fields on the fly. I have searched Google and most of the
> tutorials state that you'd have to create the fields in JS which is
> not efficient and very tedious for me as the event_details section has
> about 20 fields. What is the best way to achieve this? Does anyone
> have any exprience with this? I'm not too sure about this as JS is not
> my strong suite.
> Secondly, is there a multiple picture uploader with or without a
> resizer that is recommended to be used with Cake? This would really
> help a lot.
> Thanks everyone for all your replies.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to