Solved

post

Posted on 2011-09-23
7
283 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MySQL database data submission 7 39
Get Javascript URL parameters 7 28
resizeing PHP image 2 22
PHP loop not working 4 32
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 count occurrences of each item in an array.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now