What I’m trying to do is take a form that is asking users to specify details of a file they want to save to a database and use an AJAX link to swap out a file upload field for a text box to enter a direct link url instead.
I’m using a CRUD interface for the form and have this in my _form.php
<div class="row">
<div id="ajaxDLLink">
<?php echo $form->labelEx($model,'downloadFile'); ?>
<?php echo $form->fileField($model, 'downloadFile'); ?>
<?php echo $form->error($model,'downloadFile'); ?>
<?php echo CHtml::ajaxLink('Enter a URL instead?', array('ajaxLink'), array('update'=>'#ajaxDLLink')); ?>
</div>
</div>
My controller has this code
public function actionAjaxLink()
{
$this->renderPartial('_directLink', array(), false, true);
}
And _directLink.php has this code
<?php
echo $form->labelEx($model,'downloadLink');
echo $form->textField($model,'downloadLink',array('size'=>60));
echo $form->error($model,'downloadLink');
?>
This is generating errors in _directLink.php about $form not being defined. $form is defined in the top of _form.php as
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'files-form',
'enableAjaxValidation'=>false,
'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
Am I going about this the wrong way? I’d like some advice if so about what I should do instead.
Many thanks