views:

351

answers:

1

Hy,

I'm using jq_link_to_remote function to load in a div a form to do answers to a comment (like in facebook). My problem is that i call this form like that 'social/respond/id/14' where id content the parent opinion. I create a funcion that setValue to a hidden field in my form.

Then, why if i try to call directly 'social/respond/id/14' it assign correctly value and when i do it with jq_link call not? I do a 'echo' of value passed as input in function than set value of field and it works fine.

Thanks.

Form code..

public function setDefaultEntityId($id_response=0)
  {
   if($id_response!=0){
     $this->setDefault('sf_opinion_id',$id_response);   
   }
   $this->configure();
  } 

template opinions

<?php echo jq_link_to_remote('opinar', 
                 array(
                        'update' => 'respuesta_hidden_'.$opinion->getId(), 
                         'url'  => 'social/responder?id_response='.$opinion->getId()),array('rel' => 'nofollow','class' =>'mini')

); ?>

action responder

$this->form = new OpinionResForm();

$this->form->setDefaultEntityId($request->getParameter('id_response'));

// formulario opiniones
if($request->isMethod(sfRequest::POST))
{
    $this->form->bind($request->getParameter($this->form->getName()));
    if ($this->form->isValid()) {
    $opinion = $this->form->save();  
    }
}

And finally, an example of generated code...

<a onclick="jQuery.ajax({type:'POST',dataType:'html',success:function(data, textStatus){jQuery('#respuesta_hidden_1').html(data);},url:'/sfproject/zampalo/web/frontend_dev.php/social/responder/id_response/1'}); return false;" href="#" class="mini" rel="nofollow">opinar</a>

I hope that helps... :)

A: 

Hmm, it looks clean - I'm not sure what the problem is. However, I'm not sure why you do this in the form:

if($id!=0){
  $this->setDefault('id_elemento',$id);
}
if($id_response!=0){
  $this->setDefault('id_elemento',$id_response); 
}

you are setting the default for id_elemento twice - if $id and $id_response are not 0, then id_elemento gets set to $id first, then $id_response... which doesn't sound right.

Raise
I'll try it later but it seems that is the problem... :(Thank you so much Raise!
nebur85
I edited information. Still not working :(If i run... social/responder/id_response/1 directly it works, via jquery not :(
nebur85
Raise... any idea? How can I test it or know what are failing?
nebur85
At this point, no. My only recommendation is to install the Tamper Data plugin for Firefox: https://addons.mozilla.org/firefox/addon/966 and use it to inspect your AJAX transactions by monitoring the request/responses via the Tamper Data window. You should be able to see what variables are not being set.
Raise