Fork me on GitHub

Variables wont load  Bottom

  • I'm working on a petition module and i'm having problems sending variables to function.

    In my function to add the signature to the database it's suppose to send you to the "Thank You" page after the signature has been successfully added.

    code from "add_signature"...

    Code

    $tid = pnModAPIFunc('bkbPetition',
                            'user',
                            'create_signature',
                            array('pid' => $id,
                                  'uid' => $uid,
                                  'realname' => $realname,
                                  'email' => $email,
                                  'address' => $address,
                                  'city' => $city,
                                  'state' => $state,
                                  'zip' => $zip,
                                  'sendhow' => $sendhow,
                                  'extrafield' => $extrafield,
                                  'catid' => $catid,
                                  'comment' => $comment,
                                  'showname' => $showname,
                                  'country' => $country,
                                  'sendcomment' => $sendcomment));

        if ($tid != false) {
    //        echo ('id-' . $id . '<br>tid- ' . $tid . '<br>catid- ' . $catid);
            pnRedirect(pnModUrl('bkbPetition',
                                'user',
                                'display_thankyou',
                                array('pid' => $id,
                                      'sid' => $tid,
                                      'catid' => $catid)));
            return true;
        }


    code from "display_thankyou"

    Code

    list($pid,$sid,$catid) = pnVarCleanFromInput('pid','sid','catid');

        extract($args);

        $item = pnModAPIFunc('bkbPetition',
                             'user',
                             'get_petitions',
                             array('id' => $pid));


        $pnRender =& new pnRender('bkbPetition');

        $pnRender->caching=false;

        $pnRender->assign('petition', $item);
        $pnRender->assign('catid', $catid);

        return $pnRender->fetch('user_display_thankyou.tpl');


    The problem is that the variables $pid, $sid, and $catid in "display_thankyou" are not available to the fucntion, even though they are present when the function is called from the "add_signature" fucntion. The echo statement in "add_signature" just before "display_thankyou" confirms that the variables are set, just not being transferred to "display_thankyou".

    Thanks for any help.

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • pnVarCleanFromInput takes things submitted via form, not passed internally. You need this instead:

    [code]function display_thankyou($args)
    {
    extract($args);

    [...]
    }

    That will make the variables available in the function (alternatively use $args['pid'] to refer to the variables, but I prefer to use the extract function, to make
    $pid = $args['pid'];

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • extract($args) is there right after the pnVarCleanFromInput command. I did var_dump($args) right before extraction, and it says that $args is an empty array. I was getting the same results prior to adding pnVarCleanFromInput.

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • Also, the variables are shown in the URL whent he thank you page is displayed.

    Code

    http://localhost/index.php?module=bkbPetition&func=display_thankyou&pid=2&sid=35&catid=-1


    I just wish I could figure out why the function can't access them.

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • Using the GET method in forms is what makes the variables appear in the URL. Instead, use the POST method to keep them out of the URL.
  • ...additionally, if you list() the variables and strain them through pnVarCleanFromInput, there's no need to extract($args) ... the variables are already available as "themselves".

    Try a print_r($tid) right after you assign it...see what the API function is giving back...

    ...also, where you're echo'ing the vars after you've assigned $tid, you should be echo'ing $pid, rather than $id...I think...

    ...then in your redirect, 'pid' => $pid... but then again, you're assigning 'sid' the contents of $tid..which is everything...I'm not sure that's what you're meaning to do...maybe it is...
  • Alar,

    As you can see from the "add_signature" code above, I'm not using a form to transfer the variables to "display_thankyou" so I don't know how the GET method is being used.

    When I take out the extract($args) and only leave in the pnVarCleanFromInput then the variables are loaded, but when I try to use them, nothing happens.

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • Ok... one step at at a time... ;)

    That was my bad on the GET/POST comment. If you pass the vars in pnModURL, it's logical they will get passed in the URL. If you don't want that, then you have to pass them in ie, a pnModFunc()...

    So anyway, the vars load...good. When you say, "nothing happens" please explain what you mean...how are you using them?
  • I figured out what the problem was. I thought it would be something stupid and it was. I was trying to use a userapi function and forgot to load the userapi.

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • Cool...

    ...carry on...

    ;)
  • I just realised I completely misread the first post icon_rolleyes

    Anyway, not important now, thanks Alar ;)

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • ...no prob... It's the thought that counts. ;)

This list is based on users active over the last 60 minutes.