0

Hi!The code I use for getting the values from dynamic javascript form fields is not working dont know why?
The problem might actually be because of form tags and submit buttons, I guess.So now I have three sets of pages using same code,
#1.Working in excellent condition
#2.Partially working if used with only one form tag
#3.Not working if used with three form tags
Dont believe me??
Please check following link:
http://flyingcv.com/test/
The complete code is given below for your kind perusal.Obviously I want solution for "Not working example" because that is one I want to use in my website.

<fieldset>

<legend>Invoice Details</legend>

<form name="newquotation1" method="post" action="invoice_data.php">

<table align="center">

<tr>

<td align="center" colspan="2"><span class="style2">All Fields Are Mandatory.</span></td>

</tr>

<tr>

<td>Invoice Number:</td>

<td><input type="text" name="number"></td>

</tr>

<tr>

<td>Client Name:</td>

<td>

<?PHP

$query=mysql_query("SELECT * FROM client_master");

echo "<select name='name'>";

while($row=mysql_fetch_array($query))

{

echo "<option value=$row[client_id]>

$row[client_name]</option>";

}

echo "</select>";

?>

</td>

</tr>

<tr>

<td>Work Order Number:</td>

<td width="300">Applicable&nbsp;<input name="radio" type="radio" value="applicable" />&nbsp;

<?PHP

$query=mysql_query("SELECT * FROM existing_clients");

echo "<select name='work'>";

while($row=mysql_fetch_array($query))

{

echo "<option value=$row[exi_work_number]>

$row[exi_work_number]</option>";

}

echo "</select>";

?>

&nbsp;Not Applicable&nbsp;<input name="radio" type="radio" value="notapplicable" />

</td>

</tr>

<tr>

<td>Invoice Date:</td>

<td width="200"><input id="demo3" name="date" type="text" >

<a href="javascript:NewCssCal('demo3','yyyymmdd')">

<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>

</tr>

</table>

</fieldset>

<fieldset>

<legend>&nbsp;</legend>

<table align="center">

<tr>

<td>Sales Person:</td>

<td><input type="text" name="sales_person"></td>

<td>Job:</td>

<td><input type="text" name="job"></td>

<td>Payment Terms:</td>

<td><input type="text" name="terms"></td>

<td>Due Date:</td>

<td><input type="text" name="due_date"></td>

</tr>

</table>

</form>

</fieldset>

<fieldset>

<legend>&nbsp;</legend>

<form name="newquotation" method="post" action="invoice_data.php" onSubmit="return validateForm(this)" id="form1">

<td><input type="button" value="Add Row" onClick="addRow('dataTable')" /></td>

<table align="center" id="dataTable">

<tr>

<td>Qty:</td>

<td><input type="text" name="qty[]"></td>

<td>Description:</td>

<td><textarea name="description[]" cols="16" rows=""></textarea></td>

<td>Unit Price:</td>

<td><input type="text" name="unit_price[]"></td>

<td>Line Total:</td>

<td><input type="text" name="line_total[]"></td>

</tr>

</table>

</form>

</fieldset>

<fieldset>

<legend>&nbsp;</legend>

<form method="post" action="invoice_data.php">

<table align="center">

<tr>

<td>Subtotal:</td>

<td><input type="text" name="subtotal"></td>

<td>Taxes:</td>

<td><input type="text" name="tax"></td>

<td>Advance:</td>

<td><input type="text" name="advance"></td>

<td>Total:</td>

<td><input type="text" name="total"></td>

</tr>

<tr>

<td colspan="8" align="center" >

<input name="submit" type="submit" value="Submit"></td>

</tr>

</table>

</form>

</fieldset>

</body>

</html>

<?php

$action=$_GET['query'];

if($action == "insert")

{

echo "<div align='center' class='style1'>Data Inserted..</div>";

}

if($action == "duplicate")

{

echo "<div align='center' class='style1'>This Invoice Already Exist..</div>";

}

?>

<fieldset>

The invoice_data.php code is:

<?PHP



if (isset($_POST['qty']) && sizeof($_POST['qty']) > 0) 

{

    for($i = 0, $maxi = count($_POST['qty']); $i < $maxi; $i++) 

    {

        $quantity    = (isset($_POST['qty'][$i]) && !empty($_POST['qty'][$i])) ? mysql_real_escape_string($_POST['qty'][$i]) : 0;

        $description = (isset($_POST['description'][$i]) && !empty($_POST['description'][$i])) ? mysql_real_escape_string($_POST['description'][$i]) : 0;

        $unit_price  = (isset($_POST['unit_price'][$i]) && !empty($_POST['unit_price'][$i])) ? mysql_real_escape_string($_POST['unit_price'][$i]) : 0;

        $line_total  = (isset($_POST['line_total'][$i]) && !empty($_POST['line_total'][$i])) ? mysql_real_escape_string($_POST['line_total'][$i]) : 0;



        $sql = "INSERT INTO 

        test 

        (qty,

        description,

        unit_price,

        line_total) 

        VALUES ('".$quantity."',

        '".$description."',

        '".$unit_price."',

        '".$line_total."')";

       mysql_query($sql);

       print_r($sql);

    }

} 

else 

{

    exit('No values entered');

} 

?>

<?PHP

$number=$_POST['number'];

$name=$_POST['name'];

$radio=$_POST['radio'];

$date=$_POST['date'];

$sales_person=$_POST['sales_person'];

$job=$_POST['job'];

$payment_terms=$_POST['terms'];

$due_date=$_POST['due_date'];

$tax=$_POST['tax'];

$advance=$_POST['advance'];

$total=$_POST['total'];

$work=$_POST['work'];

$select=mysql_query

("SELECT * 

FROM 

existing_clients 

WHERE 

exi_inv_number='".$number."'");

if(mysql_num_rows($select) > 0)

{

while($fetch=mysql_fetch_array($select))

{

if($fetch!=0)

{

header('Location:invoice.php?query=duplicate');

}

}

}

else

{

if($radio=="applicable")

{

$add=mysql_query

("UPDATE 

existing_clients 

SET 

exi_inv_date='$date', 

exi_inv_price='$price', 

exi_inv_number='$number', 

exi_inv_tax='$tax',

exi_inv_advance='$advance', 

exi_inv_total='$total', 

exi_status='2',

exi_inv_sales_person='$sales_person',

exi_inv_job='$job',

exi_inv_payment_terms='$payment_terms',

exi_inv_due_date='$due_date'

WHERE 

exi_work_number='$work'");

}

if($radio=="notapplicable")

{

$query=mysql_query

("INSERT INTO 

existing_clients 

(client_id, 

exi_inv_date, 

exi_inv_price, 

exi_inv_tax, 

exi_inv_advance, 

exi_inv_total, 

exi_inv_number, 

exi_status,

exi_inv_sales_person,

exi_inv_job,

exi_inv_payment_terms,

exi_inv_due_date) 

VALUES 

('".$name."',

'".$date."',

'".$price."',

'".$tax."',

'".$advance."',

'".$total."',

'".$number."',

2,

'".$sales_person."',

'".$job."',

'".$payment_terms."',

'".$due_date."'

)");

print_r($query);

}

header('Location:invoice.php?query=insert');

}

?>

I cant find the solution due to lack of expertise I guess
Thanking you in anticipation.

3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by anita_86
0

Why do you need to have multiple forms where the forms contain same action ?
Make a single form request where you have all requests to the same action page.
Add validations to mandatory fields.

Edited by paulrajj: n/a

0

Hello,

I show your code, As "paulrajj" suggestion it's doesn't need to make three form, So make one form with same action with multiple fieldset (which difference your different as form) and after click on submit button you need to make proper validation & than write code on invoice_data.php page.

By the way right now it's not working because, when you submit form ( which are in third form) and you check condition on invoice_data.php for "qty" field which are into second form. So after submit $_POST not have that qty value which is in second form.

I hope this will help you..

0

I am very thankful to paulrajj & HemantPHP for their replies.
Finally i got the solution for the issue.I just made it in single form tag and placed the javascript table at the end.
Thanks for your support.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.