Harder than I thought...
Hello,
I can't seem to get the array posted to the DA Insert Behaviour.
I can print_r the array and see the results present but in the js alert I set in the behaviour the array never shows up.
<?php require_once("../../Connections/emailList.php"); ?>
<?php require_once("../../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php
// WA Application Builder Insert
if (isset($_POST["InsertMe"])) // Trigger
{
echo "<script language=\"JavaScript\">\n";
echo "alert('";
echo '<pre>';
print_r($matches[0]);
echo '</pre>';
echo "we made it this far');\n";
echo "</script>";
// loop to allow array of inserts
for($i = 0; $i < sizeof($matches[0]); $i++) {
{
$WA_connection = $emailList;
$WA_table = "phplist_user_user";
$WA_sessionName = "phplist_user_user_id";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "id";
$WA_fieldNamesStr = "email|confirmed|uniqid|htmlemail|subscribepage";
$WA_fieldValuesStr = "$matches[0]" . "|" . "1" . "|" . md5(uniqid(mt_rand())) . "|" . "1" . "|" . "4";
$WA_columnTypesStr = "',none,''|none,none,NULL|',none,''|none,none,NULL|none,none,NULL";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_emailList;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Search, Find and Insert</title>
</head>
<body>
<form method="post">
Please enter full URL of the page to parse (including http://):<br />
<input type="text" name="url" size="65" value="<?php echo $the_url; ?>"/><br />
or enter text directly into textarea below:<br />
<textarea name="text" cols="50" rows="15"></textarea>
<br />
<input type="submit" value="Parse Emails" />
</form>
<p>
<form id="formUser" name="formUser" method="post" action="">
<?php
$the_url = isset($_REQUEST['url']) ? htmlspecialchars($_REQUEST['url']) : '';
?>
<?php
if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) {
// fetch data from specified url
$text = file_get_contents($_REQUEST['url']);
}
elseif (isset($_REQUEST['text']) && !empty($_REQUEST['text'])) {
// get text from text area
$text = $_REQUEST['text'];
}
// parse emails
if (!empty($text)) {
$res = preg_match_all("/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i",$text,$matches);
if ($res) {
// loop through array only taking the first one of any duplicates with the array_unique function
foreach(array_unique($matches[0]) as $email) {
echo $email . "<br />";
}
}
else {
echo "No emails found.";
}
}
?>
</p>
<p>
<label for="fldEmail"></label>
Email: **
<input name="fldEmail" type="text" id="fldEmail" size="45" />
</p>
<p> </p>
<p>
<input type="submit" name="InsertMe" id="InsertMe" value="Submit" />
</p>
<p> </p>
<p>rev3</p>
</form>
<p> </p>
</body>
</html>
The page allows you to specify some page that has email addresses in it then using preg_match_all makes an array of the results. I now need to pass that in the insert loop to the DB.
I'm down to thinking I need pass the array in a $_POST from a hidden field but tests have not worked with that method so I am at a loss.
Any ideas?