Zen Cart Logo
Forums / General Questions / Setting Order Comments field required, and making it drop-down?

Setting Order Comments field required, and making it drop-down?

Locked

Views: 2,402

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
5 Jan 2008, 7:40 PM
#1
davemehta avatar

davemehta

Zen Follower

Join Date:
Aug 2005
Posts:
130
Plugin Contributions:
0

Setting Order Comments field required, and making it drop-down?

Ok, so I want to have the customer choose who they found our website on the checkout procedure (on the first checkout page where they enter their shipping info) and require this to be completed.

Now I didn't know how to do this so I thought, I'll just edit the Comments box and call it "How did you find us". This worked good, but people still weren't typing in how they found us so I want to make this field required.

I also thought to change this to a drop-down with hard-coded choices for the user. I know I can edit the templates/tpl_checkout_shipping_default.php file and just draw out the drop-down and call it comments.

So my questions are:

  1. How do I make the comments fields required? So that if there is nothing entered, the page will be displayed again and an error note saying they must select how they found us.

  2. This does away with the comment box, per se... any other ideas on how I can do this and still keep the comments box for comments?

Thanks!

6 Jan 2008, 6:53 PM
#2
davemehta avatar

davemehta

Zen Follower

Join Date:
Aug 2005
Posts:
130
Plugin Contributions:
0

Re: Setting Order Comments field required, and making it drop-down?

Anyone have any ideas... I thought about this as well: What if I just added to the javascript to have it check that field and issue an error if it is "blank". What file (and where) do I have to edit to add to the javascript? It's not a perfect solution because sometimes javascript can be not installed or off in a client's computer but it's simpler I thought.

Please help, I gotta get this going asap!

7 Jan 2008, 8:35 PM
#3
davemehta avatar

davemehta

Zen Follower

Join Date:
Aug 2005
Posts:
130
Plugin Contributions:
0

Re: Setting Order Comments field required, and making it drop-down?

Didn't get any answers on this so I thought I would post my solution here for others who may need this in the future.

So first I edited the checkout_shipping.php and checkout_payment.php template files and I changed the comments box from a textarea to a select box thus giving me a drop-down box with the appropriate choices. It's still called comments so everything works the same in the backend.

Now, that solved me wanting a drop-down box but I still needed to make sure to validate that they chose an option from the drop-down. Here's how I solved that... I edited the file /includes/classes/payment.php and found the section of javascript that validates and added my validation code to it.

The entire solution works great! Please let me know if anyone would like me to post the code I used, I'd be happy to.

7 Jan 2008, 8:40 PM
#4
jammin320 avatar

jammin320

Zen Follower

Join Date:
Mar 2007
Location:
Seattle, WA
Posts:
158
Plugin Contributions:
0

Re: Setting Order Comments field required, and making it drop-down?

Well done. . . I don't currently have a need for that functionality, however, it looks like you did a slended job.

3 May 2008, 3:21 PM
#5
backspacer avatar

backspacer

New Zenner

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

Re: Setting Order Comments field required, and making it drop-down?

i would like to have the code please. maybe i can mod this for what i need.

21 May 2008, 3:10 AM
#6
backspacer avatar

backspacer

New Zenner

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

Re: Setting Order Comments field required, and making it drop-down?

dave, i just emailed you through the zencart forum system. I would like some help adding a required script to the checkout process for 4 different fields that i have added.

thanks,
jamie

23 Nov 2008, 5:57 PM
#7
davemehta avatar

davemehta

Zen Follower

Join Date:
Aug 2005
Posts:
130
Plugin Contributions:
0

Re: Setting Order Comments field required, and making it drop-down?

I would like to see the code you used to change the comments from text to drop down. If you could email or post that would be appreciated.

Thanks!
KMF

KMF,

I don't have the code anymore (couldn't find it) but if you read my post above it's all laid out. Basically just change the text area to a dropdown. So that would be:

<textarea name="comments"></textarea>

... change to ...

<select name="comments">
   <option value="choice1">Choice 1</option>
   <option value="choice2">Choice 2</option>
   <option value="choice3">Choice 3</option>
</select>

And what that will do is just change the type of input field but the name is the same so it doesn't change anything about the way Zen processes it.

The only other step was validation that something was selected, so as I stated in my last post in this thread "I edited the file /includes/classes/payment.php and found the section of javascript that validates and added my validation code to it".

Hope that helps!

24 Nov 2008, 5:31 PM
#8
talk2kmf avatar

talk2kmf

New Zenner

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

Re: Setting Order Comments field required, and making it drop-down?

Thanks, however I believe the comment box is generated by:

<fieldset class="shipping" id="comments">
<legend><?php echo TABLE_HEADING_COMMENTS; ?></legend>
<?php echo [B]zen_draw_textarea_field[/B]('comments', '45', '3'); ?>
</fieldset>

in MYTEMPLATE/templates/tpl_checkout_shipping_default.php

Also the <select> HTML code requires a <form> set but I don't believe that works with the PHP page here.

It would make sense to use the zen_draw_pull_down function instead but I can't find any good source of how to code it properly.

Any help would be appreciated. Thanks!

KMF

24 Nov 2008, 5:37 PM
#9
davemehta avatar

davemehta

Zen Follower

Join Date:
Aug 2005
Posts:
130
Plugin Contributions:
0

Re: Setting Order Comments field required, and making it drop-down?

Basically I just hard-coded the drop down in that template file so I changed the default code to:

<fieldset class="shipping" id="comments">
<legend><?php echo TABLE_HEADING_COMMENTS; ?></legend>
<select name="comments">
  <option value="option1">Option 1</option>
  <option value="option2">Option 2</option>
  <option value="option3">Option 3</option>
</select>
</fieldset>

And since that is using the same input name "comments" it will process properly. You don't have to mess with the zen_draw_pull_down function because it's overkill here.