Jump to content

Suggestions for PHP Dynamic Form Handling


marisha

Recommended Posts

 

Hello All,

 

I am building a web based data entry project for my University Recycling Department

1) In the first level the user will enter the number of "rows" that he has to enter it can be any number form 4- 10 . Each row will contain "Vendor Name","Date","Net Recycled Weight"

2) Depending on the number of rows entered by the user I am generating a table structure that has

2.1) A <select> containing vendor names(I am querying for this and then storing the result in an Associative Array and then parsing it for select in every way)

2.2) A text box for the date

2.3) A text box for the Net Recycled Weight

------------------------------------------------

Here is the logic I have implemented so far

<html>

<head></head>

<body>

<form name = "form1" method = "post">

<select>HERE THE USER CAN SELECT THE NUMBER OF ROWS HE WANTS TO ENTER</select>

<input type = "submit" value = "submit1" name = "submit1">

</form>

<body>

</html>

<?php

if(submit1 has been clicked )

{

//HERE I AM GENERATING A DYNAMIC FORM BASED ON THE NUMBER OF ROWS COUNT

<form name = "form2" method = "post">

echo <table>

echo <tr>

echo<td>VENDOR</td>

echo<td>DATE</td>

echo<td>NET RECYCLED WEIGHT</td>

echo </tr>

for(IT ITERATES TILL I GENERATE THE NUMBER OF ROWS THAT HAS TO BE ENTERED)

{

I AM GENERATING ROWS HERE

 

}

echo <input type = "submit" name = "submit2" value = "submit2">

echo</table>

</form>

HOW CAN I ACCESS THE POST METHOD OF FORM 2

}

?>

 

 

MY PROBLEM

---------------

 

I WANT TO KNOW THE FOLLOWING

1) It this the correct way to do it

2) how can I access the data entered in each dynamic row as I have to validate it and then enter the data in MySql

3) I am not sure how I will access the submit button event of the dynamically generated form

 

 

I hope I can get some help

Thanks,

Marisha

Link to comment
Share on other sites

Hello,

during dynamic create of form value, in for loop write a below code

 

<input type="hidden" name="dynamic_value[]" value="$value[$i]">

 

So, you get those values in the form submit page.

 

* you haven't write action in form open tag and your submit works properly, there are no changes required.

 

let me know any error you get.

Link to comment
Share on other sites

Thank you for replying ....

I have a hidden field in "form1"

<input type="hidden" name="form1submit" value="1"/>

 

THIS IS WHEN UPPER FORM or form1 is submitted

if (array_key_exists('form1submit', $_POST))

{

//HERE I AM GENERATING A DYNAMIC FORM BASED ON THE NUMBER OF ROWS COUNT

<form name = "form2" method = "post">

echo <table>

echo <tr>

echo<td>VENDOR</td>

echo<td>DATE</td>

echo<td>NET RECYCLED WEIGHT</td>

echo </tr>

for(IT ITERATES TILL I GENERATE THE NUMBER OF ROWS THAT HAS TO BE ENTERED)

{

I AM GENERATING ROWS HERE

 

}

echo <input type = "submit" name = "submit2" value = "submit2">

echo</table>

//MY HIDDEN FIELD

<input type="hidden" name="form2submit" value="1"/>

</form>

}

//PROCESSING OF INNER FORM

if (array_key_exists('form2submit', $_POST))

{

}

 

?>

 

 

So if I do the following I will be able to access the POST of inner form "form2"

 

 

Please let me know if this is what you ment......

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.