Advanced Web Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsWeb DesignAdvanced Web Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 9th, 2011, 02:57 PM
stevemtno stevemtno is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 1 stevemtno User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 43 sec
Reputation Power: 0
Looking for a way to dynamically create a set of form fields

Hi Everyone,

Like the subject says, I'm looking for a way to dynamically create a set of form fields. Here is the scenario:

I'm going to have a customer information form, with company information (business name, address, phone, etc). If the company has more than one location, I need to be able to click a "New Location" button and create a new set of fields for that location. I'm not sure how many times I'll need to create a new set of fields, but at least once or twice, I'm sure.

I will also need to be able to send the form data to either an email address or a database of some kind. I have a PHP script that I use to send form data to an email address, but nothing to send the data to a database. For now, the email script should be fine. Still I need to be able to send the dynamically created field data. Not sure how to do that. The PHP script I'm currently using specifies the field names. Unless I would just add code based on what the new field names would be (I would think a more dynamic approach to this would be better tho).

Any advice on which direction to go with all this would be greatly appreciated.

Thanks!

Steve

Reply With Quote
  #2  
Old February 5th, 2012, 09:26 AM
COBOLdinosaur COBOLdinosaur is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Location: Canada
Posts: 6 COBOLdinosaur User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 47 sec
Reputation Power: 0
Are you wanting to create the change in the form permanently, or just for a single submission?


Cd&

Reply With Quote
  #3  
Old February 10th, 2012, 08:28 AM
Jaxxon Jaxxon is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 2 Jaxxon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 10 sec
Reputation Power: 0
Saving to a db, you'll have the same fields for each location, regardless of how many there are. You'll need to setup the db table to allow the business name to be listed in that table more than once, unless using a relationship where the business names go into one table and are given a unique business id and then the business id is not unique in the locations table. Let's not go there right now.

You'll want to change the action of your current form to a php script, say "processlocation.php" or whatever. Add another submit button to your form, named the same as your current button, but change its value to "Add Location" or something like that. Your new php script "processlocation.php" must check the $_POST['submit'] value, if the buttons are both named "submit" for instance, and according to that value, save posted data to the db and then do what you want. If they clicked the "Save" button it will save the posted data to the db and move on, if they clicked the "Add" button it will save posted data to the db and then present a new form - same form - with the business name pre-populated with their business name, and allowing them to continually add locations to db for all their locations and save when they have no more to add.

Reply With Quote
  #4  
Old September 4th, 2012, 02:48 AM
James360Smith James360Smith is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Location: Miami
Posts: 8 James360Smith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 34 m 45 sec
Reputation Power: 0
Facebook
Arrow

Here, i am placing a code to create dynamic set of form fields.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <link href="/style.css" rel="stylesheet" type="text/css" /> <title>More form fields</title> <script type="text/javascript"> FUNCTION addRowToTable() {   VAR tbl = document.getElementById('tblAddress');   VAR lastRow = tbl.rows.length;   // if there's no header row in the table, then iteration = lastRow + 1   VAR iteration = lastRow; //  var iteration = lastRow + 1;   VAR row = tbl.insertRow(lastRow);     //  cell 0   VAR cell0 = row.insertCell(0);   VAR el = document.createElement('input');   el.type = 'text';   el.NAME = 'Address[]';   el.size = 30;   cell0.appendChild(el);     //cell 1   VAR cell1 = row.insertCell(1);   VAR el = document.createElement('input');   el.type = 'text';   el.NAME = 'City[]';   el.size = 10;   cell1.appendChild(el);     //cell 2   VAR cell2 = row.insertCell(2);   VAR el = document.createElement('input');   el.type = 'text';   el.NAME = 'State[]';   el.size = 2;   cell2.appendChild(el);      //cell 3   VAR cell3 = row.insertCell(3);   VAR el = document.createElement('input');   el.type = 'text';   el.NAME = 'Zip[]';   el.size = 5;   cell3.appendChild(el); } </script> </head>   <body> <h3>Dynamic add form fields</h3>   <br /><br />  <form action="Untitled-2.php" name="h" method="post">  <table id="tblAddress">                 <tr>                   <td class="txtBase">Address</td>                   <td class="txtBase">City</td>                   <td class="txtBase">State</td>                   <td class="txtBase">Zip</td>                 </tr>                <tr>                   <td><input name="Address[]" type="text" size="30" maxlength="255"></td>                   <td><input name="City[]" type="text" size="10" maxlength="255"></td>                   <td><input name="State[]" type="text" size="2" maxlength="10"></td>                   <td><input name="Zip[]" type="text" size="5" maxlength="25"></td>     </tr>   </table><input type="button" name="Add" value="Add" onClick="addRowToTable();">                <input type="submit" name="Submit" value="Submit"> </form>     </body> </html>


For Code Source details info visits : psoug [dot] org [/] snippet [/] Javascript-Add-more-form-fields_106 [dot] htm

Reply With Quote
  #5  
Old September 4th, 2012, 10:19 PM
Teresa460 Teresa460 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 4 Teresa460 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 43 sec
Reputation Power: 0
Are you wanting to create the change in the form permanently, or just for a single submission?URLURLURL

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsWeb DesignAdvanced Web Development > Looking for a way to dynamically create a set of form fields


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap