OSCommerce Basics: Posting A Variable with a form

This is the basic code used in OSCommerce to create a form and send a value to a page, and display that value on that page.

echo tep_draw_form('', tep_href_link('index.php', 'action=post', 'SSL'));
echo tep_draw_input_field('my_form', '');
echo tep_image_submit('', 'submit', '');
echo '</form>';

The oscommerce function tep_draw_form() creates a form, the oscommerce function tep_draw_input_field() creates a text box. You can tell these are functions because they have () after their name. (The programming knows to look in the file includes>functions>html_output to find out exactly how output these functions and so can you) .

The tep_draw_input_field() function is written so that the value in the first set of single quotes is recognized as the name of the input. In this case the name of the input is ‘my_form’. The function tep_image_submit(), also found in includes>functions>html_output, creates a submit button and </form> completes and closes the form.

Note the function within a function, tep_href_link() . This tells the form what page to send, or post, the input to. It can be the same page or another page. When you hit the submit button, you will go to that page. If on that page you have the code $HTTP_POST_VARS[‘my_form’], then that page knows to look for and capture the input called ‘my_form’ from the form. The input is now available to be used on that page in any of it’s programming. If you want to see that input, (and it is not necessary to do so in order to use that input), simply echo that variable on that page.

You can also substitute a number of other form types for the text box form, tep_draw_input_field(). For example the function tep_draw_checkbox_field() draws a checkbox. Now your code would be:

echo tep_draw_form('my_form', tep_href_link('index.php', 'action=post', 'SSL'));
echo tep_draw_checkbox_field('my_form', 'donuts');
echo tep_image_submit('', 'submit', '');
echo '</form>';

Note that the information, or value to be transmitted needs to be in the checkbox function, within the brackets() in the second set of quotes. And thus in this case $my_new_variable instead of being equal to anything that is typed into a text box, would always be equal to ‘donuts’.