Solved

post

Posted on 2011-09-23
7
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

Author Comment

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 i…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 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 …

724 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