Hello!
I've looked at the docs, at the API, and a little bit at the source,
as well as Googling around for this, but I can't seem to find any
answers, and I'm kinda stuck :)
I'm trying to use the Cake 1.2.0.6311 (beta) distribution, and I've
tried it using both FireFox 3 and IE 7.0.5730.13
I'm trying to use Cake's built-in AjaxHelper, to create form with a
'cascading select' - the user is presented with a drop-down list (a
select), and once they've made a section, then the observeField that
was watching that select uses
the built-in AJAX support to update an $ajax->div, in order to add the
second drop-down (as well as a second observeField, for that drop-
down)
The problem I'm running into is that when I try to update the div, it
doesn't actually print the script (as far as I can tell). When I use
FireBug, I can verify that the non-javascript output is present on
either side of the script in the div, but the actual output of $ajax-
>observeField is not there. (This is annotated in the code below with
"NOTE NOTE NOTE")
The odd thing is that when I write the first select into the form, and
the first observeField (i.e., when the page is first generated), that
all works fine - it's only when I try to put the observeField output
into the div that I'm updating that problems arise.
If anyone has any experience with this, and wouldn't mind helping me
out, I'd greatly appreciate it! :)
I'll include the code here, in case it's helpful:
(Yeah, it's awful stuff - I've been stuck on the 'getting it to work'
phase, and so haven't been able to go back & polish it up)
****************** View Code Snippet (student.ctp) **************
<td colspan="4"><fieldset><legend>Enroll In A Course</legend>
<?php
echo $ajax->form( array('action' =>
'/main/enrollInCourse'),
'post',
array('update' =>
'dynamic1', 'id'
=>'courseSelectionForm' ));
echo 'First, choose a term: ';
echo $this->renderElement('selectTerm',
array( 'termList' =>
$terms,
'formHelper' => $form) );
// This element I made - it generates something
like:
// <select name="data[SELECTTERM]"
id="SELECTTERM">
// <option value="-1"
selected="selected">Select A Term</option>
// <option value="2">2002 Winter</option>
// <option value="1">2001 Fall</option>
// </select>
echo $ajax->observeField('SELECTTERM', array(
'frequency'=>'1',
'url'=>'/main/updateCourse',
'update'=>array('dynamic1',
'dynamic2'),
) );
echo $ajax->div('dynamic1');
echo "<pre>data2: ";
print_r($data2);
echo '<br/>showC: ' . $showCourses;
echo "</pre>";
$WTF = $ajax->observeField('SELECTCOURSE',
array( 'frequency'=>'1',
'url'=>'/main/updateCourse',
'update'=>array('dynamic1', 'dynamic2'),
) );
if($showCourses)
{
echo 'Next, choose a course: ';
echo
$this->renderElement('selectCourse',
array( 'courseList' =>
$courses,
'formHelper' => $form) );
// This element I made - it generates
something similar to
selectTerm
// NOTE NOTE
NOTE::::::::::::::::::::::::::::::::::::::::::::::::::::::
// Here's where it gets weird:
$cln = new Sanitize();
echo $cln->html($WTF); // I can see
this output fine
echo "WTF????" . $WTF . "SFSDFSD";
// I can see WTF????, and I can see
SFSDFSD, but according to
FireBug,
// there's no <script> element between
them!
}
echo $ajax->divEnd('dynamic1');
echo $ajax->div('dynamic2');
echo 'Finally, click here to enroll! ' .
$goodToGo . 'fff<br/>';
if($goodToGo)
{
echo $form->end( 'Submit');
}
else
{
echo 'ending form...';
echo $form->end( );
}
echo $ajax->divEnd('dynamic2');
?>
<hr/>
</fieldset></td>
****************** Controller Code Snippet (main_controller.php)
**************
function updateCourse()
{
// $this->layout='defaultajax';
$terms = $this->Term->find('all', array(
//'conditions' => array('name' => 'Thomas
Anderson'),
//'fields' => array('name', 'email'),
'order' => 'year DESC',
'recursive' => 1,
//'group' => 'type'
)) ;
// get rid of any terms that have no courses...
foreach(array_keys($terms) as $key)
{
if(empty($terms[$key]['Course']))
{
unset($terms[$key]);
}
}
$this->set('terms', $terms );
$this->set('data2', $this->params['data']);
$this->set('showCourses', false);
$this->set('goodToGo', false ) ;
//TODO:SECURITY: Do we need to check the value coming back from the
client?
$courses = $this->Term->find(array('id' => $this->params['data']
['SELECTTERM']),
null, null, 1) ;
if(!isset($this->params['data']['SELECTTERM']) || $courses == null)
{
$this->render('student', 'ajax');
return;
}
$this->set('courses', $courses['Course']);
$this->set('showCourses', true);
if( isset($this->params['data']['SELECTCOURSE']) &&
$this->Course->find(array('id' => $this->params['data']
['SELECTCOURSE']),
null, null, 1) )
{
$this->set('goodToGo', true ) ;
}
// use ajax layout
$this->render('student', 'ajax');
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---