You are here

function phantomjs_capture_test_submit in PhantomJS Capture 7

Ajax callback for the test PhantomJS form on the administration page.

_state

Parameters

$form:

Return value

array

1 string reference to 'phantomjs_capture_test_submit'
phantomjs_capture_admin_form in ./phantomjs_capture.module
The administration form.

File

./phantomjs_capture.module, line 123
Defines the administration interface and utility functions to use PhantomJS and test screen shot capture functions.

Code

function phantomjs_capture_test_submit($form, $form_state) {

  // Build urls and destination.
  $url = $form_state['values']['phantomjs_capture_test']['url'];
  $file = 'test' . $form_state['values']['phantomjs_capture_test']['format'];
  $dest = file_default_scheme() . '://' . variable_get('phantomjs_capture_dest', 'phantomjs');

  // Get the screen shot and create success/error message.
  $output = '<div class="messages status"><ul><li>' . t('File has been generated. You can get it !url', array(
    '!url' => l(t('here'), file_create_url($dest . '/' . $file)),
  )) . '.</ul></li></div>';
  if (!phantomjs_capture_screen($url, $dest, $file)) {
    $output = '<div class="messages error"><ul><li>' . t('The address entered could not be retrieved.') . '</ul></li></div>';
  }

  // Return.
  return array(
    'phantomjs_capture_test' => array(
      'result' => array(
        '#prefix' => '<div id="phantomjs-capture-test-result">',
        '#suffix' => '</div>',
        '#markup' => $output,
      ),
    ),
  );
}