Solved

post

Posted on 2011-09-23
7
305 Views
Last Modified: 2012-05-12
Form with two inputs first text second a number that determines how many text fields the next time form is shown.  Starts with one
0
Comment
Question by:rgb192
  • 4
  • 2
7 Comments
 
LVL 13

Expert Comment

by:themrrobert
ID: 36589130
This should do it:  (going to test it now, will update if it changes)
<?php

$lines = (isset($_POST['nextlines']) ? $_POST['nextlines'] : 1;

$form = "<form action=\"" . $PHP_SELF . "\" METHOD=\"POST\">";
$form .= 'Text line: <input name="textline" type="text" /><br />';
$form .= 'Number of new lines: <input name="nextlines" type="text" size="4" /><br />';
$form .= "Additional Lines Below<hr />";
for($x=0;$x<=$lines;$x++) {
  $form .= 'Line #: ' . $x + 1 . " <input type="text" name="mytext[' . $x . ']" />';
 }
 
 ?>

Open in new window

0
 
LVL 13

Expert Comment

by:themrrobert
ID: 36589160
Here is the non buggy code:
<?php

$lines = (isset($_POST['nextlines'])) ? $_POST['nextlines'] : 1;

$form = "<form action=\"" . $PHP_SELF . "\" METHOD=\"POST\">";
$form .= 'Text line: <input name="textline" type="text" /><br />';
$form .= 'Number of new lines: <input name="nextlines" type="text" size="4" /><br />';
$form .= "Additional Lines Below<hr />";
for($x=0;$x<$lines;$x++) {
  $form .= 'Line #: ' . ($x + 1) . ' <input type="text" name="mytext[' . $x . ']" />';
 }
$form .= "<input type=submit value=Go></form>";
 echo $form;
?>

Open in new window

0
 
LVL 13

Accepted Solution

by:
themrrobert earned 500 total points
ID: 36589175
To access variables in the dynamically created lines, in php you do this:

$MyNewLines = $_POST['mytext'];

foreach($MyNewLines as $index => $value) {
 echo "Key # $index = $value <br />";
}

Or  you can access like

$line2 = $MyNewLines[2];

etc
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:rgb192
ID: 36589453
Why are there two inputs for input text.  And form doesn't work
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 36590599
I believe that jQuery has some dynamic forms available.
0
 
LVL 13

Expert Comment

by:themrrobert
ID: 36591120
well we need more info.

what is the actual function od the form?

there are two because 1 is text and the 2nd prompts for number of new lines. type a number in box 2
0
 

Author Closing Comment

by:rgb192
ID: 36592641
combining this with the 'non buggy code'

delivers results

I can not click twice though
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question