0

i have the following Problem and i have no ideas left. I try to explain: We have some Producttests you need to register for. A Post can be a Producttest, wich is indicated by a checkbox in the editscreen. So if the checkbox is checked there will be a formular attached to the post via the_content filter. Works fine till then. After register an opt-in email is being send to the user for activating himself. And here is the Problem: for the activation url i attached the users email, a generated key and a action variable. I just generate the string and put it in the email. The logic for activation is in the_content filter either. It looks like this:

public function post_show_form( $content ) {
        if( !is_single() ) return $content;

        $file = 'form';
        if( !( $val = get_post_meta( get_the_id(), 'is_producttest', TRUE ) ) ) return $content;


        if( isset( $_GET[ 'optin_produkttest' ] ) && !empty($_GET[ 'optin_produkttest' ]) ) {

            if( $this->model->already_registered( $_GET[ 'email' ] ) ) {

                if( $this->model->activate( $_GET[ 'email' ], $_GET[ 'regkey' ] ) ) {
                    if( function_exists( 'activate_user_in_cr' ) ) {
                        activate_user_in_cr( $_GET[ 'email' ] );
                    }

                    return '<h1>Success</h1>' . $content;
                }
            } else {
                return $content . '<h1>Error</h1>';
            }
        } else {

            $start_date = new \DateTime(get_field( 'form_test_startdate', FALSE, FALSE ));
            $end_date = new \DateTime(get_field( 'form_test_enddate', FALSE, FALSE ));
            $now_date = new \DateTime(date( "Ymd"));


            if( $now_date < $start_date){
                $file = 'form';
            }else{
                 if( $now_date < $end_date ){
                     $file = 'running';
                 } else{
                    $file = 'expired';
                 }
            }

            return $content . $this->view->get_template( $file );
        }
    }

The problem: the user is always activated immediatly and the "isset( $_GET[ 'optin_produkttest' ] ) && !empty($_GET[ 'optin_produkttest' ])" is always set and they have the right values but i dont set them, EVER. How come they are set anyway. How is that possible, i dont understand it at all.

I hope you understand what i mean, if not ask please. I need to fix this.

Thanks

  • When you say "user is always activated immediatly", do you mean when they submit the form, or when they visit the page? – Jacob Peattie May 27 at 13:31
  • when they submit the form, yes – sibbih May 27 at 13:44
  • i had the same code in an add_action('init', 'function_to_call'); the same problem here, after sending the form its activated. – sibbih May 27 at 13:57
  • What's the code for the form? Is one of the fields named optin_produkttest? – Jacob Peattie May 27 at 14:08
  • no, there is nothing named like that. Just simple firstname, lastname stuff EDIT: a hidden field with the id of the current post, nothing more. Never had this before. – sibbih May 27 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.