Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Making a Custom Field Required


Guest

Recommended Posts

Hey all :D So far I've been able to customize and modify everything by just searching on the boards here for what I need (thanks to all who post help, contribs, and tricks!). This one, however, is stumping me and though I've tried several searches for it, I can find no answer with enough detail.

 

I can usually figure out what to code, where to place things in the php files. I'm not a php or SQL expert, but I follow directions well at least :thumbsup:

 

I have added a custom field to my customers database table and added it to the create_account.php using much of the great tutorial here:

 

http://www.oscommerce.com/forums/index.php?showtopic=93551&hl=

 

Everything is working perfectly. But, I need this field to be required. I know it involves adding a check through the javascript and some coding on few pages, but it is more involved than what I've done before and I'm afraid I'm going to majorly screw something on a store I've worked on for quite awhile now. :(

 

I need it to be required and also show as required on the edit account php (it's already there, I just need it to show as required). Is there some kind soul out there, who could take the time to show me step by step how to make a custom field required? Or someone who could point me to the proper place for these instructions? I'm skeeeeeered. :blush:

Link to comment
Share on other sites

Bumpity bump :blush: You know, other posts I've found here on this topic have pretty much been avoided... what is it with this? Is there no way to do this? Why do people see this topic and just skip it? :blink: Pretty please with sugar on top? :D

Link to comment
Share on other sites

Anyone? Anyone? Bueller? (and now I'm even showing my age.. please don't make me have to resort to posting any more 1980s movie quotes.. it's a little embarrassing!)

Link to comment
Share on other sites

open your includes\form_check.js.php file near the end there is a function called check_form() It checks the various fields of the form its where you can add your extra field for validation. Copy one of the other lines and modify it like this:

 

  check_input("mycustomfield", <?php echo ENTRY_CUSTOM_MIN_LENGTH; ?>, "<?php echo ENTRY_CUSTOM_ERROR; ?>");

 

Then in your catalog\create_account.php see how other fields like the name is done so you have something like this:

              <tr>
               <td class="main"><?php echo ENTRY_FIRST_NAME; ?></td>
               <td class="main"><?php echo tep_draw_input_field('firstname') . ' ' . (tep_not_null(ENTRY_FIRST_NAME_TEXT) ? '<span class="inputRequirement">' . ENTRY_FIRST_NAME_TEXT . '</span>': ''); ?></td>
             </tr>

 

so you could have another entry for your field

              <tr>
               <td class="main"><?php echo ENTRY_CUSTOM; ?></td>
               <td class="main"><?php echo tep_draw_input_field('firstname') . ' ' . (tep_not_null(ENTRY_CUSTOM_TEXT) ? '<span class="inputRequirement">' . ENTRY_CUSTOM_TEXT . '</span>': ''); ?></td>
             </tr>

Change your language file catalog\includes\languages\<language>\create_account.php (if its specific to create account form otherwise if its a global entry you could included in (catalog\includes\languages\<language>.php file) to include your custom definitions text.

Link to comment
Share on other sites

Mark Samios you are the greatest. I have been reading and absorbing posts for just a short time now, but you stand out as offering accurate, workable, and very clear instructions on solving problems. Thank you! :thumbsup:

Link to comment
Share on other sites

I was working on the same problem the other day, i managed to work out what was to be done, but the javascript alert was not picking up on the new field i had put in.

 

My new field is a text area, does that make any difference when the form check function is checking?

 

I know the field works fine as the data gets put in the DB, and the php error checking works a treat.

 

Thanx

Link to comment
Share on other sites

  • 2 weeks later...

I know this is a late reply, but I was called away to work on something else for awhile.

 

Thank you, enigma1, for your reply! I was beginning to lose hope ;)

 

I have tried this - but it doesn't seem to be working. It looks as though the form_check file is looking for a minimum length in order to return the error. I know I can set minimum values in the Admin area, but there is not one there for my custom field.

 

Any idea how to add it to my admin area? I'm thinking if I could set that, the script would know to return the error to the customer rather than processing the account anyway, which is what it is doing now.

 

Thanks for your input on this :thumbsup:

Link to comment
Share on other sites

My new field is a text area, does that make any difference when the form check function is checking?

 

From the jscript code I see I assume the check_input function would validate that if the field is not hidden. The check this function does is against empty fields and the size passed as an argument. Also make sure you have a config field in the dbase under the configuration table. Then check for the field in form_check.js.php (See for example how ACCOUNT_GENDER is set)

 

I have tried this - but it doesn't seem to be working. It looks as though the form_check file is looking for a minimum length in order to return the error. I know I can set minimum values in the Admin area, but there is not one there for my custom field.

 

post the code you added. I would expect the above in order for a new custom field to work.

Link to comment
Share on other sites

Here is a snippet from my includes/form_check.js.php file (my new field is the "url" field):

  check_input("email_address", <?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>, "<?php echo ENTRY_EMAIL_ADDRESS_ERROR; ?>");

  check_input("url", <?php echo ENTRY_CUSTOMER_URL_MIN_LENGTH; ?>, "<?php echo ENTRY_CUSTOMER_URL_ERROR; ?>");

  check_input("street_address", <?php echo ENTRY_STREET_ADDRESS_MIN_LENGTH; ?>, "<?php echo ENTRY_STREET_ADDRESS_ERROR; ?>");

  check_input("postcode", <?php echo ENTRY_POSTCODE_MIN_LENGTH; ?>, "<?php echo ENTRY_POST_CODE_ERROR; ?>");

  check_input("city", <?php echo ENTRY_CITY_MIN_LENGTH; ?>, "<?php echo ENTRY_CITY_ERROR; ?>");

 

In my catalog/create_account.php:

 

<!-- this is the added URL field code //-->

 

              <table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">

          <tr class="infoBoxContents">

            <td><table border="0" cellspacing="2" cellpadding="2">

              <tr>

                <td class="main"><?php echo ENTRY_CUSTOMER_URL; ?></td>

                <td class="main"><?php echo tep_draw_input_field('url') . ' ' . (tep_not_null(ENTRY_CUSTOMER_URL_TEXT) ? '<span class="inputRequirement">' . ENTRY_CUSTOMER_URL_TEXT . '</span>': ''); ?></td>

              </tr>

              </table></td></tr>

<!-- end of URL code //-->

 

In my includes/languages/english.php file:

 

define('ENTRY_CUSTOMER_URL','Website URL:');

define('ENTRY_CUSTOMER_URL_TEXT', '* <br>(main domain URL where 3DWC content might be displayed)');

define('ENTRY_CUSTOMER_URL_ERROR', 'You must provide a domain name URL where purchased images may be displayed.');

 

Thank you!!!

Link to comment
Share on other sites

you need to add it to your sql config table too and you need to add the validation in the php section of create_account.php, For the later you should have something like this in your create_account.php:

 

    if (strlen($street_address) < ENTRY_CUSTOMER_URL_MIN_LENGTH) {
     $error = true;

     $messageStack->add('create_account', ENTRY_CUSTOMER_URL_ERROR);
   }

then you create a config entry use phpmyadmin or an sql file to store it.

insert into configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) values ('333', 'Customer URL Address', 'ENTRY_CUSTOMER_URL_MIN_LENGTH', '5', 'Minimum length of customer url', '2', '5', NULL, NULL, NULL, NULL);

watch the 333 above should be a unique id in the configuration table. Then you can control the parameters from your admin cpanel

Link to comment
Share on other sites

Fantastic! I've got it working now! :D

 

The only thing I had to change from your post above was the sql code. It errored and said that date_added could not be NULL. So I changed it to this:

 

insert into configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) values ('333', 'Customer URL Address', 'ENTRY_CUSTOMER_URL_MIN_LENGTH', '5', 'Minimum length of customer url', '2', '5', NULL, DEFAULT, NULL, NULL);

 

And it works like a charm.. I can even control it in the admin area. Awesome! You totally rock!! :D

Link to comment
Share on other sites

  • 3 weeks later...

Mark Samios:

 

I'm attempting to adapt your instructions to some custom product attributes I have created using a contribution ("Product Attributes - Option Types Feature") (which, btw, works great for adding custom fields as additional product options)...

 

Anyway, since my custom fields are NOT related to customer information or creating accounts, I'm wondering if your instructions can be adapted to make my custom-product-option-fields required (by the users, of course) in the product attributes? To be clear, this would require users to fill in all the "option" blanks of a particular product BEFORE the user can Add To Cart.

 

FYI: I've tried "comparing" codes from create_account.php and product_info.php, but -- as you might have guessed -- it all looks like greek to me (not to mention the fact that I might not even be looking at the right files). :blush:

 

FYI (again): I followed your instructions and added a field to the database in the configuration table -- 'course I didn't know which configuration "group" I should be using (or if it matters), as there does not appear to be one for my specific needs. I also altered the includes/langugages/english.php file to include the info now in the DB. I also added the information from your instructions for the check_form.js.php.

 

I have no idea where to put a red asterisk (*) to denote required field, nor where else I should include code similar to what would go in the create_account.php file (but for the product attributes' custom fields, of course). :x

 

Any thoughts you might have are appreciated BEYOND EXPRESSION!!!!

 

Then again, maybe this just can't be done without taking a crow-bar and opening up a can of worms!!! :blink:

 

Thanks in advance,

 

--OSCnewbie (Pam)

Link to comment
Share on other sites

I have found a contribution to fit my needs and appears to answer the questions I've been asking in this thread. I'm posting it here so that if someone else sees this and has similar issues, this will help them, too.

 

Here is the contribution needed for required product attributes:

 

http://www.oscommerce.com/community/contributions,2628

 

There are a couple of glitches, one of which is explained here:

 

http://www.oscommerce.com/forums/index.php?showtopic=149663

or

http://www.oscommerce.com/forums/index.php?sho...st=0&p=663422

 

Good luck to everyone!

 

-OSCnewbie

Link to comment
Share on other sites

  • 2 months later...

many tnx to enigma and other peoples...

 

Now when i edit a customers (customers.php) the field apperas at normal how i make a * required like the first name and the others?..

 

For the createaccount.php is simple but for it heeheh

 

Many TNX

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...