Thursday, June 27, 2013

Re: Generating multiple 'requests' based on form selections

Not sure if this is what you want to do but I have a view with 2 form elements on it. I did get hung up because I usually use $this->Form->end

<?php
 echo $this->Form->create('User', array( 'action'=>'/add_staff'));?>
    <fieldset>
         <legend><?php __('Admin Add Staff Member'); ?></legend>
    <?php
        echo $this->Form->input('id', array('label' => 'Select an existing Student','options' => array(  $users)));
        echo "By submitting this form you are giving the selected student Administrative access";
        echo $this->Form->hidden('group_id', array('value' => '1'));
        echo "<br>";
        ?>
    </fieldset>
<?php
        echo $this->Form->submit('Add a Staff Member from an existing Student', array('name' => 'submit'));
        echo "<br>";
        echo "-- OR -- Create a new profile for this Staff Member. ";
        echo "<br>";
?>   
    <?php echo $this->Form->create('User2', array( 'action'=>'/add_staff'));?>

    <fieldset>
         <legend><?php __('Add a New Staff Member '); ?></legend>
    <?php

        echo $this->Form->input('first_name');
        echo $this->Form->input('last_name');
        echo $this->Form->input('username');
        echo $this->Form->input('password');
        echo $this->Form->input('email');
        echo $this->Form->input('birthdate', array('label' => 'Date of Birth', 'empty' => true, 'timeFormat' => '', 'minYear' => ( date('Y') - 70 ), 'maxYear' => ( date('Y') - 3)));
        echo $this->Form->input('address');
        echo $this->Form->input('city');
        echo $this->Form->input('state');
        echo $this->Form->input('zip_code');
        echo $this->Form->input('phone');
        echo $this->Form->input('uniform_size', array( 'type' => 'select', 'options' => array( '0000' => 'Size 0000', '000' => 'Size 000', '00' => 'size 00', '0' => 'Size 0', '1' => 'Size 1', '2' => 'size 2' , '3' => 'Size 3', '4' => 'size 4', '5' => 'Size 5', '6' => 'Size 6')));
        echo $this->Form->input('is_head', array('type'=>'checkbox'));
        echo $this->Form->input('household_id');
        echo $this->Form->hidden('group_id', array('value' => '1'));
        echo $this->Form->input('school_id', array( 'value' => $currentSchool , 'type' => 'hidden') );

        ?>
    </fieldset>
<?php
//echo $this->Form->end(__('Submit', true));
echo $this->Form->submit('Add a Staff Member', array('name' => 'submit'));

controller:

if (isset($this->params['form']['submit'])){
            //check for first form
            if ($this->params['form']['submit'] == "Add a Staff Member from an existing Student"){
                if ($this->User->save($this->data)) {
                $this->Session->setFlash(__('The user has been saved', true));
                $this->redirect(array('action'=>'view_staff'));
                } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
                }
            //check for second form
            }elseif ($this->params['form']['submit'] == 'Add a Staff Member'){
                //give value of second form (User2) to User so it can be automatically saved
                $this->data['User'] = $this->data['User2'];
                //save the data
                if ($this->User->save($this->data)) {
                $this->Session->setFlash(__('The user has been saved', true));
                $this->redirect(array('action'=>'view_staff'));
                } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
                }
            }
        }


On Thu, Jun 27, 2013 at 1:19 PM, David Carr <dcarr@scienceprousa.com> wrote:

I have a CakePHP form that lets a user select a variety of parameters. What I want to do is let them select multiple choices on a few different parameters, and then turn these into multiple submissions. My CakePHP model is called 'Requests' so ideally what I want to do is have the user be able to create multiple requests through one form submission - essentially a 'cross-product' of the options they choose.

I don't want/need anyone to write code for me but if someone could help me think this problem through and give me a few pointers in the right direction, I'd greatly appreciate it!

Disclaimer: I'm using CakePHP 1.1, and am unable to upgrade - this site runs on the same machine as many others inside my company and there was lots of hackery done and lots of shared files.  Disclaimer #2, I am an intern and brand new to CakePHP ;-)

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: