Forums / Templates, Stylesheets, Page Layout / Adding Field to Checkout

Adding Field to Checkout

Views: 31,098

Results 41 to 60 of 84
20 May 2008, 4:20 AM
#41
backspacer avatar

backspacer

New Zenner

Join Date:
May 2008
Posts:
9
Plugin Contributions:
0

Adding Field to Checkout

OK, I finally got what I needed by modifying another module. I used the order delivery date mod and basically duplicated it four times and changed the text to what I need. I works perfect in the front end, back end, mysql db, emails, basically everywhere. The only problem I have or I should say, the only other thing I need help is to make the four fields I added to be required. They are on the checkout_shipping section of the checkout. A simple javascript validation would be oK, but I just can't figure it out. can someone help me? my test site is at https://www.meandmomrentals.com/cart if you want to register and do a sample checkout to see the page.

5 Jun 2008, 2:59 PM
#42
gabstero avatar

gabstero

Zen Follower

Join Date:
Nov 2007
Posts:
342
Plugin Contributions:
0

Re: Adding Field to Checkout

Hi Gang -

Before I start cutting an pasting code, is this mod adding a field to the checkout page that will be added to the totals?

Also - will it work with Zen Cart v1.3.7.1?

Thanks!
Gabstero

9 Feb 2009, 3:07 PM
#43
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

This Thread has been extremely helpful, I have found a lot of threads asking the same questions but all have been abandoned or found work a rounds.

Anyway, I have followed through the instructions and got it to work as it should, I do have a couple of questions though.

  1. The new fields created, are they secure from sql injection and the like ?

  2. How can I make some of the fields required ?

Thanks in advance :D

9 Feb 2009, 3:24 PM
#44
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding Field to Checkout

1 - depends on how you handle your own data. You need to ensure that it is handled in the same way as all other data being passed. So if it is added to an array, and tehn passed to a zen_db_perform() function this handles the injection checking. If you are creating the insert, then you need to ensure you use zen_db_prepare_input() or similar, however, this function can only be RUN ONCE one your data, oterhwise you will create more problems than you solve!

2 - Making fields required is handled by the checkout page header_php.php file. If you are submitted the shipping page, it would be within includes/modules/pages/checkout_shipping/header_php.php. Chek that the data is set correctly, and if not, raise the error. You'll see similar examples within this file.

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

9 Feb 2009, 4:02 PM
#45
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

Absolute:

1 - depends on how you handle your own data. You need to ensure that it is handled in the same way as all other data being passed. So if it is added to an array, and tehn passed to a zen_db_perform() function this handles the injection checking. If you are creating the insert, then you need to ensure you use zen_db_prepare_input() or similar, however, this function can only be RUN ONCE one your data, oterhwise you will create more problems than you solve!

2 - Making fields required is handled by the checkout page header_php.php file. If you are submitted the shipping page, it would be within includes/modules/pages/checkout_shipping/header_php.php. Chek that the data is set correctly, and if not, raise the error. You'll see similar examples within this file.

Absolute

Thanks for the prompt reply.

Im using the exact example given in the 2nd post in this thread, just repeating the process for the amount of feilds I need (changing there names of course)

so in includes/modules/pages/checkout_shipping/header_php.php

this line

if (zen_not_null($_POST['frequent_code'])) {
$_SESSION['frequent_code'] = zen_db_prepare_input($_POST['frequent_code']);
}
$frequent_code = $_SESSION['frequent_code'];

Im assuming takes care of it :smile:

Once again, thanks for the help and prompt reply :D

9 Feb 2009, 4:11 PM
#46
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding Field to Checkout

That will handle SQL injection for you as it includes the zen_db_prepare_input() function.

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

9 Feb 2009, 5:16 PM
#47
tinadad avatar

tinadad

New Zenner

Join Date:
Apr 2008
Posts:
39
Plugin Contributions:
0

Re: Adding Field to Checkout

Thanks That is what I needed for my membership project

10 Feb 2009, 6:40 PM
#48
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

Ive been wracking my brain for a few hours now on how to make a radio button group

I found

function zen_draw_radio_field($name, $value = '', $checked = false, $parameters = '') {
    return zen_draw_selection_field($name, 'radio', $value, $checked, $parameters);
  }

in includes/functions/html_output.php and I can get it to show a button on the page if i declair $name, $value, but i have no idea what $parameters should be.

Obviously I have more than one set of options and values so im at a loss on how to get my options and values output onto the page.

Any help or pointers to some example code is much apreciated :smile:

Thanks in advance :D

10 Feb 2009, 6:44 PM
#49
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Adding Field to Checkout

eddyboy:

I found

function zen_draw_radio_field($name, $value = '', $checked = false, $parameters = '') {
return zen_draw_selection_field($name, 'radio', $value, $checked, $parameters);
}

> 
> in includes/functions/html_output.php and I can get it to show a button on the page if i declair $name, $value, but i have no idea what  $parameters should be.
> 
> Obviously I have more than one set of options and values so im at a loss on how to get my options and values output onto the page.Parameters is a catch-all for anything else you need e.g. 'class="myRadioButton"'. You don't have to put anything in there if you don't need anything.

You would use this function once of each option/value combination, grouping the options by giving them the same name, with each value for that option having its own unique value.

You'll probably want to sprinkle lightly with LABEL tags too.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

10 Feb 2009, 7:14 PM
#50
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

kuroi:

Parameters is a catch-all for anything else you need e.g. 'class="myRadioButton"'. You don't have to put anything in there if you don't need anything.

You would use this function once of each option/value combination, grouping the options by giving them the same name, with each value for that option having its own unique value.

You'll probably want to sprinkle lightly with LABEL tags too.

Wow, again.. thanks or the fast reply..

Works great :D

11 Feb 2009, 4:32 PM
#51
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

That time to bug you for help again :dontgetit

Ive tried and got no where with trying to make a feild required :frusty:

I am also struggling with a seperate javascript fix :frusty:

So once again, any help or pointers on making a feild required would be very much appreciated. :smile:

Im sure a donation will be made, for the help in the forums and for the zencart system when my site is up and running :D
I have made a fair few mods as well that I'd like to share with others, once the dust has settled.

11 Feb 2009, 4:45 PM
#52
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding Field to Checkout

Ok, from the top!

The way you add new fields has been shown earlier in this thread.

To make them required, edit the header_php.php file you are currently working with - there should only be one. It's the one where you have $_SESSION['xxxx'] = $xxxx

If there is a variable set somewhere in this page called $error, which is either true or false, you need to follow the same protocol.

If not, then you can use this:

  if (!zen_not_null($_POST['my_variable_name'])) {  //perform ALL checks on relevancy here
    $messageStack->add_session($_GET['main_page'], TEXT_ERROR_VARIABLE_MISSING, 'error');
    zen_redirect(zen_href_link($_GET['main_page']));
  }

It's not the prettiest way of doing it, and if the customer has entered an entire page of data, and then comes across this type of error they will hate you, as none of their data will be re-populated, but as I don't know where you are adding the details, or what other modules you have installed, it is the only fail-safe way of doing it I can think of.

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

11 Feb 2009, 5:15 PM
#53
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

Absolute:

If not, then you can use this:

if (!zen_not_null($_POST['my_variable_name'])) { //perform ALL checks on relevancy here
$messageStack->add_session($_GET['main_page'], TEXT_ERROR_VARIABLE_MISSING, 'error');
zen_redirect(zen_href_link($_GET['main_page']));
}

> 
> Absolute

Thanks for the speedy reply.

I have been editing the checkout_shipping/header_php.php page as i have put the new form on the  index.php?main_page=checkout_shipping page. And I have gone through the code a few times but cant find any examples to copy.


Anyway, I put in the new code so it reads like this
 ```php
if (zen_not_null($_POST['address'])) {
$_SESSION['address'] = zen_db_prepare_input($_POST['address']);
}
$address = $_SESSION['address'];

if (!zen_not_null($_POST['address'])) {  //perform ALL checks on relevancy here
    $messageStack->add_session($_GET['main_page'], TEXT_ERROR_VARIABLE_MISSING, 'error');
    zen_redirect(zen_href_link($_GET['main_page']));
  }

but i get a redirect loop error-

Redirect Loop
Redirection limit for this URL exceeded. Unable to load the requested page.

Im asuming this is because when the page first loads the variables have no value :wacko:

Again, thanks for your patiance and help.. I am coming to the end of what hasbeen a very long project, and my brain is starting to fail me :frusty: All and any help is much appreciated:smile:

11 Feb 2009, 5:53 PM
#54
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

I think i have a work around.

If I change a form feild to include some defult text

<?php echo zen_draw_textarea_field('address', '45', '3','required feild') ?>

and tweak your last bit of code to

if (($_POST['address'] =="required feild")) {  //perform ALL checks on relevancy here
    $messageStack->add_session($_GET['main_page'], TEXT_ERROR_VARIABLE_MISSING, 'error');
    zen_redirect(zen_href_link($_GET['main_page']));
  }

It means unless they change the text for something they enter it will throw an error.

I think my brain has something left inside it after all :clap:

11 Feb 2009, 5:55 PM
#55
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding Field to Checkout

Firstly, move that code so it comes BEFORE the if (zen_not_null($_POST['address'])) { line.

And then change it so it reads:

if (isset($_POST['address']) && !zen_not_null($_POST['address'])) {  //perform ALL checks on relevancy here
    $messageStack->add_session($_GET['main_page'], TEXT_ERROR_VARIABLE_MISSING, 'error');
    zen_redirect(zen_href_link($_GET['main_page']));
  }

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

11 Feb 2009, 6:13 PM
#56
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

Absolute:

Firstly, move that code so it comes BEFORE the if (zen_not_null($_POST['address'])) { line.

And then change it so it reads:

if (isset($_POST['address']) && !zen_not_null($_POST['address'])) { //perform ALL checks on relevancy here
$messageStack->add_session($_GET['main_page'], TEXT_ERROR_VARIABLE_MISSING, 'error');
zen_redirect(zen_href_link($_GET['main_page']));
}

> 
> Absolute


Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou 
:clap: 

My way did seem to work, but I dont trust my coding on 0 sleep.. 
i have used the new code and it works perfectly
11 Feb 2009, 10:02 PM
#57
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding Field to Checkout

Glad I could help!

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

4 Mar 2009, 4:23 PM
#58
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

I'm at the point of testing my site online now and I have set up paypal website payments pro and express checkout. I have made 2 successfull orders, 1 with a credit card and one through the express checkout. However I have just noticed that the details for the new feilds that I have made have not made it through to the database when using the express checkout, but the info from the new feilds is there for the order that I payed with using a credit card.

Just wondering if anyone has come across this before or can think why it would be an issue ?

Thanks in advance

5 Mar 2009, 1:33 PM
#59
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

Ok so when you checkout with expresscart this page is skiped and you are returned to the next page in the process. Trouble is i need those feilds to be filled out. :frusty:

I guess I need to move the feilds or find out how to change the redirect url after using express checkout :(

5 Mar 2009, 1:42 PM
#60
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding Field to Checkout

Edit your PayPal Express Checkout module settings and turn off the setting that auto-selects cheapest shipping.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.