Jump to content

submitting form problem..


john_6767

Recommended Posts

Prehaps I'm missing something, but I think you are making this more complicated than it should be.

instead of having your form, that when it's submitted it's checked for errors.  If it passes error checking, the form is presented for confirmation and submitted to a different place.  If it fails error checking, it is presented for correction and submitted back to itself again.

So, rather than trying to set the submit via javascript, set it in the normal action way, but have the action determined by your php.  Something like this:

[code]<?php
//WA eCart Include
require_once("WA_eCart/chandlery_PHP.php");
require_once("WA_ValidationToolkit/WAVT_Scripts_PHP.php");
require_once("WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php");

$chandlery->GetContent();

$postto = $_SERVER['PHP_SELF'];

if (isset($_POST["Checkout"]))  {
  $WAFV_Redirect = "checkout.php";
  $_SESSION['WAVT_checkout'] = "";
  if ($WAFV_Redirect == "")  {
    $WAFV_Redirect = $_SERVER["SCRIPT_NAME"];
  }
  $WAFV_Errors = "";
  $WAFV_Errors .= WAValidateRQ(((isset($_POST["Name"]))?$_POST["Name"]:"") . "",true,1);
  $WAFV_Errors .= WAValidateEM(((isset($_POST["Email"]))?$_POST["Email"]:"") . "",true,2);
  $WAFV_Errors .= WAValidateCC(((isset($_POST["CreditCardNo"]))?$_POST["CreditCardNo"]:"") . "","4:51:52:53:54:55:34:37:30:36:38:",true,3);
  $WAFV_Errors .= WAValidateRQ(((isset($_POST["CreditCardType"]))?$_POST["CreditCardType"]:"") . "",true,4);

  if ($WAFV_Errors != "")  {
    PostResult($WAFV_Redirect,$WAFV_Errors,"checkout");
  } else {
  $postto = 'checkout_confirm.php';
  }
}

// WA eCart Redirect
if ($chandlery->redirStr != "")    {
  header("Location: ".$chandlery->redirStr);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Newcastle Rigging & Chandlery</title>

<?php
$currentPageGroup = "images/nav/online_shop.gif";

if ($chandlery->DisplayInfo("Name") == "") {
print "<script language=\"JavaScript\">";
print "window.location = 'shopping_cart.php?Action=checkoutFailed' ";
print "</script>";
}
?>

<link href="styles/nrc.css" rel="stylesheet" type="text/css">
<script type="text/JavaScript">
<!--

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340; 
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth;
if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0;
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self; 
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    popupWindow[wp].document.body.onbeforeunload = function() {
  if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    window.onbeforeunload = null; } 
  autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; } 
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}
//-->
</script>
</head>
<body>
<div id="contents">
<table width="740" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="120">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" class="content">
      <h1>checkout</h1>
      <form name="checkout_form" method="POST" action="<?php echo $postto; ?>">
        <?php $chandlery_Index = $chandlery->DisplayIndex - 1;?>
        <?php
while (!$chandlery->EOF())      {
$chandlery_Index ++;?>

<input type="hidden" name="ID_<?php echo $chandlery_Index; ?>" value="<?php echo $chandlery->DisplayInfo("ID") ?>">
<input type="hidden" name="Name_<?php echo $chandlery_Index; ?>" value="<?php echo $chandlery->DisplayInfo("Name") ?>">
<input type="hidden" name="Description_<?php echo $chandlery_Index; ?>" value="<?php echo $chandlery->DisplayInfo("Description") ?>">
<input type="hidden" name="Weight_<?php echo $chandlery_Index; ?>" value="<?php echo $chandlery->DisplayInfo("Weight") ?>">
<input type="hidden" name="Quantity_<?php echo $chandlery_Index; ?>" value="<?php echo $chandlery->DisplayInfo("Quantity") ?>">
<input type="hidden" name="Price_<?php echo $chandlery_Index; ?>" value="<?php echo $chandlery->DisplayInfo("Price") ?>">
<input type="hidden" name="Colour_<?php echo $chandlery_Index; ?>" value="<?php echo $chandlery->DisplayInfo("Colour") ?>">
<input type="hidden" name="Size_<?php echo $chandlery_Index; ?>" value="<?php echo $chandlery->DisplayInfo("Size") ?>">
<?php
  $chandlery->MoveNext();
}
$chandlery->MoveFirst();
?>
        <table cellpadding="0" cellspacing="0" class="tableForm">
          <tr>
            <th> Name</th>
              <td><input name="Name" type="text" class="formTextField" value="<?php echo(ValidatedField("checkout","Name")) ?>"></td>
              <td>
  <?php
if (ValidatedField("checkout","checkout"))  {
  if ((strpos((",".ValidatedField("checkout","checkout").","), "," . "1" . ",") !== false || "1" == ""))  {
if (!(false))  {
?>
                <img src="images/error.gif" width="14" height="14"> Please enter your name
              <?php //WAFV_Conditional checkout.php checkout(1:)
}
  }
}
?>
  </td>
            </tr>
          <tr>
            <th> Email</th>
              <td><input name="Email" type="text" class="formTextField" value="<?php echo(ValidatedField("checkout","Email")) ?>"></td>
              <td>
  <?php
if (ValidatedField("checkout","checkout"))  {
  if ((strpos((",".ValidatedField("checkout","checkout").","), "," . "2" . ",") !== false || "2" == ""))  {
if (!(false))  {
?>
<img src="images/error.gif" width="14" height="14"> Please enter a valid email
<?php //WAFV_Conditional checkout.php checkout(2:)
}
  }
}
?>
  </td>
            </tr>
          <tr>
            <th> Credit Card No.</th>
              <td><input name="CreditCardNo" type="text" class="formCreditCardField" value="<?php echo(ValidatedField("checkout","CreditCardNo")) ?>"></td>
              <td>
  <?php
if (ValidatedField("checkout","checkout"))  {
  if ((strpos((",".ValidatedField("checkout","checkout").","), "," . "3" . ",") !== false || "3" == ""))  {
if (!(false))  {
?>
<img src="images/error.gif" width="14" height="14"> Please enter your credit card number
<?php //WAFV_Conditional checkout.php checkout(3:)
}
  }
}
?>
  </td>
            </tr>
          <tr>
            <th> Card Type</th>
              <td><select name="CreditCardType" class="formDropDownField" id="CreditCardType">
                <option value=" " <?php if (!(strcmp(" ", (ValidatedField("checkout","CreditCardType"))))) {echo "selected=\"selected\"";} ?>> </option>
                <option value="VISA" <?php if (!(strcmp("VISA", (ValidatedField("checkout","CreditCardType"))))) {echo "selected=\"selected\"";} ?>>VISA</option>
                <option value="MasterCard" <?php if (!(strcmp("MasterCard", (ValidatedField("checkout","CreditCardType"))))) {echo "selected=\"selected\"";} ?>>MasterCard</option>
                <option value="AMEX" <?php if (!(strcmp("AMEX", (ValidatedField("checkout","CreditCardType"))))) {echo "selected=\"selected\"";} ?>>AMEX</option>
                <option value="Diners" <?php if (!(strcmp("Diners", (ValidatedField("checkout","CreditCardType"))))) {echo "selected=\"selected\"";} ?>>Diners</option>
              </select></td>
              <td>
  <?php
if (ValidatedField("checkout","checkout"))  {
  if ((strpos((",".ValidatedField("checkout","checkout").","), "," . "4" . ",") !== false || "4" == ""))  {
if (!(false))  {
?>
<img src="images/error.gif" width="14" height="14"> Please select your card type
<?php //WAFV_Conditional checkout.php checkout(4:)
}
  }
}
?>
  </td>
            </tr>
          <tr>
            <td>&nbsp;</td>
              <td colspan="2" align="center"><input name="Checkout" type="submit" class="formCartButton" onMouseOver="this.className='formCartButtonOver';" onMouseOut="this.className='formCartButton';" value="Preview Purchase"></td>
            </tr>
          </table>
      </form>
</td>
  </tr>
</table>
</div>
</body>
</html>[/code]
Link to comment
Share on other sites

  • 2 weeks later...
ok, i see how this is supposed to work, i have a small error,

the page is ment to submit to the next page if there is no errors, this code at the moment only sets the action to '$postto', this means that the page reloads and the submit button needs to be re pressed to get to the next page.

So that said my question is; how do i get the php to submit the form when the $postto is set, i don't want to have to push the submit button twice when the correct data is entered.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.