validation

how do I use this script:
[php][/php]
with this form button:

<input name="submit" type="submit" value="Checkout" onclick="notEmpty(document.getElementById('pay1234'), 'Please Enter a Value')" />

so that way when the value is not empty the form submits, otherwise the message displays.

Well, you have to alter your IF-then to have a javascript posting command if the value is not zero.

Here is a link that explains how to post a form from Javascript… I think it will do well for you…

http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml

this is what I came up with:
[php] <div id=“Accordion1” class="Accordion"tabindex=“0”>


One Payment Type

 <form id="form1" name="form1"  action="final.php" method="post" >

Please select Payment Type<br /><label>
<input type="radio" name="type" value="Cash" id="demo_radio1" />
      Cash</label>
    <br />
    <label>
      <input type="radio" name="type" value="Credit Card" id="demo_radio1" />
      Credit Card</label>
    <br />
    <label>
      <input type="radio" name="type" value="Check" id="demo_radio1" />
      Check</label>
    <br />
    <label>
      <input type="radio" name="type" value="Gift Card" id="demo_radio1" />
      Gift Card</label>
    <br />
  </p>
  <p>
    <?php

// Query member data from the database and ready it for display
$sql = mysql_query(“SELECT * FROM cart where cart_id = '”.$_SESSION[‘complete’]."’ && product123 !=’’");
while($row = mysql_fetch_array($sql)){
$product = $row[“product123”];
$price1 = $row[“price”];
$id = $row[“product_id”];
$qty = $row[“quantity”];

$month = date(“F Y”);
$day = date(“d”);
$year = date(“Y”);
$date = date(“Y-m-d”);

?>








    <?php

}
?>

Amount:
    <input name="submit" type="submit" value="Checkout" 	

/>

  </p>
</form></div>
Two Payment Types
Please select 1st Payment Type:
Cash
Credit Card
Check
Gift Card



      Amount:
        <input type="text" name="payment2" id="pay123" onkeyup="textchanged()" />
      </div>
      
      <br />
      Please select 2nd payment type:</p>
  <p>

<br /><label>
<input type="radio" name="type" value="Cash" id="demo_radio3" />
      Cash</label>
    <br />
    <label>
      <input type="radio" name="type" value="Credit Card" id="demo_radio3" />
      Credit Card</label>
    <br />
    <label>
      <input type="radio" name="type" value="Check" id="demo_radio3" />
      Check</label>
    <br />
    <label>
      <input type="radio" name="type" value="Gift Card" id="demo_radio3" />
      Gift Card</label>
    <br />
  </p>
  <p>
    <br />
  </p>
  <p>
    <?php

// Query member data from the database and ready it for display
$sql = mysql_query(“SELECT * FROM cart where cart_id = '”.$_SESSION[‘complete’]."’ && product123 !=’’");
while($row = mysql_fetch_array($sql)){
$product = $row[“product123”];
$price1 = $row[“price”];
$id = $row[“product_id”];
$qty = $row[“quantity”];

$month = date(“F Y”);
$day = date(“d”);
$year = date(“Y”);
$date = date(“Y-m-d”);

?>








    <?php

}
?>


You may change this value to what the customer gives you:
    Amount:
    <input type="text" name="payment" id="pay1234" />
     <input name="submit" type="submit" value="Checkout" onclick="validate_form()"/></div>
  </p>
</form></div>
[/php] only problem is the second form wont submit, please help. I'm sure it is something obvious that I am missing.

Well, I see in your code where you start a form. () and then you end it. ()
And, next you end it again. () So, I think you are missing something there…

I deleted it, still doesn’t work, that belonged to the first form anyhow.

Well, if one form is wrong, it can mess up the next ones…

Anyway, So, what happens, it just does not post to the final.php file?
Or, do yo get an error?

Also, have you checked the SOURCE of it when you get to the point of posting it?
With the RIGHT-CLICK and selecting VIEW-SOURCE to see if the button is actually there and pointing to the form and the final.php? It might be something else I can not see. Without all the code to test on a site, I can only see parts of it. Look at the source and see if it jumps out at you…

here is the page source:

[code]34395772297878158168Old_CheneyOld_Cheney

Untitled Document
  <script type="text/javascript"><!--

if(document.all && !document.getElementById) { //IE4 support
document.getElementById = function(id) { return document.all[id]; }
}
function dss_addLoadEvent(fn) {
if(typeof(fn)!=“function”)return;
var tempFunc=window.onload;
window.onload=function() {
if(typeof(tempFunc)==“function”)tempFunc();
fn();
}
}
dss_addLoadEvent(function() {
if(!document.getElementById) return;
var f = document.getElementById(‘form2’);
// to prevent the form from submitting in this demo
f.onsubmit = function(){ return false; }
// hide the textarea and its parent label
document.getElementById(‘demo_radio_ta_label2’).style.display = ‘none’;
// get a reference to the radio button group
var rads = f.elements[‘demo_radio2’];
for(var i=0;i<rads.length;i++) {
// we add the event handler to each button in the group
rads[i].onkeyup=rads[i].onclick=function(){
if(!this.checked) return;
var el = document.getElementById(‘demo_radio_ta_label2’);
el.style.display = (this.value!=="")?’’:‘none’;
}
// in case, for any reason, one of the radio buttons is already checked
rads[i].onclick();
}
});
// -->

Please enter total given

do not enter commas (,) or dollar signs ($)

<p>

  The total is $37.50    </p>
<p>&nbsp;</p>
<div id="Accordion1" class="Accordion"tabindex="0">
  <div class="AccordionPanel">
<div class="AccordionPanelTab">One Payment Type</div>
<div class="AccordionPanelContent">
 
 <form id="form1" name="form1"  action="final.php" method="post" >

Please select Payment Type<br /><label>

<input type="radio" name="type" value="Cash" id="demo_radio1" />
      Cash</label>
    <br />
    <label>
      <input type="radio" name="type" value="Credit Card" id="demo_radio1" />
      Credit Card</label>
    <br />
    <label>

      <input type="radio" name="type" value="Check" id="demo_radio1" />
      Check</label>
    <br />
    <label>
      <input type="radio" name="type" value="Gift Card" id="demo_radio1" />
      Gift Card</label>
    <br />
  </p>

  <p>
     
    <input name="product[]" type="hidden" value="Gear Bag: Square Canvas" />
    <input name="academy[]" type="hidden" value="Old_Cheney" />
    <input name="month[]" type="hidden" value="March 2012" />
    <input name="day[]" type="hidden" value="03" />
    <input name="year[]" type="hidden" value="2012" />
    <input name="date[]" type="hidden" value="2012-03-03" />
    <input name="price[]" type="hidden" value="30.00" />
    <input name="id[]" type="hidden" value="35" />

    <input name="qty[]" type="hidden" value="1" />
    
     
    <input name="product[]" type="hidden" value="Water" />
    <input name="academy[]" type="hidden" value="Old_Cheney" />
    <input name="month[]" type="hidden" value="March 2012" />
    <input name="day[]" type="hidden" value="03" />
    <input name="year[]" type="hidden" value="2012" />
    <input name="date[]" type="hidden" value="2012-03-03" />
    <input name="price[]" type="hidden" value="1.50" />
    <input name="id[]" type="hidden" value="18" />

    <input name="qty[]" type="hidden" value="5" />
    
       

 <input type="hidden" name="total" id="total" value="37.5" />
Amount:
    <input name="submit" type="submit" value="Checkout" 	

/>

  </p>
</form></div>
SixServe Free Web Hosting
[/code] the page doesn't change or anything. nothing happens, it does however display the message if the field is empty.

if I also completely get rid of the function, it still does not post, must have something to do with the form

here is entire php code if it helps[php]<?php
session_start();
require_once “connect.php”;

if(isset($_SESSION[‘logged’])){

// Query member data from the database and ready it for display

$cid = $_SESSION[‘complete’];
$academy = $_SESSION[‘academy’];

$sql = mysql_query(“SELECT * FROM login where academy =’$academy’”);
while($row = mysql_fetch_array($sql)){
$date =$row[“date”];
if ($date !=="".date(‘m-d-Y’)){echo ‘’;
exit(); }

}
}else{
echo ‘’;
exit();
}

echo $cid;

echo $academy;

if($_POST[‘total’]){
$total = $_POST[‘total’];
}
?>

Untitled Document
  <script type="text/javascript"><!--

if(document.all && !document.getElementById) { //IE4 support
document.getElementById = function(id) { return document.all[id]; }
}
function dss_addLoadEvent(fn) {
if(typeof(fn)!=“function”)return;
var tempFunc=window.onload;
window.onload=function() {
if(typeof(tempFunc)==“function”)tempFunc();
fn();
}
}
dss_addLoadEvent(function() {
if(!document.getElementById) return;
var f = document.getElementById(‘form2’);
// to prevent the form from submitting in this demo
f.onsubmit = function(){ return false; }
// hide the textarea and its parent label
document.getElementById(‘demo_radio_ta_label2’).style.display = ‘none’;
// get a reference to the radio button group
var rads = f.elements[‘demo_radio2’];
for(var i=0;i<rads.length;i++) {
// we add the event handler to each button in the group
rads[i].onkeyup=rads[i].onclick=function(){
if(!this.checked) return;
var el = document.getElementById(‘demo_radio_ta_label2’);
el.style.display = (this.value!=="")?’’:‘none’;
}
// in case, for any reason, one of the radio buttons is already checked
rads[i].onclick();
}
});
// -->

Please enter total given

do not enter commas (,) or dollar signs ($)

<p>
  <?php setlocale(LC_MONETARY, "en_US");

echo money_format(“The total is %n”, $total);?>


 


<div id=“Accordion1” class="Accordion"tabindex=“0”>

One Payment Type

 <form id="form1" name="form1"  action="final.php" method="post" >

Please select Payment Type<br /><label>
<input type="radio" name="type" value="Cash" id="demo_radio1" />
      Cash</label>
    <br />
    <label>
      <input type="radio" name="type" value="Credit Card" id="demo_radio1" />
      Credit Card</label>
    <br />
    <label>
      <input type="radio" name="type" value="Check" id="demo_radio1" />
      Check</label>
    <br />
    <label>
      <input type="radio" name="type" value="Gift Card" id="demo_radio1" />
      Gift Card</label>
    <br />
  </p>
  <p>
    <?php

// Query member data from the database and ready it for display
$sql = mysql_query(“SELECT * FROM cart where cart_id = '”.$_SESSION[‘complete’]."’ && product123 !=’’");
while($row = mysql_fetch_array($sql)){
$product = $row[“product123”];
$price1 = $row[“price”];
$id = $row[“product_id”];
$qty = $row[“quantity”];

$month = date(“F Y”);
$day = date(“d”);
$year = date(“Y”);
$date = date(“Y-m-d”);

?>








    <?php

}
?>

 <input type="hidden" name="total" id="total" value="<?php echo $total; ?>" />
Amount:
    <input name="submit" type="submit" value="Checkout" 	

/>

  </p>
</form></div>
[/php]

do you see anthing?

Sorry, it took me a very long time to sort thru all that and make sense of it.
Sometimes reading other people’s code can be confusing. I did notice one thing, finally.
You have form2 that takes the payments and all. During it, you use Javascript to copy
a field into another one. All okay so far. Then, once it is read to post, you call the
Validation script instead of posting. Still okay. But, at that point all the Validation script
does it verify input in one field and then exit. It does not do anything else. At that point,
the script should execute the post or do whatever else you want it to.
In other words, to post a form the action is normally “somecodepage.php”, not a call to
a validation script. So, what do you want the program to do if the validation is VALID?
That would have to be placed in the script. You can post to another page very easily in
Javascript. If that is what you want, use this code:

document.forms["form2"].submit();    //your form name of course...

Here is a link to more info on this subject:
http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml
Hope that helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service