0

i have a Zend Form and i would like to use jquery to do some ajax posting.

if ($this->getRequest()->isPost()) {
$data = $form->getValues();
$image_id = $this->usermedia->crop_image($userObj->user_id, $data);
}

the crop_image saves the data:

$new_image_id = $this->getDbTable()->createRow($new_row_data)->save();
return $new_image_id;

if the form is posted then run a function and give me back an $new_image_id.

all this happens in a modal window that loads a iframe with the form.

what i want is when i submit the form to grab that $new_image_id from inside the iframe, close the modal window and place it on my original page

any ideas on how this can be done?

thanks

edit:

Patrioticcow
  • 26,422
  • 75
  • 217
  • 337

1 Answers1

0

Just render that variable into a javascript variable:

var newImageId = "<?php echo $new_image_id ?>";

Then you can use:

http://api.jquery.com/load/

jQuery's wonderful .load() method to send that id to an external PHP page that then pulls it from the database and renders it to HTML. .load() will pull that all back in to your current page. You can then define a callback from .load() which gets rid of the modal.

Edit:

If your code is such that rendering the variable to a javascript variable is not practical, you can render it to the DOM itself, say as an element attribute... then get it using .content()

jQuery/JavaScript: accessing contents of an iframe

Bear in mind same origin policy:

http://en.wikipedia.org/wiki/Same_origin_policy

Community
  • 1
  • 1
arkigos
  • 362
  • 1
  • 8