chozma
Member
Hi guys,
I would much appreciate some advice on how to go about the below... I think I have figured out the general approach but would like some advice on whether I have that approach right and maybe some help with the syntax if I have. So....
I have a custom button (labelled 'Add to mobs') on a list called 'Animals'. I have created the button using the javascript list plugin. When some rows are selected and that button is clicked I would like it to load up a form called 'Add to mobs'. The user needs to fill some details in on the form and when the form is saved I would like to call some bespoke php that saves the form data. The key thing is I need the form to make use of the ids that were selected on the 'Animals' list when saving.
I know how to write the php to save the forms, I can't figure out how to pass the variables into the form for use.
The approach I'm using is to use ajax to pass the selected ids from the list to the form. Using the firebug console I can see that ids is the array of values I want to pass/make use of in the form. Then I'm telling the form to load. I am trying to do this with the following JS...
When the form is submitted I'm using the form php plugin to do the necessary actions with the data on form submission. However, I'm struggling to retrieve the variables in the php. The code I am using is:
At the moment this just outputs NULL which suggests to me I'm not actually managing to pass the variables into the form properly.
I don't know if AJAX works in the way I am trying to use it.... Ie posting the variables for use when a function is called a bit later...
Hope this description makes sense... Any ideas on how to do this or if there is an alternative approach? Thanks as always... Hannah
I would much appreciate some advice on how to go about the below... I think I have figured out the general approach but would like some advice on whether I have that approach right and maybe some help with the syntax if I have. So....
I have a custom button (labelled 'Add to mobs') on a list called 'Animals'. I have created the button using the javascript list plugin. When some rows are selected and that button is clicked I would like it to load up a form called 'Add to mobs'. The user needs to fill some details in on the form and when the form is saved I would like to call some bespoke php that saves the form data. The key thing is I need the form to make use of the ids that were selected on the 'Animals' list when saving.
I know how to write the php to save the forms, I can't figure out how to pass the variables into the form for use.
The approach I'm using is to use ajax to pass the selected ids from the list to the form. Using the firebug console I can see that ids is the array of values I want to pass/make use of in the form. Then I'm telling the form to load. I am trying to do this with the following JS...
Code:
var url = "/index.php/mobs/form/24";
new Request({url:url,
method: 'post',
data: {ids:ids},
.done(function( data ) {
alert( "Data Loaded: " + data );
}).send();
window.open ('/index.php/mobs/form/24','_self',false);
When the form is submitted I'm using the form php plugin to do the necessary actions with the data on form submission. However, I'm struggling to retrieve the variables in the php. The code I am using is:
Code:
$ids = $_POST['ids'];
var_dump($ids);exit;
At the moment this just outputs NULL which suggests to me I'm not actually managing to pass the variables into the form properly.
I don't know if AJAX works in the way I am trying to use it.... Ie posting the variables for use when a function is called a bit later...
Hope this description makes sense... Any ideas on how to do this or if there is an alternative approach? Thanks as always... Hannah