ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP notices in EE template

August 10, 2012 7:39am

Subscribe [2]
  • #1 / Aug 10, 2012 7:39am

    Hi all.

    I am integrating a mailchimp subscribe form into an EE template. The form works, and allows the user to subscribe, but I have two notices appearing. I should mention no notices show when the form is in a standard page, not an EE template. I have set to allow PHP output on this form. I also tried input just to sure but both display the notices.

    The form has a require_once:

    <? require_once('-/inc/store-address.php'); if($_GET['submit']){ echo storeAddress(); } ?>

    and the store-address.php looks like:

    <?php
    function storeAddress(){
     
     if(!$_GET['email']){ return "No email address provided"; } 
    
     if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
      return "Email address is invalid"; 
     }
    
     require_once('MCAPI.class.php');
     $api = new MCAPI('87610ca40190fdaf58907cea1c2eb2c7-us2');
     
     $list_id = "245bd30377";
    
     if($api->listSubscribe($list_id, $_GET['email'], '') === true) {
      return 'Success! Check your email to confirm sign up.';
     }else{
      return 'Error: ' . $api->errorMessage;
     }
     
    }
    
    if($_GET['ajax']){ echo storeAddress(); }
    ?>


    I think the notices are refering to ‘submit’ in the require_once, and ‘ajax’ at the bottom of the store-address.php script.

    How can I resolve this?

     

  • #2 / Aug 10, 2012 8:49am

    Ralph

    78 posts

    You need to check if a value has been set before accessing it. You can use the isset() function:

    <? require_once('-/inc/store-address.php'); if(isset($_GET['submit'])){ echo storeAddress(); } ?>
    if(isset($_GET['ajax'])){ echo storeAddress(); }
  • #3 / Aug 10, 2012 8:54am

    Hi Patrick. Thank you for helping out.

    I have added the isset() function, and both notices disappear? Can you explain what that means?

  • #4 / Aug 10, 2012 9:53am

    Ralph

    78 posts

    If you try to access an element in an array that isn’t there php will report an error. The isset() function checks if that element exists in the array and returns true if it exists, false if not.

  • #5 / Aug 10, 2012 10:37am

    Lisa Wess

    20502 posts

    I have moved this to Community Help since it is fairly custom.  However - have you checked devot-ee for MailChimp add-ons? I think that they might make this a bit easier on you.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases