Add multiple element with jQuery using symfony 1.4
I am going to be as clear as I can be, but don't hesitate to tell me if there is something you don't understand.
What I'm trying to do shouldn't be complicated, I've read tons of stuff about it, but I'm looking for some tips to get me started...
Okay, So I have two tables, "Utilisateur" and "Contact"
What I'd like to do, is, when adding a new contact, I'd like to have a list of all the Utilisateurs on the left, and with a doublelist widget, when adding one or many utilisateusr to the right column, it adds the utilisateur(s) to my contact list.
In other words, when an utilisateur is selected and transfered in the right column of my double list, it creates a new contact for each utilisateur selected.
Am i clear ?
I have written already the javascript code for my double list, but i'd like to have some help on the action handling.... How, in my action can I tell Symfony to add a new contact for each utilisateur selected ?
I may add that a contact has an "utilisateur_id" field, so I just need to match the "utilisateur_id" of the contact with the id of the utilisateur object each time an utilisateur is selected and transfered....
Ohlala, am I clear ? :)
Anyways, thank you for reading this post til the end, and hep much be, as usual, much appreciated !
EDIT
So i've created a new button "mybutton"
add this js code:
$('#mybutton').click(function(){
alert( "Bouton");
var value = $("#contact_utilisateur_id").val();
$.post("http://localhost:8080/backend_dev.php/en/contact/add",
{myParam : value},
function(data)
{
alert( "Dat开发者_高级运维a saved: " + value);
}
);
});
then, I created an action "add":
public function executeAdd(sfWebRequest $request){
if($request->isXmlHttpRequest()){
$this->redirect('@contact');
}
But it seems that executeAdd is never read....
first, you can validate your routing by try http://localhost:8080/backend_dev.php/en/contact/add" in your browser (after remove the isXmlHttpRequest() condition). If it's ok, try to return something in your action instead of using a rdirec:
public function executeAdd(sfWebRequest $request){
return 'toto';
}
and in your callback function, i think you've made a mistake with the return value:
function(data)
{
alert( "Data saved: " + data);
}
精彩评论