Please help with coding prob.

Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Thu, 2006-10-05 17:16

Can anyone please help point me in the right direction on CheckoutMoneyBookers Module I am working on?

QUESTION 1
I have a challenge in that the module has to be able to post to the MoneyBookers site and send an email to the gallery owner when the user clicks "submit". I take it I can't have two post methods on the same form. Does anyone have any ideas on how to post to two separate URLs from one form ... if possible at all?

QUESTION 2
Also, I have a form where users input data (say their first name).

I want to take that information, store it in a variable and display it in the next view but struggling.

I can activate the next view etc but can't pass the data from View 1 to View 2.

Example:
Original Form
<table cellspacing="5">
<tr>
<td align="right"><strong>First Name:</strong></td>
<td><input type="text" name="{g->formVar var="form[custFirstName]"}" value="{if isset($form.custFirstName)}{$form.custFirstName}{/if}"</td>
</tr>
</table>

goes to *.inc file and calls next tpl file.

New View
<table cellspacing="5">
<tr>
<td align="right"><strong>First Name:</strong></td>
<td>{$custFirstName}</td>
</tr>
</table>

I can't seem to load my variable with the data from the first form.

I am new to this and must confess I don't know much of php etc. I know a reasonable amount of VB but sruggling with what I would consider simple tasks on this.

Thanks for your help.

.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Fri, 2006-10-06 10:35

I found some clues on the HTML Goodies site that I will try to implement.
.
Gallery Version: 2.1.1
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Wed, 2006-10-11 19:22

The clues didn't work out as I am missing something out.

The way it is supposed to work is this.

Details.tpl is loaded. It is a form controlled by Email.inc to get user details (no problems with this)
User clicks the submit button and email.inc takes over where I load an array ($reviewform) with the form details with the next view being checkoutmbookers.Review.

As far as I know, Review.inc is called and then Review.tpl.

I need the values entered in Details. tpl to be passed to Review.tpl.

I have attached truncated files. Can anyone please give an indication of how to get this done?

Thanks.

.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

AttachmentSize
Review.tpl_.txt1.34 KB
Review.inc_.txt1.79 KB
Email.inc_.txt2.98 KB
Details.tpl_.txt1.57 KB
 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2006-10-13 19:40

maybe make EmailController use 'delegate' instead of 'redirect' to specify Review. a delegate is processed in the same request, so you can get the form data.

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Fri, 2006-10-13 22:03

Awesome! Thanks.

I had spent ages on PHP forums and tutorials trying to sort this out. I learnt a lot of things but not how to solve this...anyway, I guess the knowledge would come in useful at some point.

Thanks again.
.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Sat, 2006-10-14 19:37

@ Mindless / anyone else

The delegate tip worked like a charm and I have all the form info passed across like I wanted. However I have another variable scope issue.

I need to get some info from the Admin setup of my module and from the checkout module. I have put the code to do this in EmailController class in Email.inc and created hidden fields in Review.tpl but the info is not getting through. I know this has to do with variable scope and wondering if the code I have in email.inc should be implemeted in Review.inc.

Truncated files attached

Thanks for your time.

.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

AttachmentSize
Review.tpl_.txt1.27 KB
Email.inc_.txt2.11 KB
Review.tpl_.txt1.27 KB
 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sun, 2006-10-15 15:32

you didn't use g->formVar for the name attribute of your hidden inputs.

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Sun, 2006-10-15 18:27

No I didn't. I want to post the values to the Money Bookers site and the API expects the value to have certain names. As I understand it, using g->formVar will add a form prefix to the name.

The challenge is to post the $csymbol variable for instance to the MBookers site.

Thanks

.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sun, 2006-10-15 23:01

oh, just saw other g->formVar in the same file, didn't notice this posts elsewhere.. i'd remove the g->formVar inputs and hiddenFormVars.. that external site won't need those.
then the question is where did you set {$csymbol} in your template data? don't see it in your attachments. (there's 2 Review.tpl's and no Review.inc)

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Tue, 2006-10-17 15:02

My error

I will clean up the files as they are a bit messy for testing and attach them. Thanks.
.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Sat, 2006-10-21 16:58

I think I have the structure in place although it still doesn't work. I have attached the whole module so feel free to look at the code and make suggestions

The problem lies, I think, in email.inc, review.inc or/and review.tpl

The flow is supposed to be

1) User clicks on CheckoutMB button in Checkout Module
2) CheckoutMB module is loaded. Controller is Email.inc
3) Email.inc gets Details.tpl which is a form where user fills in address etc. As Mbookers only takes total amount without itemised list, vendor has to be sent an email similar to CheckoutEmail.
4) When User clicks "submit" on this form, templated email is supposed to be sent by email.inc and Review.tpl loaded. This holds the data filled in on the Details form and hidden values for MBookers.
5) When user confirms details by clicking submit, the hidden values are posted to MBookers.

Steps 1 - 3 work fine but after that is where it goes south.

Thanks
.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

AttachmentSize
Checkoutmbookers 0.0.1.1.zip37.07 KB
 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Thu, 2006-10-26 06:59

Any tips anyone?
.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2006-10-26 19:07

anything POSTed with the action==email request will go into $form for Email controller, which then delegates to Details view --> Details.tpl --> browser. the next POST goes to Email controller again now with action==send, right? you need all the data in this POST, so make sure all data in $form (when Details.tpl is rendered) that you'll need for action==send is added in the <form> (hidden inputs as needed) is that the problem, some data missing in Email controller?

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Thu, 2006-10-26 20:03

Hi Mindless

The first action==email is from paymentbutton.tpl (which is called by the main checkout module) and goes into Email controller which then delegates to Details.inc --> Details.tpl --> browser as you noted. This works ok.

The user then fills in the details form with their name etc and post this again to Email controller (action==email) should then delegate to Review.inc --> Review.tpl --> browser. This does not work. Before delegating to Review.inc, a templated email should be sent to the user and the owner and variables loaded from the module admin and from the checkout module should be hidden in Review.tpl ready for posting to the external site together with the form variables from Details.tpl.

Are you suggesting that these other variables should be hidden on Details.tpl and then passed to Review?

I tried that but when I tested the fields as text instead of hidden values, they came out blank.

I suppose the specific query is whether the way I have tried to load the variables in the "/* Get parameters from the checkout plugin */" & "/* Get parameters from this plugins admin setup */" etc in Email.inc are done correctly.

Thanks for your time.

.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2006-10-26 21:04

that all sounds fine.. guess it needs debugging. i can't really guess what's wrong from it "goes south".. where exactly does something have missing or wrong data for some variables?

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Thu, 2006-10-26 21:48

"it goes south" is UK colloqiual for it goes downhill (south being down on a map.. at least I think that's the origin) lol.

On the specifics, I think the way I have tried to load the variables is the problem.

1) For instance after the send action @ details.tpl, I tried this code. $total is a variable from the Checkout plugin that holds the total value of the transaction that I need to hide on review.tpl to pass to the external site. Is the code correct and can I just have {$total} as a hidden input in review.tpl after the delegation?

		/* Get parameters from the checkout plugin */
		list ($ret, $total) = GalleryCoreApi::getPluginParameter('module', 'checkout', 'total');
		if ($ret) {
		    return array($ret->wrap(__FILE__, __LINE__), null);
		}

2) Also I have the following code for the gallery owners' registered email on money bookers which is entered in the theme admin and stored in a variable for instance. Same query applies.

		/* Get parameters from this plugins admin setup */
		list ($ret, $mbookersname) = GalleryCoreApi::getPluginParameter('module', 'checkoutmbookers', 'mbookersname');
		if ($ret) {
			return array($ret->wrap(__FILE__, __LINE__), null);
		}

3) I also need to pass the $email array across. Here is the code where it is specified but in review.tpl, it doesn't show up.

		/* Begin constructing the data to pass to the email templates */
		$email = array( 'transactionId' => unserialize($session->get('checkoutmbookers.transactionId')),
	    		        'items' => unserialize($session->get('checkoutmbookers.items')),
	    		        'product' => unserialize($session->get('checkoutmbookers.product')),
	    		        'price' => unserialize($session->get('checkoutmbookers.price')),
	    		        'paper' => unserialize($session->get('checkoutmbookers.paper')),
	    		        'postage' => $postage,
	    		        'csymbol' => $csymbol,
	    		        'total' => unserialize($session->get('checkoutmbookers.total')),
	    		        'custFirstName' => $form['custFirstName'],
	    		        'custLastName' => $form['custLastName'],
	    		        'custEmail' => $form['custEmail'],
	    		        'custRecipientName' => $form['custRecipientName'],
	    		        'custAddress1' => $form['custAddress1'],
	    		        'custZip' => $form['custZip'],
	    		        'custCountry' => $form['custCountry'],
	    		        'custComments' => $form['custComments'],
			       );

.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2006-10-26 23:51

data source:
html page -> input with {g->formVar var="form[something]"} -> included in $form given to controller
module configuration stored in database -> read with GalleryCoreApi::getPluginParameter
data put in session earlier -> get with $session->get

consider what data you're working with and use the right source.. if you have checkout data related to this particular transaction, it will NOT be in the database as a checkout configuration parameter.

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Fri, 2006-10-27 16:29

Thanks for that.

1) html page -> input with {g->formVar var="form[something]"} -> included in $form given to controller.
This I have in Details.tpl for user input and can delegate to Review.tpl for posting to the external site. Works ok and now well understood.

2) module configuration stored in database -> read with GalleryCoreApi::getPluginParameter
This is how the configuration is stored in Admin Controller

	    $ret = GalleryCoreApi::setPluginParameter('module', 'checkoutmbookers', 'mbookersname', $form['mbookersname']);
	    if ($ret) {
		return array($ret->wrap(__FILE__, __LINE__), null);
	    }

and this is how I try to retrive it in Email Controller

		/* Get parameters from this plugins admin setup */
		list ($ret, $mbookersname) = GalleryCoreApi::getPluginParameter('module', 'checkoutmbookers', 'mbookersname');
		if ($ret) {
			return array($ret->wrap(__FILE__, __LINE__), null);
		}

Is this syntax correct?

3) consider what data you're working with and use the right source.. if you have checkout data related to this particular transaction, it will NOT be in the database as a checkout configuration parameter
Makes sense. I assume that instead of the code below I tried to use for the transaction total value for the checkout module...

		list ($ret, $total) = GalleryCoreApi::getPluginParameter('module', 'checkout', 'total');
		if ($ret) {
		    return array($ret->wrap(__FILE__, __LINE__), null);
		}

... I should be trying something like $total = unserialize($session->get('checkout.total'))

4) I have used the code below to try to retrieve stuff such as the currency symbol stored in the checkout module admin

		list ($ret, $csymbol) = GalleryCoreApi::getPluginParameter('module', 'checkout', 'csymbol');
		if ($ret) {
		    return array($ret->wrap(__FILE__, __LINE__), null);
		}

5) Finally, assuming the syntax in Point 4 for instance is correct, is it the case that the $csymbol variable will be available when I delegate to the review.tpl view? I was reading In a PHP book I bought to learn, that a variable declared in a function (my $csymbol in function handleRequest in this instance) will only be available in that function. Could that be my problem here since when review.inc is loaded, another function is called that actually loads review.tpl?

I am sure I am close to the final line but lack of specific knowledge is thwarting me so thanks for your patience.
.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Fri, 2006-10-27 18:54

@ Mindless

I have managed to solve the problems thanks. The point on variable scope I touched on in Point 5 was the key. I realised that initialising the variables in EmailController was a problem as the Review view was being called from another function. As I had been successful in passing the user inputs in the Details.tpl view to the Review.tpl view (Point 1), I thought the answer lay in initialising the variables in Details.inc and hiding them to be passed along with the user inputs and it works.

The only outstanding thing is that the return url which I have set as 'g->url arg1="view=checkoutmbookers.PaymentComplete" ' & the cancel url which goes in as 'g->url arg1="view=checkoutmbookers.PaymentCancelled" ' to be posted to the external site is coming back as a relative url. I found the tpl reference about forcefullurl=true but not sure of the syntax. Can you please give me a pointer?

Thanks
.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2006-10-27 19:31

{g->url arg1="view=.." forceFullUrl=true}
or in php code: $urlGenerator->generateUrl(array('view' => '..'), array('forceFullUrl' => true));

 
Dayo

Joined: 2005-11-04
Posts: 1555
Posted: Fri, 2006-10-27 19:52

Thanks

I found I needed to declare "$session =& $gallery->getSession();" before using the get session ... do I need to do something similar for the urlGenerator?

*********************EDIT****************************
Nevermind, I found it "$urlGenerator =& $gallery->getUrlGenerator();"
Thanks again ...works like a dream.

.
Gallery Version: 2.1.2
Gallery Theme: PGTheme 1.1.0 (RC01)
Web Site: http://dakanji.com