Jump to content


Photo

submitting form problem..


  • Please log in to reply
30 replies to this topic

#21 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 04 August 2006 - 03:39 AM

the javascript is only being used to redirect to the next page.. is this ok?

#22 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 04 August 2006 - 03:45 AM

Okay, well, I can tell you why your JavaScript isn't working.  Part of the DOM is that you cannot dynamically alter the attributes of something that hasn't yet been created.  For instance, you are trying to set an action to your form and submit it before you even create that form in the HTML.  You will have to put that segment of PHP/JavaScript after you create your form or else it will not work.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#23 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 04 August 2006 - 03:56 AM

ok ihave tried to do that but unsuccessful so far,

i have put this code in the else so that the function is called


  	print "<script language=\"JavaScript\">";
	print "loadNewPageFunc();";
	print "</script>";


then i have put after the form

<script language="JavaScript">
	function loadNewPageFunc()
	document.checkout_form.action='checkout_confirm.php';
	document.checkout_form.submit();
	</script>


#24 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 04 August 2006 - 03:59 AM

Put {} around your function.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#25 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 04 August 2006 - 04:04 AM

ok, it looks like this now, but doesn't work yet..
<script language="JavaScript">
	function loadNewPageFunc(){
	document.checkout_form.action='checkout_confirm.php';
	document.checkout_form.submit();}
	</script>

do i need the semicolons still? I have seen functions that don't have them at the end of every line.

#26 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 August 2006 - 05:11 PM

semicolons are not required at the end of the line in javascript.  Php, yes, javascript, no.

#27 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 August 2006 - 05:38 PM

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:

<?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>


#28 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 04 August 2006 - 08:47 PM

That is what I suggested, but he insists on doing it with JavaScript (not really sure why).
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#29 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 13 August 2006 - 11:09 PM

ahh, i get it now, i'll have a play with it and let you guys know how i go..

#30 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 13 August 2006 - 11:44 PM

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.

#31 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 17 August 2006 - 01:04 AM

ok, solved my problem, thanks for your help guys, i've learnt some good habits on the way!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users