-1

I've got phantomjs and casperjs working on a webserver. I've got a webpage up with a form on it and two fields in the form (name and email address).

I need to input both 'name' and 'email' as variables into my casper script. From reading

Pass parameter from php to casperjs/phantomjs

and

http://phantomjs.org/api/system/property/platform.html

I understand you need to put var system and var args but it all seems like double dutch to me.

Php code

$name = $_POST['user_input'];
$email = $_POST['user_input'];
putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
exec('/usr/local/bin/casperjs hello.js $name $email 2>&1',$output);

print_r($output);

casperjs code

var system = require('system');
var args = system.args;
var name = args
var email = args

var casper = require('casper').create({
  verbose: true,
});
casper.start('website url');



casper.then(function () {
    casper.wait(5000); 
        this.echo("wait for 5 seconds.");

});
casper.then(function () {

    this.sendKeys('#firstname', name);
    this.sendKeys('#thereemail', email);
    this.click('.button');

From the looks of it I need to get both into one argument and then split them but how would I go about doing that?

Edit: The method posted would not work

Community
  • 1
  • 1
  • 1
    Possible duplicate of [How to pass variables and data from PHP to JavaScript?](http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript) – Pedro Lobito May 02 '16 at 15:52
  • Possible duplicate of [How to pass a variable to a CasperJS script through the command line?](http://stackoverflow.com/questions/21765178/how-to-pass-a-variable-to-a-casperjs-script-through-the-command-line) – Vaviloff May 03 '16 at 05:26

1 Answers1

1
var casper = require("casper").create({
  verbose: true,
});
var name = casper.cli.args[0];
var email = casper.cli.args[1];

See also: very close answer to your question; official CasprJS docs on working with CLI

Community
  • 1
  • 1
Vaviloff
  • 16,282
  • 6
  • 48
  • 56