Administrator Recipe: Create Survey

The Survey Builder application allows you to create any number of surveys that, in turn, have a varied set of questions. Each survey is, in essence, a record in the Surveys data source. When the user submits the survey information, the new record is created. This record can be modified later. In addition to a straightforward form, a standard Insert Record server behavior is used in this recipe.

Step 1: Implement Create Survey Design

In this recipe, you'll build a form for creating surveys. The form includes fields for specifying a survey title, start date, end date, and brief description. Naturally, a button is also added to the form that will be used to activate the Insert Record server behavior.

  1. In the server model of your choice, create a dynamic page.

    graphics/book.gif In the SurveyBuilder folder, locate the folder for your server model and open the add_survey page from there.

  2. Add a table to the Content region of your page to contain the interface elements for the Create Survey application.

    graphics/book.gif From the Snippets panel, drag the Recipes > SurveyBuilder > Wireframes > Create Survey - Wireframe snippet into the Content editable region.

  3. Insert the form and its elements into the table. That includes three text fields (survey title, start date, and end date), one text area for the survey description, and a button.

    graphics/book.gif Place your cursor in the row below the words CREATE SURVEY and insert the Recipes > SurveyBuilder > Forms > Create Survey - Form snippet [r5-1].


    Figure r5-1.

    graphics/07fig01.jpg


  4. Save the file.

Step 2: Insert Record New Survey

As noted earlier, each new survey is entered as a record in the Surveys data source. To accomplish this, a standard Macromedia Dreamweaver server behavior, Insert Record, is applied. PHP users also need to add a bit of custom code to properly convert the dates for MySQL.

Note

To accommodate the different dialogs for the various server models, the steps are presented separately here and when necessary throughout this recipe.


For ASP
  1. From the Server Behaviors panel, choose Add (+) and select Insert Record from the list.

  2. In the Insert Record dialog, choose your data source.

    graphics/book.gif Choose Recipes from the Connection list.

  3. Select the table you want to insert the record into.

    graphics/book.gif From the Insert into Table list, choose Surveys.

  4. Set the page you want to appear after the record is inserted.

    graphics/book.gif Choose the survey_manager.asp file from your server model's folder for the After Inserting, Go To field.

  5. Select the form on the current page from which to gather the record values.

    graphics/book.gif From the Get Values From list, make sure CreateSurvey is selected.

  6. In the Form Elements area, match the form elements on the page to the fields in the data source table.

    graphics/book.gif Set SurveyTitle to insert into the SurveyName column as the text type.

    Set SurveyStartDate to insert into the SurveyStartDate column as the date type.

    Set SurveyEndDate to insert into the SurveyEndDate column as the date type.

    Set SurveyCompletionMessage to insert into the SurveyCompletedMessage column as the text type.

  7. When you're sure your choices are correct, click OK to close the dialog and add the behavior.

For ColdFusion and PHP
  1. From the Server Behaviors panel, choose Add (+) and select Insert Record.

  2. In the Insert Record dialog, choose the current form.

    graphics/book.gif Select CreateSurvey from the Submit Values From list.

  3. Select your data source from the list.

    graphics/book.gif Choose Recipes from the Data Source list.

  4. Enter your username and password, if needed.

  5. Select the table in the data source to insert into from the list.

    graphics/book.gif Choose Surveys from the Insert into Table list.

  6. Set the data source fields to their corresponding form elements.

    graphics/book.gif Make sure the SurveyID data column is set to be an unused Primary Key.

    Set SurveyName to the FORM.SurveyTitle form element and submit it as a Text type.

    Set SurveyStartDate to the FORM.SurveyStartDate form element and submit it as a Date MS Access type.

    Set SurveyEndDate to the FORM.SurveyEndDate form element and submit it as a Date MS Access type.

    Make sure SurveyLive is set not to get a value.

    Set SurveyCompletedMessage to the FORM.SurveyCompletionMessage form element and submit it as a Text type.

  7. In the After Inserting, Go To field, enter survey_manager.cfm or survey_manager.php as appropriate and click OK to close the dialog.

  8. Save your page.

PHP developers need to take one additional step to ensure that the date is converted from mm/dd/yyyy format to the more MySQL-friendly yyyy/mm/dd format.

  1. In Code view, move your cursor to the top of the page after the line that starts <?php require_once and insert the following code:

    graphics/php.gif From the Snippets panel, insert the Recipes > SurveyBuilder > CustomCode_PHP > Create Survey Format Date snippet.

    graphics/php.gif

    [View full width]

     <?phpif ((isset($_POST['SurveyStartDate']))||(isset graphics/ccc.gif($HTTP_POST_VARS ['SurveyStartDate']))||(isset graphics/ccc.gif($_POST['SurveyEndDate']))|| (isset graphics/ccc.gif($HTTP_POST_VARS['SurveyEndDate']))) {       $_POST['SurveyStartDate'] = substr graphics/ccc.gif($_POST['SurveyStartDate'],6,4) . substr graphics/ccc.gif($_POST['SurveyStartDate'],0,2). substr  graphics/ccc.gif($_POST['SurveyStartDate'],3,2);       $HTTP_POST_VARS['SurveyStartDate'] = substr  graphics/ccc.gif($HTTP_POST_VARS['SurveyStartDate'],6,4). substr  graphics/ccc.gif($HTTP_POST_VARS['SurveyStartDate'],0,2). substr  graphics/ccc.gif($HTTP_POST_VARS['SurveyStartDate'],3,2);       $_POST['SurveyEndDate'] = substr graphics/ccc.gif($_POST['SurveyEndDate'],6,4) . substr graphics/ccc.gif($_POST['SurveyEndDate'],0,2).substr($_POST['SurveyEndDate'] graphics/ccc.gif,3,2);       $HTTP_POST_VARS['SurveyEndDate'] = substr  graphics/ccc.gif($HTTP_POST_VARS['SurveyEndDate'],6,4). substr  graphics/ccc.gif($HTTP_POST_VARS['SurveyEndDate'],0,2). substr  graphics/ccc.gif($HTTP_POST_VARS['SurveyEndDate'],3,2); } ?> 

  2. When you're done, save the page.



Macromedia Dreamweaver MX 2004 Web Application Recipes
Macromedia Dreamweaver MX 2004 Web Application Recipes
ISBN: 0735713200
EAN: 2147483647
Year: 2003
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net