Page 1 of 1

Newsletter signup action

PostPosted: Thu Oct 28, 2010 10:05 am
by tomhousley
Hi Steve,

On xataface.com there is the form to sign up to the newsletter:

Code: Select all
<form action="admin.php" method="post" onsubmit="if (!this.email.value.match(/^[a-z0-9A-Z.\-_]+@[a-z0-9A-Z.\-]+$/)){alert('Please enter a valid email address.');return false;} return true;">
   <input type="hidden" name="-action" value="maillist_signup"/>

   <input type="text" name="email" size="15" />
   <input type="submit" value="Sign up" />
</form>


Would it be possible for you to upload the maillist_signup.php and any related code so I may implement the same?

Many thanks, Tom

Re: Newsletter signup action

PostPosted: Fri Oct 29, 2010 2:38 pm
by shannah
Here's the custom action:
Code: Select all
<?php
class actions_maillist_signup {
   function handle(&$params){
      if ( !@$_POST['email'] ) return PEAR::raiseError("No email address supplied");
      if ( !preg_match('/^[a-z0-9A-Z.\-_]+@[a-z0-9A-Z.\-]+$/', $_POST['email']) ) return PEAR::raiseError("Please enter a valid email address");
      $record = new Dataface_Record("maillist_optin", array());
      $record->setValue('email', $_POST['email']);
      $res = $record->save();
      if ( PEAR::isError($res) ){
         header("Location: admin.php?-action=home&--msg=".urlencode("Error occurred trying to subscribe to maillist: ".$res->getMessage()));
         exit;
      } else {
         mail('email@example.com','New Xataface maillist signup', $record->val('email').' has signed up for the xataface newsletter.');
         header("Location: admin.php?-action=home&--msg=".urlencode("Thank you for subscribing to the Xataface maillist.  You can opt out at any time by following the link provided in emails from the list"));
         exit;
      }
   }   
}

Re: Newsletter signup action

PostPosted: Mon Nov 01, 2010 10:02 am
by tomhousley
Thank you Steve.

In the process of creating actions for confirming email address etc.

Once complete, I will post them here.

Cheers, Tom