I'm trying to make some ajax-functionality in my web application, but I cannot get all puzzle pieces to fit:
I want to add a link that, when clicked upon, will open a new input (text) field that can be filled by the user. In the back-end, I want to do some administration that the link is clicked.
I want to do according to the Zend Framework principles, with using the ajaxLink()
method. Can anyone have an example for me? I've read the official documentation (ZendX_JQuery) but it doesn't fully help me.
My front-end (view) code looks like this;
<?= $this->ajaxLink("Subscribe", $this->url(array('controller' => 'mycontroller', 'action' => 'action1', 'id' => $event['id'])),
array("beforeSend" => "hide",
"update" => "#pb_" . $event['id'],
'noscript' => false,
'method' => 'POST')); ?>
My back-end code looks like this.
public function action1Action()
{
if( !$this->loggedIn || ! $this->athlete) {
$this->_redirect('index');
}
if(! $this->_request->isXmlHttpRequest())
{
//The request was NOT made with JS XmlHttpRequest
die;
}
// Do some administration
// (removed to make this easier in this example)
$pb = new Zend_Form_Element_Text('PB');
$pb->setLabel('PB:')
->addValidator('StringLength', false, array(0,20))
->setRequired(false);
$renderText = $pb->render();
return $renderText;
}
I keep getting errors back that the given method wants to look-up a action1.phtml view script. I'm also not sure if what I try to do with the generation of the form input element works in this way.
I found some of the answer in this question, but it's not that elegant (requires an extra parameter in the link and you need another controller) which I don't like.