Solved

post

Posted on 2011-09-23
7
312 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

830 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