When the solution matters

Tips...

Registration Documentation Knowledgebase Seminars / Training Partner Programs 4D Partner Central

Room 4 Rent

After you have completed the Questionnaire in the previous step, it will be time to enter a bid.

screenshot

This page is peppered with 4D Tags. Let us take a look at a section of "bidding.shtml", the source file for this page.

screenshot

Right near the beginning of the page, you can see an instance of 4DVAR. If you recall, 4DVAR is used to display either the contents of a 4D Variable, Database Field (column), or a 4D expression. The expression, in this first instance, happens to be:

String(WSC_i_MinimumBid;"$#,##0.00")

WSC_i_MinimumBid is a process variable that is declared in the Compiler_WEB method. The value of this variable is 600. This could have been written simply like this:

<!--4DVAR WSC_i_MinimumBid-->

However, the String command is used in order to format the variable to appear as "$600.00" rather than "600".

The next 4D tag is <!--4DSCRIPT/WSC_BidHighest-->

This is a simple call to the WSC_BidHighest method:

screenshot

This method should not be too difficult to understand. It simply selects all the records (ALL RECORDS) in the [Bids] table, sorts them by the Bid Amount in ascending order (ORDER BY) , and loads the last record after the sort (LAST RECORD) to get the [Bids] record with the highest Bid_Amount. Finally, the highest bid amount is sent back in the $0 variable.

Next, the Bids the Applicant has submitted will be loaded. It may well be that the Applicant hasn't submitted any bids yet (as with the first time he has visited the site). The [Bids] records are loaded and the highest bid amount checked by this call:

<!--4DIF (WSC_BidsForUser>0)-->

The 4DIF tag can evaluate any valid 4D expression that yields a boolean value. The WSC_BidsForUser method returns in $0 the highest Bid Amount the Applicant has submitted. So (WSC_BidsForUser>0) will either return True or False. This is a valid boolean expression, so it works fine with 4DIF.

screenshot

If there are some [Bids], they will be drawn in the <table> using 4DLOOP and 4DVAR.

The last part of the "bidding.shtml" file contains a <form> tag:

<form name="bid_form" action="/4DACTION/WSC_FormPost/Bid" method="post" >

If you examine the WSC_FormPost method again, you will see that if the parameter passed to it is "Bid" it will call the WSC_BidSave method. Let us examine the heart of this method:

screenshot

This method is also relatively simple. Some checks are made to see if the [Applicants] record is found, and if the submitted Bid Amount ($rBidAmount) is within acceptable parameters. Notice that at the end of the Case of statement (just before the Else), there is a call to WSC_BidsForUser. This is the same method that was used in conjunction with 4DSCRIPT in "bidding.shtml". If the submitted Bid Amount is determined to be valid, the [Bids] record is created (CREATE RECORD) and saved (SAVE RECORD).

Finally, all the [Bids] for the Applicant are re-loaded, sorted by the Timestamp_Submitted (this value is set in the Trigger of the [Bids] table), and the "bidding.shtml" page is sent back to the user.

Finished!

You have come to the end of the Room4Rent web application tutorial. A lot of material was covered in it, so if you're feeling a little dazed, that's perfectly understandable. However, you have now learned the fundamentals of web application development using 4th Dimension. So where should you go from here? Before you go anywhere, make sure you don't have any questions about what has been covered so far. Once you feel you've mastered all this tutorial has to offer, try modifying it to add some extra functionality - for instance, try sending an e-mail notification (using the 4D Internet Commands) to the "administrator" whenever a new high bid is submitted. The sky's the limit! Remember: if you think it, you can do it with 4th Dimension.

Previous  1 2 3 4 5 6 7 8 9 10 11 12


International | Company | Contact 4D | Site Map | Privacy Policy | © 4D, Inc. 1995-2008 | Change font size: [A] [A] [A] | Print this page | 4D RSS Feeds