close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Web development tutorial

Add a form field to your existing web form

Tutorial created by Team WebAssist

Categories: eCart


Have you ever created a form for a website, and as close to a masterpiece as it was, you just couldn't shake that feeling that it was missing something… that spark to make it perfect? Well you WERE missing something; an extra form field on your form! Quantity is directly responsible for quality, right?

Well today we're going to show you how to take that plain Jane, unfinished, and quite frankly unprofessional form, and add one more form field to it into the jet-setting beauty queen about town of a web form we've all come to expect from you.

For this tutorial we are using an eCart form configured to use credit card payments. You in no way need to use eCart for this tutorial, but we will be mentioning specific fields and some cool, advanced topics later on, so if you are following along with different forms, or using an eCart site configured with a different payment gateway setup, take note of the changes.

arrow downWhat you need to start

  1. A web form that needs an extra field
  2. Dreamweaver CS3 or later


  1. A working eCart site with credit card payments
  2. eCart installed and activated in Dreamweaver

arrow downAdd form field

In this step, we're going to add a Company Name field under the customer First and Last name fields. Again, since forms are so subjective, and you could be using a completely different form than we are, or you could be using even a different eCart configuration than we are, these fields may be totally different. Keep that in mind when we mention specific fields.

  1. Open your checkout.php page
  2. In Design view, click on the Email Address row under billing info
  3. Click Insert > Table Objects > Insert Row Above
  4. Click in the second column of the newly created row
    This will be directly above the other form fields
  5. Click Insert > Form > Text Field
  6. Enter company as the id
  7. Enter Company as the Label
  8. Verify the Style is set to Attach label using "for" attribute
  9. Click OK
  10. Highlight the entire label
  11. Click on the label
  12. Without letting go of the mouse button, drag the label into the column with the field labels
  13. In Code view, find the newly inserted text field
  14. Enter value="" at the end of the input tag
    <input type="text" name="company" id="company" value="">

  15. Save all the things!

arrow downAdd session variable

Next on the chopping block%u2026 or the opposite of a chopping block really since we're adding instead of taking away%u2026 how about; "the nega-chopping block"?

Next on the nega-chopping block, we're going to add a snazzy session variable to store the value of the Company field, so we can later store it in our eCart order info.

  1. Click Window > Bindings to ensure the Bindings floater is visible
  2. Click the Add ( ) Binding button
  3. Click Session Variable
  4. Enter eCartCheckoutForm_company as the Name
  5. Click OK

arrow downStore Company in session

Now we're going to take that fancy little session variable we created, and use it to store the company value

  1. Open the confirm.php page
  2. In Design view, click your cursor right after the last hidden element on the page
    This will be right before the Modify Information button
  3. Click Insert > Form > Hidden Field
  4. In the Property Inspector for the newly added hidden field, change the name to be company
  5. Enter the following code into the Value field
    <?php echo (isset($_SESSION['eCartCheckoutForm_company'])?$_SESSION['eCartCheckoutForm_company']:""); ?>

  6. Click Window > Server Behaviors to ensure the Server Behaviors floater is visible
  7. Click the Add ( ) Server Behavior button
  8. Click eCart > General > Set Session Value
  9. For the Trigger, select any form post
  10. For the Session name, select the eCartCheckoutForm_company session we created earlier
  11. For the value, click the dynamic lightning bolt
  12. Expand the checkout form (ecart_checkout_form)
  13. Select the company field
  14. Click OK to select the field
  15. Click OK again to apply the Server Behavior
  16. Save everything!!

Just for fun, let's show the company name value in the Billling Information section of the confirm page

  1. In Design view, under billing info, find the first and last name php snippets
  2. Add a line break (shift enter) after the first and last name php snippets
  3. Open the bindings panel
  4. Expand the checkout form (ecart_checkout_form)
  5. Select the company field
  6. Drag and drop the company field to the new line created after the first and last names
  7. Save it all, homie!

arrow downAdd company to database

We're getting close, I can taste it! It tastes garlicy, with a hint of lime%u2026

The next step is going to be adding the company the user entered into the order in the database

Step 1: Create the database field

  1. Open your database in whatever database manager you use
  2. Open the orders table
  3. Add a new field
  4. Name the field OrderCompany
  5. Set the type as varchar(100)
  6. Set the default value to NULL
  7. Allow the field to be NULL
  8. Add the field

Step 2: Store the value

  1. Open the confirm.php page in Dreamweaver
  2. Click Window > Server Behaviors to ensure the Server Behaviors floater is visible
  3. Locate the eCart Store Summary in Database server behavior
  4. Double click it to open it
  5. Find OrderCompany in the columns list
  6. Select OrderCompany
  7. Enter the following code into the Value field
    <?php echo (isset($_SESSION['eCartCheckoutForm_company'])?$_SESSION['eCartCheckoutForm_company']:""); ?>

  8. Click OK

Your skills at websites are breathtaking. I'm sure you're good at other things too, but let's be honest; the thing that sold me on you was that sharp brain for web things.

arrow downWhat to do next...

Now that you can add an awesome form field and stuff, you can try adding the field value to your email receipts, or just spam their company with emails telling everyone what your client bought (don't really do that last one). The sky is the limit! %u2026 Unless you're an astronaut...

arrow downReviews and comments

Comments will be sent to the author of this tutorial and may not be answered immediately. For general help from WebAssist, please visit technical support.

Sign in to add comments

phill401410: 5 Years, 5 Months, 2 Days, 3 Hours, 7 Minutes ago

<?php echo (isset($_SESSION['eCartCheckoutForm_company'])?$_SESSION['eCartCheckoutForm_comp?any']:""); ?>
Is there an extra "?" in the second "comp?any"?

Team WebAssist: 5 Years, 5 Months, 2 Days, 7 Minutes ago

Yes, silly mistake - sorry. Thanks for catching.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.