Beispiel #1
0
<?php

/**
 * Created by PhpStorm.
 * User: Gil
 * Date: 10/12/2015
 * Time: 9:39 PM
 */
require_once "bookmark_fns.php";
do_html_header("User Registration");
display_registration_form();
do_html_footer();
    $b_is_address_valid = validate_address($address1, $address2);
    $b_is_city_valid = validate_city($city);
    $b_is_state_valid = validate_string($state);
    $b_is_zip_valid = validate_zip($zip);
    $b_is_country_valid = validate_string($country);
    // Check POST data
    if ($b_is_first_name_valid == true && $b_is_last_name_valid == true && $b_is_address_valid == true && $b_is_city_valid == true && $b_is_state_valid == true && $b_is_zip_valid == true && $b_is_country_valid == true) {
        // The inputted data is valid, submit it to server.
        submit_data($first_name, $last_name, $address1, $address2, $city, $state, $zip, $country);
    } else {
        // The inputted data is not valid, show the form again with
        // indicated errors.
        // Create key/pair array containing the POST data and validity
        // and pass it to display_registration_form().
        $post_data = array(array($first_name, $b_is_first_name_valid), array($last_name, $b_is_last_name_valid), array($address1, $b_is_address_valid), array($address2, $b_is_address_valid), array($city, $b_is_city_valid), array($state, $b_is_state_valid), array($zip, $b_is_zip_valid), array($country, $b_is_country_valid));
        display_registration_form($post_data);
    }
}
// submit_data() sends the user inputted data to the server for
// server-side validation and entry into the database.
//
// Arguments: POST data strings
// Returns: nothing
function submit_data($first_name, $last_name, $address1, $address2, $city, $state, $zip, $country)
{
    // Set confirmation page URL.
    $confirmation_page = "http://helloworld.cookingfor20somethings.com/confirmation.php";
    // Create array of fields to submit.
    $fields = array('first_name' => $first_name, 'last_name' => $last_name, 'address1' => $address1, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country);
    // Generate URL-encoded query (POST) string.
    $post_data = http_build_query($fields);