-
Notifications
You must be signed in to change notification settings - Fork 34
Modified PHP API Example #39
base: master
Are you sure you want to change the base?
Conversation
* To determine yours, check the last 3 digits of your API key | ||
* ================ | ||
*/ | ||
$url = 'https://us5.api.mailchimp.com/3.0/lists/' . list_id . '/members/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider setting the us5
portion to a variable like list_id
and api_key
because it can change from user to user. For example, my list is us6
*/ | ||
$pfb_data = array( | ||
'email_address' => $_POST['emailname'], | ||
'status' => 'pending', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider adding 'interests' => $interests,
where $interests
may be built like this:
// Build the $interests array
$interests = [];
$interestArr = isset($_POST['interests']) && is_array($_POST['interests']) ? $_POST['interests'] : [];
foreach ($interestArr as $id) {
$interests[$id] = true;
}
* ================ | ||
*/ | ||
$pfb_data = array( | ||
'email_address' => $_POST['emailname'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider using $_POST['email']
because 1) I'm not sure what emailname
is, and 2) it's a good practice to have your email input with the name="email" for autofilling purposes
*/ | ||
$pfb_data = array( | ||
'email_address' => $_POST['emailname'], | ||
'status' => 'pending', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why pending
instead of subscribed
? The reason I'm using this file is to subscribe users with ajax without the required double opt-in, so subscribed
status is perfect for my use case.
* ================ | ||
*/ | ||
define("api_key", "your-api-key-here"); | ||
define("list_id", "your-list-id-here"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually see these constants in ALL_CAPS_CASE
, but I guess that's a preference thing.
I modified my sample to better match PSR-2 standards and other tweaks requested in last PR (#37).