gform_after_submission is getting called in my page, but the $entry and $form objects are null. Is there any reason why that would be happening? Based on the output of the logs, I know the code runs, but can't figure out why the $entry argument is null.
add_action('gform_after_submission_2', 'post_to_third_party', 10, 2);
function post_to_third_party($entry, $form) {
error_log("Posting comments form");
$post_url = 'https://api.club-os.com/prospects?clubLocationId=686';
$body = array(
'first_name' => $entry['7.3'],
'last_name' => $entry['7.6'],
'email' => $entry['6'],
'mobilePhone' => $entry['8']
);
error_log('Before Post to' . $post_url);
$args = array(
'headers' => array('Authorization' => 'Basic ' . base64_encode( 'username' . ':' . 'password' )),
'body' => $body,
'sslverify' => false
);
foreach ($body as $key => $value) {
error_log($value . " in " . $key . ", ");
}
$request = new WP_Http();
$response = $request->post($post_url, $args);
}
Figured it out.
'first_name' => $entry['7.3'],
'last_name' => $entry['7.6'],
The 7.3 and 7.6 were incorrect indexes to the $entry object. I just used '7' and the split function to get it to work correctly.
Related
The situation:
I build an authentication service that uses Basic Authentication to check if the user exists on an external database and fetches some data. The users in question only exist on the external database.
The problem:
Typo3 needs to have an user entry in the fe_user table to login the user.
So whenever this entry does not exist, the user cannot login.
What I want to do:
Create the user in the authentication service to avoid using a sql dump from the external database and ensure that synchronisation is possible.
The relevant code:
public function authUser(array $user) {
$a_user = $this->login['uname'];
$a_pwd = $this->login['uident_text'];
$url = 'https://soliday.fluchtpunkt.at/api/queryMediaItems';
$data = json_decode('{"language":"de-at"}');
$basicAuth = base64_encode("$a_user:$a_pwd");
// use key 'http' even if you send the request to https://...
$options = array (
'http' => array (
'header' => array(
"Content-Type: application/json",
"Accept: application/json",
"Authorization: Basic {$basicAuth}"
),
'method' => 'POST',
'content' => '{"language":"de-at"}'
)
);
$context = stream_context_create ( $options );
$result = file_get_contents ($url, false, $context);
$response = gzdecode($result);
$checkUser = $this->fetchUserRecord ( $this->login ['uname'] );
if (!is_array($checkUser)&& $result!== FALSE) {
$this->createUser();
}
// failure
if ($result === FALSE) {
return static::STATUS_AUTHENTICATION_FAILURE_BREAK;
}
$this->processData($response);
// success
return static::STATUS_AUTHENTICATION_SUCCESS_BREAK;
}
public function createUser() {
$username = $this->login ['uname'];
$password = $this->login ['uident_text'];
$record = $GLOBALS ['TYPO3_DB']->exec_SELECTgetSingleRow ( '*', 'fe_users', "username = '" . $username . "' AND disable = 0 AND deleted = 0" );
if (! $record) {
// user has no DB record (yet), create one using defaults registered in extension config
// password is not important, username is set to the user's input
$record = array (
'username' => $username,
'password' => $password,
'name' => '',
'email' => '',
'disable' => '0',
'deleted' => '0',
'pid' => $this->config ['storagePid'],
'usergroup' => $this->config ['addUsersToGroups'],
'tstamp' => time ()
);
if (t3lib_extMgm::isLoaded ( 'extbase' )) {
$record ['tx_extbase_type'] = $this->config ['recordType'];
}
$GLOBALS ['TYPO3_DB']->exec_INSERTquery ( 'fe_users', $record );
$uid = $GLOBALS ['TYPO3_DB']->sql_insert_id ();
$record = $GLOBALS ['TYPO3_DB']->exec_SELECTgetSingleRow ( '*', 'fe_users', 'uid = ' . intval ( $uid ) );
}
$_SESSION [$this->sessionKey] ['user'] ['fe'] = $record;
}
the ext_localconf.php file:
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addService(
$_EXTKEY,
'auth' /* sv type */,
'AuthService' /* sv key */,
array(
'title' => 'GET Authentication service',
'description' => 'Authenticates users with GET request.',
'subtype' => 'getUserFE, authUserFE',
'available' => true,
'priority' => 90,
'quality' => 90,
'os' => '',
'exec' => '',
'className' => Plaspack\professionalZoneLogin\Service\AuthService::class,
)
);
You should extend AuthenticationService with your own code, way of doing that is described here https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Xclasses/Index.html
Not sure if it's related, but t3lib_extMgm should be \TYPO3\CMS\Core\Utility\ExtensionManagementUtility unless you're using TYPO3 6.
You can also see if you get any SQL errors by calling $GLOBALS['TYPO3_DB']->sql_error().
I'm hoping someone can help me out. I inherited some code that I have no idea how it works and now that it broke I have to fix it.
I am running PHP 5.5.38 on Windows server 2012 and IIS 8.5. I have finally discovered that the php code is using httprequest which doesn't exist anymore in my version of php and with windows. How would I convert the following to use curl code, if it is even possible?
$http = new HttpRequest('https://my.securelink.com/external/readi/ssoRequest', HttpRequest::METH_POST);
$http->addHeaders(
array(
'READI_AccessKey' => $accesskey,
'READI_Timestamp' => $timestamp,
'READI_RequestSignature' => $mac
)
);
$http->addPostFields(
array(
'READIUsername' => 'myusername',
'LastName' => $_GET["lastn"],
'FirstName' => $_GET["firstn"],
'Email' => $_GET["em"],
'ForceNewAssessment' => false,
'InternalID' => $_GET["userid"],
'IncludeSettings' => ''
)
);
//Optional Post Field: 'READIUserID' => 'xxxxxx'
$response = $http->send()->getBody();
echo "<h3>===== Response ===== </h3>";
echo "<pre>";
echo $response;
echo "</pre>";
$arr = xml2array($response);
$rtn_status = getvaluebypath($arr,'sso/status');
$rtn_timestamp = getvaluebypath($arr,'sso/timestamp');
if($rtn_status == "success") {
$redirectURL = getvaluebypath($arr,'sso/redirectUrl');
echo "<h3>===== Access Link ===== </h3>";
echo "" . $redirectURL . "";
header( "Location: $redirectURL");
}
You can try adding the HttpRequest class as guyver4mk suggested (the link from Jiri Hrazdil's comment) if you don't want to change the whole code.
But since you asked how to convert the existing to cURL, try this:
$header = [
'READI_AccessKey: '.$accesskey,
'READI_Timestamp: '.$timestamp,
'READI_RequestSignature: '.$mac
];
$post = [
'READIUsername' => 'myusername',
'LastName' => $_GET["lastn"],
'FirstName' => $_GET["firstn"],
'Email' => $_GET["em"],
'ForceNewAssessment' => false,
'InternalID' => $_GET["userid"],
'IncludeSettings' => ''
];
$ch = curl_init();
$options = [
CURLOPT_URL => 'https://my.securelink.com/external/readi/ssoRequest',
CURLOPT_HTTPHEADER => $header,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $post,
CURLOPT_RETURNTRANSFER => 1
];
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
if (!$response)
print_r(curl_error($ch));
curl_close($ch);
In my wp project, I am using Assently for e-signature implementation. Though I have an account and created a pdf form file to be filled by the user I just am not able to proceed a bit. I am finding documentation not clear.
Also, I am not clear about what needs to be done so that the user will be shown form to process the transaction.
So, any help/suggestions to proceed forward is appreciated.
I have tried the following based on assently-laravel. But it's asking me to login. What is an error here?
Code:
define('ASSENTLY_DEBUG', true);
define('ASSENTLY_KEY', 'key');
define('ASSENTLY_SECRET', 'secret-generated');
include_once('assently/Assently.php');
$assently = new Assently();
$assently->authenticate(ASSENTLY_KEY, ASSENTLY_SECRET);
$url = 'https://test.assently.com/api/v2/createcasefromtemplate';
$default = array(
'Id' => '5a0e0869-' . rand(1111, 9999) . '-4b79-' . rand(1111, 9999) . '-466ea5cca5ce'
);
$data = array(
'auth' => $assently->auth(),
'templateId' => '0e004e2b-b192-4ce2-8f47-d7a4576d7df6',
'newCaseId' => '5a0e0869-' . rand(1111, 9999) . '-4b79-' . rand(1111, 9999) . '-466ea5cca5ce',
'agentUsername' => ''
);
$data = array(
'json' => $data
);
$options = array(
'http' => array(
'header' => "Content-type: application/json; charset=utf-8\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo '<pre>';
print_r($result);
die;
create this class inside assently folder
use Assently\AssentlyCase;
use Exception;
class CustomAssentlyCase extends AssentlyCase
{
public function createFromTemplate($data)
{
$default = [
'newCaseId' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce'
];
$json = array_merge($default, $data);
try{
$response = $this->client->post($this->url('createcasefromtemplate'), [
'auth' => $this->assently->auth(),
'json' => $json
]);
}catch(Exception $e){
print_r($e->getMessage());
}
return $response;
}
}
Use
define('ASSENTLY_DEBUG', true);
define('ASSENTLY_KEY', 'key');
define('ASSENTLY_SECRET', 'secret-generated');
include_once('assently/Assently.php');
include_once('assently/CustomAssentlyCase.php');
$assently = new Assently();
$assently->authenticate(ASSENTLY_KEY, ASSENTLY_SECRET);
$data = array(
'templateId' => '0e004e2b-b192-4ce2-8f47-d7a4576d7df6',
'newCaseId' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce',
'agentUsername' => 'agentUsername' // PUT your agent username here it is required
);
$customAssentlyCase = new CustomAssentlyCase($assently);
$result = $customAssentlyCase->createFromTemplate($data);
print_r($result);
Try this, though not tested but should work. Good luck.
I will try to upload an Excel file and verify its contents.
So I tried the code as below.
if ($this->upload->do_upload("filename"))
{
...
// I Think it is idiot code . . but . . anyway . . :_(
$_POST = array(
"name" => $cell[0],
"phone" => $cell[1],
"birth" => $cell[2],
...
);
$config = array(
array("field"=>"name", "label"=>"Name", "rule"=> "required"),
...
);
$this->form_validation->set_rules($config);
$this->form_validation->set_error_delimiters('', '');
if ($this->form_validation->run() === false)
{
throw new Exception($this->form_validation->error_string());
}
...
}
How to validate custom data using form_validation?
You can pass your data like that:
$data = array(
'username' => 'johndoe',
'password' => 'mypassword',
'passconf' => 'mypassword'
);
$this->form_validation->set_data($data);
I try create signature to delete photo follow code below.
$args = array(
'method' => 'flickr.photos.delete',
'format' => 'php_serial',
'api_key' => $this->api_key,
'photo_id' => $photoId,
'auth_token' => $this->token,
);
ksort($args);
$auth_sig = "";
foreach ($args as $key => $data) {
if ( is_null($data) ) {
unset($args[$key]);
continue;
}
$auth_sig .= $key . $data;
$api_sig = md5($this->secret . $auth_sig);
}
But when I use signature for api flickr.photos.delete I got message Invalid signature although I still upload and replace image success.
This is code call api flickr.photos.delete,
$params = array(
'method' => 'flickr.photos.delete',
'format' => 'php_serial',
'api_key' => $this->api_key,
'photo_id' => $photoId,
'auth_token' => $this->token,
'perms' => 'write',
'api_sig' =>$api_sig
);
$encoded_params = array();
foreach ($params as $k => $v){
$encoded_params[] = urlencode($k).'='.urlencode($v);
}
$url = $this->rest_endpoint."?".implode('&', $encoded_params);
$rsp = file_get_contents($url);
$rsp_obj = unserialize($rsp);
var_dump($rsp_obj);
How can I resolve this problem?