Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Form sent without all required fields completed.


Leighbee

Recommended Posts

Posted

I've generated a new form, with all fields required (three text, one email, one checkbox).

 

I have cracked all the error codes - they all come up if fields are left blank.

But I can't stop the form being sent once the correct email address is entered, even if the text fields are blank and the checkbox unchecked.

 

How to I stop the form being sent unless ALL the fields are completed?

 

Any help much appreciated.

 

 

<?php

 

require('includes/application_top.php');

 

require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_REQUEST_DETAILS);

 

$error = false;

if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {

$name = tep_db_prepare_input($HTTP_POST_VARS['name']);

$email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);

$telephone = tep_db_prepare_input($HTTP_POST_VARS['telephone']);

$item = tep_db_prepare_input($HTTP_POST_VARS['item']);

$terms = tep_db_prepare_input($HTTP_POST_VARS['terms']);

 

 

if (tep_validate_email($email_address)) {

tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $item, $telephone, $name, $email_address);

 

tep_redirect(tep_href_link(FILENAME_REQUEST_DETAILS, 'action=success'));

} elseif (tep_validate_email($email_address) == false) {

$error = true;

 

$messageStack->add('request_details', ENTRY_EMAIL_ERROR);

}

 

 

if (strlen($name) < ENTRY_FIRST_NAME_MIN_LENGTH) {

$error = true;

 

$messageStack->add('request_details', ENTRY_NAME_ERROR);

}

 

 

if (strlen($telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {

$error = true;

 

$messageStack->add('request_details', ENTRY_TELEPHONE_ERROR);

}

 

 

if (strlen($item) < 5) {

$error = true;

 

$messageStack->add('request_details', ENTRY_ITEM_ERROR);

}

 

 

if (!isset($HTTP_POST_VARS['terms'])) {

$error = true;

 

$messageStack->add('request_details', ENTRY_TERMS_ERROR);

}

 

}

$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_REQUEST_DETAILS));

?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS; ?>>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<title><?php echo TITLE; ?></title>

<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">

<link rel="stylesheet" type="text/css" href="stylesheet.css">

<?php require('includes/form_check.js.php'); ?>

</head>

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">

<!-- header //-->

<?php require(DIR_WS_INCLUDES . 'header.php'); ?>

<!-- header_eof //-->

 

<!-- body //-->

<table border="0" width="100%" cellspacing="3" cellpadding="3">

<tr>

<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">

<!-- left_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>

<!-- left_navigation_eof //-->

</table></td>

<!-- body_text //-->

<td width="100%" valign="top"><?php echo tep_draw_form('request_details', tep_href_link(FILENAME_REQUEST_DETAILS, 'action=send')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

<td><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>

<td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_contact_us.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>

</tr>

</table></td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<?php

if ($messageStack->size('request_details') > 0) {

?>

<tr>

<td><?php echo $messageStack->output('request_details'); ?></td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<?php

}

 

if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'success')) {

?>

<tr>

<td class="main" align="left"><?php echo TEXT_SUCCESS; ?></td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<tr>

<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">

<tr class="infoBoxContents">

<td><table border="0" width="100%" cellspacing="0" cellpadding="2">

<tr>

<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>

<td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>

<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>

</tr>

</table></td>

</tr>

</table></td>

</tr>

<?php

} else {

?>

<tr>

<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">

<tr class="infoBoxContents">

<td><table border="0" width="100%" cellspacing="0" cellpadding="2">

<tr>

<td class="main"><?php echo TEXT_INFORMATION; ?></td>

</tr>

<tr>

<td class="main"><?php echo ENTRY_NAME; ?></td>

 

</tr><tr>

<td class="main"><?php echo tep_draw_input_field('name') . ' ' . (tep_not_null(ENTRY_NAME_TEXT) ? '<span class="inputRequirement">' . ENTRY_NAME_TEXT . '</span>': ''); ?></td>

 

</tr><tr>

 

<td class="main"><?php echo ENTRY_EMAIL_ADDRESS; ?></td>

 

</tr><tr>

 

<td class="main"><?php echo tep_draw_input_field('email_address') . ' ' . (tep_not_null(ENTRY_EMAIL_ADDRESS_TEXT) ? '<span class="inputRequirement">' . ENTRY_EMAIL_ADDRESS_TEXT . '</span>': ''); ?></td>

 

</tr><tr>

 

<td class="main"><?php echo ENTRY_TELEPHONE_NUMBER; ?></td>

 

</tr><tr>

 

<td class="main"><?php echo tep_draw_input_field('telephone') . ' ' . (tep_not_null(ENTRY_TELEPHONE_NUMBER_TEXT) ? '<span class="inputRequirement">' . ENTRY_TELEPHONE_NUMBER_TEXT . '</span>': ''); ?></td>

 

</tr>

<tr>

 

<td class="main"><?php echo ENTRY_ITEM; ?></td>

 

</tr><tr>

 

<td class="main"><?php echo tep_draw_input_field('item') . ' ' . (tep_not_null(ENTRY_ITEM_TEXT) ? '<span class="inputRequirement">' . ENTRY_ITEM_TEXT . '</span>': ''); ?></td>

 

</tr>

</table></td>

</tr>

</table></td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

 

 

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<tr>

<td class="main"><b><?php echo CATEGORY_TERMS; ?></b></td>

</tr>

<tr>

<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">

<tr class="infoBoxContents">

<td><table border="0" cellspacing="2" cellpadding="2">

<tr>

<td class="main"><?php echo ENTRY_TERMS; ?></td>

<td class="main"><?php echo tep_draw_checkbox_field('terms', '1') . ' ' . (tep_not_null(ENTRY_TERMS_TEXT) ? '<span class="inputRequirement">' . ENTRY_TERMS_TEXT . '</span>': ''); ?></td>

</tr>

</table></td>

</tr>

</table></td>

</tr>

 

<tr><td><br></td></tr>

 

<tr>

<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">

<tr class="infoBoxContents">

<td><table border="0" width="100%" cellspacing="0" cellpadding="2">

<tr>

<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>

<td align="right"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>

<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>

</tr>

</table></td>

</tr>

</table></td>

</tr>

<?php

}

?>

</table></form></td>

<!-- body_text_eof //-->

<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">

<!-- right_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>

<!-- right_navigation_eof //-->

</table></td>

</tr>

</table>

<!-- body_eof //-->

 

<!-- footer //-->

<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>

<!-- footer_eof //-->

<br>

</body>

</html>

<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

cmd-z... the best keystroke invented

Posted

I see two problems here.

 

The first is that you're setting $error but not processing it. You need to take some action if $error is true.

 

The second is that you're using the generic form_check.js.php module, which adds JavaScript checks that must be met before the form can be submitted. You'll probably need to create your own version of this file, with a different name. This is what's stopping the form submission for the email. But note that you can't completely rely on JavaScript validation, since anyone can disable JavaScript. So you need to validate in both the JavaScript and PHP files.

Check out Chad's News.

Posted

Thank you!

 

Would you be willing to offer any further help?

I am not a php programmer and, while I can understand the logic of your comments, I have no how to implement the fixes. :blush:

cmd-z... the best keystroke invented

Posted

If you're going to be writing osCommerce pages, then it's probably time to learn PHP and HTML. There are lots of websites and books that teach beginning PHP.

Check out Chad's News.

Posted

I couldn't agree more; but in the middle of setting up a new business, I simply don't have the time to work it all out from scratch. God knows I've tried...

Anyway, thanks very much for the pointers. :)

 

If anyone else is willing to offer further help, I would be hugely grateful.

cmd-z... the best keystroke invented

  • 3 months later...
Posted

What is the name of the form you are using? I'm looking to implement a form into my website in product listings (descriptions) that people submit before they add to cart & checkout so we don't have to chase them asking for info.

 

Thanks,

 

Henry

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...