How can I test Mailchimp radio buttons in PHP? - php

I have a Mailchimp radio button setup for Yes/No. I'm having trouble testing it's value from PHP with something like this...
function draw_results_detail ($hitNum) {
$result = '';
if ($hitNum >= count($_SESSION['hitList'])) return $result;
if ($hitNum < 0) return $result;
$aHit = $_SESSION['hitList'][(int) $hitNum];
$result .= sprintf(
"%s %s<h2>%s %s</h2>",
$aHit->membership,
$aHit->affiliation,
htmlspecialchars(capitalize_scrub($aHit->fname)),
htmlspecialchars(capitalize_scrub($aHit->lname))
);
if (FALSE !== strpos(strtolower($aHit->unlisted),'yes')) {
$result .= "<p>Email address and telephone number are unlisted.</p>";
} else {
$result .= sprintf(
"<p>Email: <a href=\"mailto:%s\">%s<a/>" .
"<br/>Phone: %s</p>",
htmlspecialchars(strtolower($aHit->email)),
htmlspecialchars(strtolower($aHit->email)),
htmlspecialchars(strtolower($aHit->phone))
);
}
$temp = $aHit->modified;
if ($temp != '') {
$result .= "<span style=\"font-size:10px;\">(last modified: $temp UTC)</span>";
}
$temp = count($_SESSION['hitList']);
$hitNum += 1;
$result .= "<span style=\"font-size:10px;\"> [$hitNum of $temp]</span>";
return $result;
}
The central IF statement fails to trigger. If I "var_dump" $aHit, the "unlisted" key is String(0) even though Mailchimp shows the corresponding record's button is selected to Yes.
How can I test the button setting from Mailchimp?

Make sure the text of the Mailchimp radio button items EXACTLY matches the text of the corresponding SQL data element.
In this case, a webhook was updating the SQL record whenever Mailchimp data was modified. The text of the item wasn't being set correctly.
Rookie mistake, and not even in the snippet shown. Sorry for the confusion.

Related

Comparison of words from the database and output of the result

I need to check the words received from the database with the user's entered word and if there is a match, then output its value from the database, and if not, then output what the user entered.
The code below works fine if there is a match.
function d_typeplace_morf($d_typeplace)
{
global $wpdb;
$typeplace_results = $wpdb->get_results('SELECT vozmozhnyi_variant_mesta, ego_slovoforma_v_predlozhnom_padezhe FROM dEzpra_jet_cct_tip_mest_obrabotki');
if ($typeplace_results) {
foreach ($typeplace_results as $typeplace_result) {
$d_typeplace_raw = mb_strtolower($typeplace_result->vozmozhnyi_variant_mesta);
$d_typeplace_morf = mb_strtolower($typeplace_result->ego_slovoforma_v_predlozhnom_padezhe);
$d_typeplace = mb_strtolower($d_typeplace);
if (stripos($d_typeplace, $d_typeplace_raw) !== false) {
echo $d_typeplace_morf;
}
}
}
}
I'm an amateur in PHP, just learning. And I can't figure out how to output $d_typeplace if no match is found.
I tried to add
else {
echo $d_typeplace;
}
, but I get an array of words from the user entered.
I will be grateful for any help. Also for any suggestions for improving this code.
---Addition---
I apologize for my English. This is a problem in the Russian language, I need to take into account the morphology. To do this, the database has a list of words and their analog, for example, X = Y. I get these words and compare what the user entered. If he entered X, then we output Y. If he led Z, which is not in the database, then we output Z.
Thus, we check $d_typeplace with $d_typeplace_raw and if there is a match, we output $d_typeplace_morf, which is equal to $d_typeplace_raw. And if not, then $d_typeplace (it contains the value that the user entered).
Oh, I'm sorry, I understand myself that I'm explaining stupidly)
I cannot quite understand what you are asking: you need to output the string entered by the user, but you can only print an array?
If this is the case, I think you parsed the string before, in order to therefore you need to do join again the values contained in the array.
Try with:
else {
echo implode(" ", $d_typeplace);
}
--- EDITED ---
Try with:
function d_typeplace_morf($d_typeplace)
{
global $wpdb;
$typeplace_results = $wpdb->get_results('SELECT vozmozhnyi_variant_mesta, ego_slovoforma_v_predlozhnom_padezhe FROM dEzpra_jet_cct_tip_mest_obrabotki');
if ($typeplace_results) {
$found = false;
foreach ($typeplace_results as $typeplace_result) {
$d_typeplace_raw = mb_strtolower($typeplace_result->vozmozhnyi_variant_mesta);
$d_typeplace_morf = mb_strtolower($typeplace_result->ego_slovoforma_v_predlozhnom_padezhe);
$d_typeplace = mb_strtolower($d_typeplace);
if (stripos($d_typeplace, $d_typeplace_raw) !== false) {
echo $d_typeplace_morf;
$found = true;
break;
}
}
if (!$found) {
echo $d_typeplace;
}
}
}
But I think it would be more efficient, if you implemented the second code snippet written by #Luke.T
I'm presuming you were trying to add the else like this?
function d_typeplace_morf($d_typeplace)
{
global $wpdb;
$typeplace_results = $wpdb->get_results('SELECT vozmozhnyi_variant_mesta, ego_slovoforma_v_predlozhnom_padezhe FROM dEzpra_jet_cct_tip_mest_obrabotki');
if ($typeplace_results) {
foreach ($typeplace_results as $typeplace_result) {
$d_typeplace_raw = mb_strtolower($typeplace_result->vozmozhnyi_variant_mesta);
$d_typeplace_morf = mb_strtolower($typeplace_result->ego_slovoforma_v_predlozhnom_padezhe);
$d_typeplace = mb_strtolower($d_typeplace);
if (stripos($d_typeplace, $d_typeplace_raw) !== false) {
echo $d_typeplace_morf;
} else {
echo $d_typeplace;
}
}
}
}
Which was outputting an array because the for loop was continuing, if you add a break like so...
echo $d_typeplace;
break;
It should stop outputting an array. Depending on your use case you could however perform similar functionality directly in your sql query using LIKE ...
function d_typeplace_morf($d_typeplace)
{
global $wpdb;
$typeplace_results = $wpdb->get_results('
SELECT ego_slovoforma_v_predlozhnom_padezhe
FROM dEzpra_jet_cct_tip_mest_obrabotki
WHERE vozmozhnyi_variant_mesta LIKE %' . $d_typeplace . '%');
if ($typeplace_results) {
//Echo result
} else {
echo $d_typeplace;
}
}

Single way to show title based on Filters recommendation

I have a form with 5 options to filter data from mysql (start date, end date, user, course, level) and i would like to present a title with a custom text based on the selection, like if the user only choose dates, the title would say "Data from start date to end date), if the user choose user, then would be "Data for user from start date to end date, and so on.
Its a headache to make all possible combinations using if option 1 != "" && option2 == "" etc. In this case i have 25 possible combinations, there is any recommendation to handle this easily and thinking that if in a future i would like to add another filter that would be 30 combinations and i would have to rewrite the if again. Sorry if its a silly question but i dont see it another way clearly right now.
Let's simplify:
$output = "";
if($user != ""){
$output .= "User: " . $user . " ";
}
if($dateFrom != ""){
$output .= "Start date: " . $dateFrom . " ";
}
if($dateTo != ""){
$output .= "End date: " . $dateTo . " ";
}
echo $output;
You can build a message for user for example that way:
$response = "";
if($user_filter == true)
{
if($response == "")
{
$response = "Data for user: ".$some_user;
}
eles
{
$response = $response." and from user: ".$some_user;
}
}
if($date_filter == true)
{
if($response == "")
{
$response = "Data from ".$start_date." to ".$end_date;
}
eles
{
$response = $response." and from ".$start_date." to ".$end_date;
}
}
So that way you will and for each filter just one if...

Update PHP for AiContactSafe to add multiple redirects dependent on Combobox Value

This may help a few people using Aicontactsafe with joomla as the core component does not have it currently as an option. Essentially i need to change the module php file to allow different redirect urls depending on what dropdown option is selected in the "Studio" Combobox field.
Perfectly honest with you i do not know if i am typing in the correct fields or code values:
The test site you can see here - http://www.datumcreative.com/wellness/ and the form is 'book my taster class' on the right.
Below is where i believe code needs adding in the original file:
if (!array_key_exists('return_to', $parameters)) {
// initialize the database
$db = &JFactory::getDBO();
$query = 'SELECT redirect_on_success FROM #__aicontactsafe_profiles WHERE id = ' . $pf;
$db->setQuery( $query );
$redirect_on_success = $db->loadResult();
// set the return link to the current url or the one setup into the profile
if (strlen(trim($redirect_on_success)) == 0) {
$postData['return_to'] = $currentUrl;
} else {
$postData['return_to'] = $redirect_on_success;
}
}
To create the other redirects i added the following custom lines, below the line "$redirect_on_success = $db->loadResult();":
$redirect_to_wgc = "http://www.google.com";
$redirect_to_harp = "http://www.yahoo.co.uk";
I then needed to add the "if" statements **.
**if ($field_values['aics_studio'] == "Welwyn Garden City") {
$postData['return_to'] = $redirect_to_wgc;
}
elseif ($field_values['$aics_studio'] == "Harpenden") {
$postData['return_to'] = $redirect_to_harp;
}**
elseif (strlen(trim($redirect_on_success)) == 0) {
$postData['return_to'] = $currentUrl;
} else {
$postData['return_to'] = $redirect_on_success;
}
No luck so far, any suggestions?

Account Search Wildcard - SugarCRM

I'm looking for a way to do a wildcard search when searching for accounts in SugarCRM but I'm having trouble getting the queries to work properly.
Here's the build_generic_where_clause() function:
function build_generic_where_clause ($the_query_string) {
$where_clauses = Array();
$the_query_string = $this->db->quote($the_query_string);
array_push($where_clauses, "accounts.name like '%$the_query_string%'");
if (is_numeric($the_query_string)) {
array_push($where_clauses, "accounts.phone_alternate like '%$the_query_string%'");
array_push($where_clauses, "accounts.phone_fax like '%$the_query_string%'");
array_push($where_clauses, "accounts.phone_office like '%$the_query_string%'");
}
$the_where = "";
foreach($where_clauses as $clause)
{
if(!empty($the_where)) $the_where .= " or ";
$the_where .= $clause;
}
$log = fopen('1.txt', "a");
fwrite($log, $the_where . "\n");
return $the_where;
}
I only changed array_push($where_clauses, "accounts.name like '%$the_query_string%'"); to include the percentage signs on either side of the_query_string.
Here's processSearchForm() from view.list.php:
function processSearchForm(){
if(isset($_REQUEST['query']))
{
// we have a query
if(!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) { // from EditView cancel
$this->searchForm->populateFromArray($this->storeQuery->query);
}
else {
$this->searchForm->populateFromRequest();
}
$where_clauses = $this->searchForm->generateSearchWhere(true, $this->seed->module_dir);
if (count($where_clauses) > 0 )$this->where = '('. implode(' ) AND ( ', $where_clauses) . ')';
$GLOBALS['log']->info("List View Where Clause: $this->where");
$log = fopen('1.txt', "a");
fwrite($log, $this->where . "\n");
}
if($this->use_old_search){
switch($view) {
case 'basic_search':
$this->searchForm->setup();
$this->searchForm->displayBasic($this->headers);
break;
case 'advanced_search':
$this->searchForm->setup();
$this->searchForm->displayAdvanced($this->headers);
break;
case 'saved_views':
echo $this->searchForm->displaySavedViews($this->listViewDefs, $this->lv, $this->headers);
break;
}
}else{
echo $this->searchForm->display($this->headers);
}
}
Note that I only added the log file write to catch the $this->where. If I use the searchbox to find an account such as "Newbold" as well as "New York Design", I only get "Newbold" as a result and my log file reads (accounts.name like 'new%'). So the first percentage sign is being removed somehow or another, I believe in the processSearchForm() somewhere. It's tough to figure out if that's the case or if the culprit lies elsewhere. I find this code to be a bit convoluted and all over the place, but this is the only customization I need done. Any help would be immensely appreciated.
You should be able to do this without changing any code. When you're searching from the Accounts list view, simply add the wildcards to your search in the form. Put '%$the_query_string%' in the search form.
If you're wanting to programmatically use a wildcard to search for records, you can do something like the following.
<?php
$filter = 'ABC%'; // account names that start with 'ABC'
$account = BeanFactory::getBean('Accounts');
$accounts = $account->get_list("", "accounts.name like '".$filter."'");
foreach ($accounts['list'] as $account)
{
// do something with $account
}
get_list() will pull what you need. One thing to note, get_list() will only return the numbers of records that you have your list views to return. So if your list views only show 20 records, get_list() will return up to 20 records. If you want to get all results, use get_full_list().

php form validation not working

I have a form validation issue. Below is the logic that happens on submit (part of it at least.) In the for loop, we check an array of possible events that a site visitor can register for. If the user hasn't checked any events (these are checkboxes because a user can register for multiple events), we should enter the second if statement below, but for some reason we're not. I know that none of the post variables are set if nothing is checked and, by setting a session variable equal to the variable $ECEventCnt, I'm able to varify that if nothing is posted, that variable is equal to 0. However, we seem to never get into the second if statement. Any thoughts?
unset($_SESSION["ECEvents"]);
$ECEventsArray = array();
$ECEventCnt = 0;
$_SESSION['debug'] = 'EC';
for ($i=0; $i<count($Val_WhichEventTypes); $i++) {
$key = $Val_WhichEventTypes[$i]["eventKey"];
//echo 'key' . $key;
if (isset($_POST["WhichEvent-" . $key]) && $_POST["WhichEvent-" . $key] == $key) {
$_SESSION['debug'] .= ' we made it to the place.' . $_POST["WhichEvent-" . $key];
$ECEventsArray[$key] = $key ;
if (strlen($ECEventsArray[$key])) $ECEventCnt += 1; // Only advance counter if EC Event is checked (key value is set)
}
}
$_SESSION['ecventcount'] = $ECEventCnt;
if ($ECEventCnt = 0) {
set_step_INvalid(5);
$_SESSION['debug'] .= ' we made it to the 2nd place.';
$cnt += 1;
$ValidationError .= ((strlen($ValidationError)==0) ? "" : ", ") . "<br />Please just select at least one Event Type/Time";
}
$_SESSION["ECEvents"] = $ECEventsArray;
//valid_step52();
}
if ($ECEventCnt = 0) {
should be
if ($ECEventCnt == 0) {
You are assigning to the variable $ECEventCnt, but what you mean to do is compare using it.

Categories