Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

post

Posted on 2011-09-23
7
Medium Priority
?
332 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

649 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