Send custom variable in Email - contact form 7 - wordpress

| add_action('wpcf7_before_send_mail', 'save_application_form');
function save_application_form($wpcf7) {
if ($wpcf7->id == 19) {
$client->setAccessToken($_SESSION['accessToken']);
$service = new Google_DriveService($client);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$file = new Google_DriveFile();
$wpcf7 = WPCF7_ContactForm :: get_current() ;
$form_to_DB = WPCF7_Submission::get_instance();
if ($form_to_DB) {
/* #var $mail type */
$uploaded_files = $form_to_DB->uploaded_files(); // this allows you access to the upload file in the temp location
$fileId = '';
$cf7_file_field_name = 'file-181'; // [file uploadyourfile]
//Do the magic the same as the refer link above
$image_location = $uploaded_files[$cf7_file_field_name];
$mime_type = finfo_file($finfo, $image_location);
$file->setMimeType($mime_type);
$test = pathinfo($image_location);
$service->files->insert(
$file, array(
'data' => file_get_contents($image_location),
'mimeType' => $mime_type
)
);
$filetest = $service->files->get($fileId);
$add = $filetest['items'];
$final = $add[0]['alternateLink'];
// the message
$mail = "Link:" . $final;
$mail = $wpcf7->prop('mail') ;
$wpcf7->set_properties( array("mail" => $mail)) ;
// return current cf7 instance
return $wpcf7 ;
}
}
}
|I have one function in that function I have one variable where I am storing share link. I want to pass this variable to contact form 7 mail

Kindly check below code for your question.
add_action( 'wpcf7_before_send_mail', 'my_add_custom_field' ); // its called befoee email sent
function my_change_subject_mail($WPCF7_ContactForm)
{
$wpcf7 = WPCF7_ContactForm :: get_current() ;
$submission = WPCF7_Submission :: get_instance() ;
if ($submission)
{
$posted_data = $submission->get_posted_data() ;
// nothing's here... do nothing...
if ( empty ($posted_data))
return ;
$mail = $WPCF7_ContactForm->prop('mail') ;
// Your code
if ($WPCF7_ContactForm->id == 19)
{
$filetest = $service->files->get($fileId);
$add = $filetest['items'];
$final = $add[0]['alternateLink'];
$mail . = "Link:" . $final;
}
// Save the email body
$WPCF7_ContactForm->set_properties( array("mail" => $mail)) ;
// return current cf7 instance
return $WPCF7_ContactForm ;
}
}
You only did one mistake that you are not saving the mail body.

Related

How to create a bulk data endpoint in woocommerce without breaking the site performance

I am trying to create a wordpress plugin that exports or sends out (through an API) bulk data resource by resource (such as products, orders, customers, etc) of a woocommerce site without affecting the performance of the site.
But I am new to php and finding it difficult.
Also, I was planning to use WP-Cron to build the bulk data on certain time interval in order to avoid the hit in performance. But, from some research, I got to know that WP-Cron is not a reliable solution to my goal as it is not a regular cron and also, it can be disabled easily.
As my idea requires a regular bulk data building approach, I am now looking out for different options such as recursive calling.
I have exposed an endpoint where I will be receiving some required details and will call the class that will take care of the bulk data building.
public function getCCBulkSync( $request )
{
$entity = $_GET['entity'];
$startDate = $_GET['start_date'];
$endDate = $_GET['end_date'];
$delivery_url = $_GET['delivery_url'];
$limit = $_GET['limit'];
if(!$delivery_url) return 'Delivery Url cannot be null';
include 'class-wc-cc-bulk-data-builder.php';
$bulkBuilder = WC_CC_Bulk_Data_Builder::getInstance();
$bulkBuilder = ($bulkBuilder === NULL || $bulkBuilder->getObjectDetails()['entity'] === NULL) ? $bulkBuilder->setObjectDetails($entity, $delivery_url, $startDate, $endDate, $limit) : $bulkBuilder;
return 'Bulk sync initiated! Check later for the completion!!!';
}
The bulk data builder class code is given below
class WC_Bulk_Data_Builder
{
private static $instance = NULL;
protected $entity = NULL;
protected $startDate = NULL;
protected $endDate = NULL;
protected $delivery_url = NULL;
protected $dataCount = 0;
protected $limit = 0;
static public function getInstance()
{
if (self::$instance === NULL)
self::$instance = new WC_Bulk_Data_Builder();
return self::$instance;
}
protected function __construct($entity = NULL, $delivery_url = NULL, $startDate = NULL, $endDate = NULL, $limit = 1000)
{
$this->entity = $entity;
$this->delivery_url = $delivery_url;
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->limit = $limit;
}
public function getObjectDetails() {
$objData = array();
$objData['entity'] = $this->entity;
$objData['startDate'] = $this->startDate;
$objData['endDate'] = $this->endDate;
$objData['deliveryUrl'] = $this->delivery_url;
$objData['dataCount'] = $this->dataCount;
$objData['limit'] = $this->limit;
return $objData;
}
public function setObjectDetails($entity = NULL, $delivery_url = NULL, $startDate = NULL, $endDate = NULL, $limit = 1000) {
$this->entity = $entity;
$this->delivery_url = $delivery_url;
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->limit = $limit;
$this->bulk_data_builder();
return self::$instance;
}
function bulk_data_builder()
{
$entity = $this->entity;
if($entity === 'order') {
$this->build_order_data();
}
sleep(20);
$this->bulk_data_builder();
}
protected function build_order_data()
{
$ordersArray = wc_get_orders( array(
'limit' => 250,
'offset' => $this->dataCount,
'orderby' => 'ID',
'order' => 'ASC',
) );
$this->dataCount += count($ordersArray);
$orders = array();
foreach($ordersArray as $order_index=>$order) {
$orders[$order_index]=$order->get_data();
$orders[$order_index]['refunds'] = $order->get_refunds();
}
$header_args = array_keys($orders[0]);
$output = fopen( 'order_csv_export.csv', 'a+' );
fputcsv($output, $header_args);
foreach($orders AS $order_item){
foreach($header_args AS $ind=>$key) {
if('array' === gettype($order_item[$key])) $order_item[$key] = json_encode($order_item[$key]);
}
fputcsv($output, $order_item);
}
if($dataCount>=$limit)
{
$dataCount = 0;
$req_headers = array();
$req_headers[] = 'Content-Type: text/csv; charset=utf-8';
$req_headers[] = 'Content-Disposition: attachment; filename=order_csv_export.csv';
$cURL = curl_init();
$setopt_array = array(CURLOPT_URL => $delivery_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $req_headers);
curl_setopt_array($cURL, $setopt_array);
$json_response_data = curl_exec($cURL);
curl_close($cURL);
exit;
}
fclose($output);
}
}
Now, what I am expecting is the recursive calling on same bulk_data_builder() method which should build the data continuously on a 20 seconds interval or any other way to do the same until the record count reaches the limit, so that I can send the bulk data built, to the delivery_url.
But, the mentioned method is not getting called recursively. Only for the first time the method is called and giving back 250 records.
As I am new to php, I am not sure about the async functionality also.
Can someone help me to understand what I am doing wrong or what I am missing?

Ajax and hook_form_alter

I'm getting a "The value you selected is not a valid choice." error for an Ajax modified field when I submit a custom altered node/add form. An "Illegal choice error is also written to the log. This a Drupal 9 version of an app that I developed using Drupal 7 which worked. The Ajax functionality is working. Why? How do I fix it?
I believe the error is coming from some Symfony code. I'm dynamically modifying two "select" form elements. The first doesn't appear to have the problem. I'm doing the same thing for both form elements.
function bncreports_form_node_bnc_message_form_alter(&$form, FormStateInterface $form_state, $form_id)
{
$form['actions']['submit']['#submit'][] = 'bncreports_node_bnc_message_form_submit';
$form['#title'] = t('Create Contact Us');
$user = User::load(\Drupal::currentUser()->id());
$district_id = $user->get('field_district')->value;
$form['field_first_name']['widget'][0]['value']['#default_value'] = $user->get('field_first_name')->value;
$form['field_last_name']['widget'][0]['value']['#default_value'] = $user->get('field_last_name')->value;
$form['field_email']['widget'][0]['value']['#default_value'] = $user->getEmail();
$form['field_email']['widget'][0]['value']['#attributes'] = ['onblur' => 'this.value=this.value.toLowerCase();'];
$form['field_phone']['widget'][0]['value']['#default_value'] = $user->get('field_phone')->value;
$form['field_district']['widget'][0]['value']['#default_value'] = $district_id;
if (isset($form['field_district']['widget']['#default_value']))
$form['field_district']['widget']['#default_value'] = $district_id; // wtf?
if ($user->hasRole('administrator') || $user->hasRole('bnc_operator') || $user->hasRole('ao_user')) {
$form['field_office']['#access'] = false;
$form['field_office_name']['#access'] = false;
$form['field_office_names']['#access'] = false;
$form['field_site_codes']['#access'] = false;
$form['field_district']['widget']['#ajax'] = [
'event' => 'change',
'callback' => 'bncreports_ajax_offices_and_user',
'wrapper' => ['ajax-wrapper-field-offices', 'ajax-wrapper-field-user'],
];
$form['field_offices']['#prefix'] = '<div id="ajax-wrapper-field-offices">';
$form['field_offices']['#suffix'] = '</div>';
$form['field_user']['#prefix'] = '<div id="ajax-wrapper-field-user">';
$form['field_user']['#suffix'] = '</div>';
$district_id = $form_state->hasValue('field_district')
? $form_state->getValue('field_district')[0]['value']
: false;
$form['field_offices']['widget']['#options'] = $district_id
? Functions::officeNames($district_id)
: [];
$form['field_user']['widget']['#options'] = $district_id
? ['_none' => '- Select a value -'] + Functions::districtUserLastandFirstNames($district_id)
: ['_none' => '- Select a value -'];
} else { // Alterations for court users only
$form['bnc_prefix']['#markup'] =
'<p>BNC User Support: ' . Constants::BNC_PHONE_NO
. ' ' . Constants::BNC_EMAIL . '</p>'
. '<p>AO Program and CM/ECF Contacts</p>'
. '<h4>Unable to find what you need? Send us a message.</h4>';
$form['bnc_prefix']['#weight'] = -1;
$form['field_offices']['#access'] = false;
$form['field_office_name']['#access'] = false;
$form['field_office_names']['#access'] = false;
$form['field_site_codes']['#access'] = false;
$form['field_user']['#access'] = false;
$form['field_non_user_name']['#access'] = false;
$form['field_non_user_phone']['#access'] = false;
$form['field_assigned_to']['#access'] = false;
$form['revision_information']['#access'] = false;
$office = $user->get('field_office')->value;
$form['field_district']['widget']['#default_value'] = $district_id;
$form['field_office']['widget']['#options'] = Functions::officeNames($district_id);
$form['field_office']['widget']['#default_value'] = $office;
$form['field_office_name']['widget'][0]['value']['#default_value'] = Functions::officeName($district_id, $office);
$form['#attached']['library'][] = 'bncreports/restricted_contact_log';
}
}
function bncreports_ajax_offices_and_user(array $form, FormStateInterface $form_state): AjaxResponse
{
$response = new AjaxResponse();
// Issue a command that replaces the elements 'field_offices' and 'field_user'
$response->addCommand(new ReplaceCommand('#ajax-wrapper-field-office', $form['field_offices']));
$response->addCommand(new ReplaceCommand('#ajax-wrapper-field-user', $form['field_user']));
return $response;
}
Problem is there are no allowed values for the field_user list. Solution is to use an allowed values function callback. This is done in Configuration synchronization for Field Storage. Set the allowed value function property and import. Need to provide uuid to override existing config.
In my hook_form_alter:
$_SESSION['selected_district_id'] = $district_id;
In my xxx.module:
function bncreports_allowed_values_function(FieldStorageConfig $definition, ContentEntityInterface $entity = NULL, $cacheable): array
{
// NOTE: This is defined in Configuation synchronization for Field Storage (see node.field_user)
if ($entity->bundle() == 'bnc_message') { // Add a custom field_user options for BNC Message nodes.
$district_id = $_SESSION['selected_district_id'] ?? null;
return Functions::districtUserLastandFirstNames($district_id);
}
throw new Exception("Allowed values function for {$entity->bundle()} is not allowed.");
}

Opencart session info in Wordpress

I have a site that is using both WordPress and Opencart. The main site is built off of WP and then there is an OC site in a sub-directory.
I would like to bring the session data from OC into the wordpress site so I can have the Wishlist, Shopping Cart, Checkout, Login status and My Account info throughout the site.
Does anyone know what code I can add to WP to bring in this info?
Thanks again in advance,
Matt
There are already many articles regarding module development and export and session building in OpenCart.
Given your existing pages:
yoursite.com/wordpress
yoursite.com/wordpress/page.php (i.e. your page outside the shop),
yoursite.com/products/catalog/controller/common/header.php -and-
yoursite/products/catalog/view/theme/default/template/common/header.tpl
1. Create file headerXYZ.php using the following code and save it to the root directory of your main site (or other location of your choosing outside your OC shop).
<?php
// Config
require_once('shop/config.php');
// VirtualQMOD
require_once('shop/vqmod/vqmod.php');
$vqmod = new VQMod();
// VQMODDED Startup
require_once($vqmod->modCheck(DIR_SYSTEM . 'startup.php'));
// Application Classes
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/customer.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/affiliate.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/currency.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/tax.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/weight.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/length.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/cart.php'));
$myVar = array();
$myVar = array();
// Registry
$registry = new Registry();
// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);
// Config
$config = new Config();
$registry->set('config', $config);
// Database
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);
// Url
$url = new Url($config->get('config_url'), $config->get('config_use_ssl') ? $config->get('config_ssl') :
$config->get('config_url'));
$registry->set('url', $url);
// Log
$log = new Log($config->get('config_error_filename'));
$registry->set('log', $log);
function error_handler($errno, $errstr, $errfile, $errline) {
global $log, $config;
switch ($errno) {
case E_NOTICE:
case E_USER_NOTICE:
$error = 'Notice';
break;
case E_WARNING:
case E_USER_WARNING:
$error = 'Warning';
break;
case E_ERROR:
case E_USER_ERROR:
$error = 'Fatal Error';
break;
default:
$error = 'Unknown';
break;
}
if ($config->get('config_error_display')) {
echo '<b>' . $error . '</b>: ' . $errstr . ' in <b>' . $errfile . '</b> on line <b>' . $errline . '</b>';
}
if ($config->get('config_error_log')) {
$log->write('PHP ' . $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
}
return true;
}
// Error Handler
set_error_handler('error_handler');
// Request
$request = new Request();
$registry->set('request', $request);
// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
$response->setCompression($config->get('config_compression'));
$registry->set('response', $response);
// Cache
$cache = new Cache();
$registry->set('cache', $cache);
// Session
$session = new Session();
$registry->set('session', $session);
// Language Detection
$languages = array();
$query = $db->query("SELECT * FROM " . DB_PREFIX . "language");
foreach ($query->rows as $result) {
$languages[$result['code']] = $result;
}
$detect = '';
if (isset($request->server['HTTP_ACCEPT_LANGUAGE']) && ($request->server['HTTP_ACCEPT_LANGUAGE'])) {
$browser_languages = explode(',', $request->server['HTTP_ACCEPT_LANGUAGE']);
foreach ($browser_languages as $browser_language) {
foreach ($languages as $key => $value) {
if ($value['status']) {
$locale = explode(',', $value['locale']);
if (in_array($browser_language, $locale)) {
$detect = $key;
}
}
}
}
}
if (isset($request->get['language']) && array_key_exists($request->get['language'], $languages) &&
$languages[$request->get['language']]['status']) {
$code = $request->get['language'];
} elseif (isset($session->data['language']) && array_key_exists($session->data['language'], $languages)) {
$code = $session->data['language'];
} elseif (isset($request->cookie['language']) && array_key_exists($request->cookie['language'], $languages)) {
$code = $request->cookie['language'];
} elseif ($detect) {
$code = $detect;
} else {
$code = $config->get('config_language');
}
if (!isset($session->data['language']) || $session->data['language'] != $code) {
$session->data['language'] = $code;
}
if (!isset($request->cookie['language']) || $request->cookie['language'] != $code) {
setcookie('language', $code, time() + 60 * 60 * 24 * 30, '/', $request->server['HTTP_HOST']);
}
$config->set('config_language_id', $languages[$code]['language_id']);
$config->set('config_language', $languages[$code]['code']);
// Language
$language = new Language($languages[$code]['directory']);
$language->load($languages[$code]['filename']);
$registry->set('language', $language);
// Document
$document = new Document();
$registry->set('document', $document);
// Customer
$registry->set('customer', new Customer($registry));
// Affiliate
$affiliate = new Affiliate($registry);
$registry->set('affiliate', $affiliate);
if (isset($request->get['tracking']) && !isset($request->cookie['tracking'])) {
setcookie('tracking', $request->get['tracking'], time() + 3600 * 24 * 1000, '/');
}
// Currency
$registry->set('currency', new Currency($registry));
// Tax
$tax = new Tax($registry);
$registry->set('tax', $tax);
// Weight
$registry->set('weight', new Weight($registry));
// Length
$registry->set('length', new Length($registry));
// Cart
$registry->set('cart', new Cart($registry));
// Front Controller
$controller = new Front($registry);
// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance'));
// SEO URL's
$controller->addPreAction(new Action('common/seo_url'));
// Router
if (isset($request->get['route'])) {
$action = new Action($request->get['route']);
} else {
$action = new Action('common/home');
}
// Dispatch
$controller->dispatch($action, new Action('error/not_found'));
2. Now, include headerXYZ.php in page.php i.e. Place the statement below on line 1 at the very top of page.php
<?php require_once ('headerXYZ.php');?>
3. Finally, right after the opening body tag of your external page.php page add the following list of statements
<?php
require_once('shop/catalog/model/total/sub_total.php');
require_once('shop/catalog/language/english/total/sub_total.php');
require_once('shop/catalog/model/total/reward.php');
require_once('shop/catalog/model/total/shipping.php');
require_once('shop/catalog/model/total/coupon.php');
require_once('shop/catalog/model/total/tax.php');
require_once('shop/catalog/model/total/credit.php');
require_once('shop/catalog/language/english/total/credit.php');
require_once('shop/catalog/model/total/voucher.php');
require_once('shop/catalog/model/total/total.php');
require_once('shop/catalog/language/english/total/total.php');
foreach($myVar as $key=>$value)
{
$$key = $value;
}
require_once('shop/catalog/controller/common/header.php');
require_once('shop/catalog/view/theme/default/template/common/header.tpl');
?>
That's it... You're done! You should now have a fully functional header (with working cart, login, etc.) in your page located outside of your Opencart shop.
SIDE NOTE: You could also just plug the entire code (including the content of headerXYZ.php and the 13 require_once statements) directly into the your external page.
I was looking for something similar, what I did was to write same html/css for footer and header in both systems, after that, I wrote an additional Wordpress plugin to show user and cart info when user is logged in opencart.
https://github.com/saRca/op2wp

Using the $object in Actions.I've created a module but parameter _action($object) is not work

Using the $object in Actions.
$object: Many actions act on one of Drupal’s built-in objects: nodes, users, taxonomy terms, and so on. When an action is executed by trigger.module, the object that is currently being acted upon is passed along to the action in the $object parameter. For example, if an action is set to execute when a new node is created, the $object parameter will contain the node object.
$object haven't value.i will get node's title and use in code.
function beep_action($object, $context) {
global $user;
//$q_mailfrom = db_query("SELECT mail FROM {users} WHERE uid = '%d'", 1);
// $f_mailfrom = db_fetch_object($q_mailfrom);
$q_mailuser = db_query("SELECT uid, mail FROM {users}");
// $a_mailto=array();
// $i=0;
while($f_mailuser = db_fetch_object($q_mailuser)){
if($f_mailuser->uid==1){
$mailfrom = $f_mailuser->mail;
}
$q_mailer = db_query("SELECT news,proudcts,privilagecard,occassioncard,others FROM {beep} WHERE uid = '%d'", $f_mailuser->uid);
$f_mailer = db_fetch_object($q_mailer);
if($f_mailer->news==1 OR $f_mailer->proudcts==1 OR $f_mailer->privilagecard==1 OR $f_mailer->occassioncard==1 OR $f_mailer->others==1 ){
if($f_mailer->news==1){
$mailto = $f_mailuser->mail;
$subject = "... Group";
$message = "<h2>... Group Latest News </h2>".$object->nid."<br/>Test";
drupal_mail('beep', 'reply', $mailto, language_default(),
array('body' => $message, 'subject' => $subject), $mailfrom, TRUE);
}
// $a_mailto[$i]= $f_mailto->mail;
// $i++;
}
}
}
I see what you want
function MYMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
switch($op){
case 'insert':
if($node->type == 'mytype'){
beep_action($node);
}
break;
}
}
Show call function. What you post in $object ?
And read drupal code stantarts.
function beep_action($object, $context) {
_vdump($object);
global $user;
$default_from = variable_get('site_mail', ini_get('sendmail_from'));
$query = "SELECT user.uid, user.mail FROM {users} user WHERE status <> %d";
$result = db_query($query, 0);
$subject = t("Azaran Mehr Group");
while ($row = db_fetch_object($result)) {
$query = "SELECT beep.news, beep.proudcts, beep.privilagecard, beep.occassioncard, beep.others FROM {beep} beep WHERE uid = %d"; // Do not use ' on integer values
$f_mailer = db_fetch_object(db_query($query, $row->uid));
if ($f_mailer->news == 1 && ($f_mailer->proudcts == 1 || $f_mailer->privilagecard == 1 || $f_mailer->occassioncard == 1 || $f_mailer->others == 1)) {
$message = '<h2>'. t('Azaran Mehr Group Latest News - !nid', array('!nid' => $object->nid)) .'</h2><br/>Test';
drupal_mail('beep', 'reply', $row->mail, language_default(),
array('body' => $message, 'subject' => $subject), $default_from, TRUE);
}
}
}
function _vdump($var, $keys = FALSE) {
if($keys){
drupal_set_message('<pre>' . print_r(array_keys($var), 1) . '</pre>');
}
else {
drupal_set_message('<pre>' . print_r($var, 1) . '</pre>');
}
}

Drupal and netForum: Creating a User

I am trying to create a user in netForum from a Drupal Webform.
Using a webform hook, I am calling two functions to take a users email address and first and last name, and create a netforum account when a user submits basic webforms.
However, the form times out when I hit submit, and the watchdog error from Netforum is 'could not fetch http headers'. Have I done something wrong in my implementation? I keep getting a timeout.
http://wiki.avectra.com/XWeb:WEBWebUserCreate
function inclind_form_webform_submission_insert($node, $submission) {
// find the email address in the form
$form_fields = $node->webform['components'];
foreach ($form_fields as $key => $value) {
$arguments = array();
$response = '';
if ($value['type'] == 'email') {
$arguments = array(
'emailToMatch' => $submission->data[$key]['value'][0]
);
$response = netforum_xweb_request('WEBWebUserFindUsersByEmail', $arguments, NULL);
if (!isset($response) || $response->{#attributes}['recordResult'] == 0) {
inclind_form_create_netforum_user($form_fields, $submission);
}
}
}
return;
}
/*
* Create a user in netForum based on form data
*
* #param $form_fields
* The form structure passed in from inclind_form_webform_submission_insert
* #param $submission
* The form data passed in from inclind_form_webform_submission_insert
*/
function inclind_form_create_netforum_user($form_fields, $submission) {
$arguments = array();
$arguments['oWebUser']['Individual'] = array();
$arguments['oWebUser']['Email'] = array();
$arguments['oWebUser']['Customer'] = array();
$arguments['oWebUser']['Business_Address'] = array();
$arguments['oWebUser']['Business_Phone'] = array();
$arguments['oWebUser']['Business_Phone_XRef'] = array();
$arguments['oWebUser']['Business_Fax'] = array();
$arguments['oWebUser']['Business_Fax_XRef'] = array();
foreach ($form_fields as $key => $value) {
if ($value['form_key'] == 'ind_first_name') {
$arguments['oWebUser']['Individual']['ind_first_name'] = $submission->data[$key]['value'][0];
}
if ($value['form_key'] == 'ind_last_name') {
$arguments['oWebUser']['Individual']['ind_last_name'] = $submission->data[$key]['value'][0];
}
if (strlen($arguments['oWebUser']['Individual']['ind_first_name']) && strlen($arguments['oWebUser']['Individual']['ind_last_name'])) {
$arguments['oWebUser']['Individual']['ind_full_name'] = $arguments['oWebUser']['Individual']['ind_first_name'] . ' ' . $arguments['oWebUser']['Individual']['ind_last_name'];
}
if ($value['form_key'] == 'eml_address') {
$arguments['oWebUser']['Email']['eml_address'] = $submission->data[$key]['value'][0];
$arguments['oWebUser']['Customer']['cst_web_login'] = $submission->data[$key]['value'][0];
$arguments['oWebUser']['Customer']['cst_new_password'] = user_password(20);
$arguments['oWebUser']['Customer']['cst_new_password_confirm'] = $arguments['oWebUser']['Customer']['cst_new_password'];
}
if ($value['form_key'] == 'adr_post_code') {
$arguments['oWebUser']['Business_Address']['adr_post_code'] = $submission->data[$key]['value'][0];
}
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_city'])) {
$arguments['oWebUser']['Business_Address']['adr_city'] = 'Not Given';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_state'])) {
$arguments['oWebUser']['Business_Address']['adr_state'] = 'NA';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_post_code'])) {
$arguments['oWebUser']['Business_Address']['adr_post_code'] = '00000';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_country'])) {
$arguments['oWebUser']['Business_Address']['adr_country'] = 'Not Given';
}
if (!isset($arguments['oWebUser']['Business_Phone']['phn_number'])) {
$arguments['oWebUser']['Business_Phone']['phn_number'] = '000-000-0000';
}
if (!isset($arguments['oWebUser']['Business_Phone_XRef']['cph_extension'])) {
$arguments['oWebUser']['Business_Phone_XRef']['cph_extension'] = '000';
}
if (!isset($arguments['oWebUser']['Business_Fax']['fax_number'])) {
$arguments['oWebUser']['Business_Fax']['fax_number'] = '000-000-0000';
}
$response = netforum_xweb_request('WEBWebUserCreate', $arguments, '1 min');
watchdog('netforum', 'netforum user #user created', array('#user' => $arguments['oWebUser']['Email']['eml_address']), WATCHDOG_NOTICE);
}
Solved: http://drupal.org/node/866534

Resources