Jump to content
Larry Ullman's Book Forums

Virtual Store Registration Form


Recommended Posts

I have added an "Accept Terms" check box to the registration form. It seems to work with the exception that it has no stickiness. Any help will be appreciated. Below my code snippets:

 

form_functions.inc.php

// Conditional to determine what kind of element to create:
if ( ($type == 'text') || ($type == 'password') || ($type == 'checkbox') ) { // Create text or password or checkbox inputs.

 

register.php - validation:

// Validate the terms:
if (isset($_POST['terms'])) {
$t = TRUE;
} else { // Terms not checked.
$reg_errors['terms'] = 'You must accept the terms and conditions of use.';
}

 

register.php - form

<p><label for="terms"></label><?php create_form_input('terms', 'checkbox', $reg_errors); if (isset($_POST['terms']) && $_POST['terms'] == "Yes") echo "checked"; ?> <small>I have read and agree to the <a href="terms.php" title="View Terms and Conditions">terms and conditions</a> of use.</small></p>

 

Thank you in advance.

Link to comment
Share on other sites

Thank you for the response Larry and Margaux. I have managed to get the checkbox to work but just need confirmation from you on the "quality" of the code.

 

form_functions script:

} elseif ($type == 'checkbox') { // Create a checkbox.

// Start creating the input:
echo '<input type="' . $type . '" name="' . $name . '" id="' . $name . '"';

// Add the value to the input:
if ($value == TRUE) echo 'checked="checked"';

// Check for an error:
if (array_key_exists($name, $errors)) {
echo 'class="error" /> <span class="error">' . $errors[$name] . '</span>';
} else {
echo ' />';
}

 

register script:

// Validate the terms:
if (isset($_POST['terms'])) {
$t = TRUE;
} else {
$reg_errors['terms'] = 'You must accept the terms and conditions of use.';
}

 

register script form:

<p><label for="terms"></label><?php create_form_input('terms', 'checkbox', $reg_errors); ?> <small>I have read, understood and agree to the <a href="terms.php" title="View Terms and Conditions">terms and conditions</a> of use.</small></p>

 

I also want to use data retrieved from the database for select menus in the form_functions script. The "require Config and MySQL" are contained in the header. I however get the following errors:

 

Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in C:\xampp\htdocs\site\includes\config.inc.php on line 69

Warning: print_r() [function.print-r]: Property access is not allowed yet in C:\xampp\htdocs\site\includes\config.inc.php on line 69

 

The code is as follows:

} elseif ($type == 'select') { // Create a select menu.

if (($name == 'timezone')) { // Create a list of timezones.
// Retrieve the timezones.
$q = "SELECT timezone_id, timezone FROM timezones ORDER BY timezone ASC";
$r = mysqli_query ($dbc, $q);
while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {
 echo "<option value=\"$row[0]\"";
}
$data = $r;
// Free the results:
mysqli_free_result($r);

 

 

Thank you in advance.

Link to comment
Share on other sites

Hi Larry,

 

Thank your for your continued advice. As I am still very new at web development I get lost very easy. What do you mean by "that the value will depend upon the value of the checkbox"? Do I have to change the value from "True" to "Yes"?

 

I have started a new thread for my second question.

 

Kind regards,

 

Jacques

Link to comment
Share on other sites

 Share

×
×
  • Create New...