troubleshooting Question

do many form inputs with one input statement (repeated by a loop)

Avatar of rgb192
rgb192Flag for United States of America asked on
PHP
4 Comments1 Solution186 ViewsLast Modified:
this code has the desired output

<style>

#firstlastname {
  margin: auto;
  width: 200px;
  font-family: Geneva, Arial, Helvetica, sans-serif;
  font-size: 27px;
  font-style: bold;
  padding: 5px;
  color: #FFFFFF;
  background-color: #000000;
  padding-top: 4px;
  padding-bottom: 4px;
  margin-top: 4px;
  margin-bottom: 4px;
  border: none;  
}

#pass1 {
  margin: auto;
  width: 440px;
  font-family: Geneva, Arial, Helvetica, sans-serif;
  font-size: 27px;
  font-style: bold;
  padding: 5px;
  color: #FFFFFF;
  background-color: #000000;
  padding-top: 4px;
  padding-bottom: 4px;
  margin-top: 4px;
  margin-bottom: 4px;
  border: none;  
}

</style>
<?php
$myArray[0]["first_name"] = "firstname";
$myArray[0]["last_name"] = "lastname";
$myArray[0]["email"] = "address";
$myArray[0]["pass1"] = "pass1";
$myArray[1]["first_name"] = "firstname";
$myArray[1]["last_name"] = "lastname";
$myArray[1]["email"] = "address";
$myArray[1]["pass1"] = "pass1";


for($i=0;$i<count($myArray);$i++){
echo '
        <br>Organization<br>
        <input name="organization" type="text" id="pass1" title="organization" />
        <br>Email<br>
        <input name="email" type="text" id="$myArray[$i]["address"]" title="email" />
        <br>Address Line 1<br>
        <input name="address1" type="text" id="pass1" title="address1" />
        <br>Address Line 2<br>
        <input name="address2" type="text" id="pass1" title="address2" />
        <br>City/Country<br>
        <input name="city" type="text" id="firstlastname" title="city" />
        <input name="country" type="text" id="firstlastname" title="country" />        
        <br>State Region/Postal Zip Code<br>
        <input name="state" type="text" id="firstlastname" title="state region" />
        <input name="postalcode" type="text" id="firstlastname" title="postal zip code" /    
>';

      }


desired html output
        <br>Organization<br>
        <input name="organization" type="text" id="pass1" title="organization" />
        <br>Email<br>
        <input name="email" type="text" id="pass1" title="email" />
        <br>Address Line 1<br>
        <input name="address1" type="text" id="pass1" title="address1" />
        <br>Address Line 2<br>
        <input name="address2" type="text" id="pass1" title="address2" />
        <br>City/Country<br>
        <input name="city" type="text" id="firstlastname" title="city" />
        <input name="country" type="text" id="firstlastname" title="country" />        
        <br>State Region/Postal Zip Code<br>
        <input name="state" type="text" id="firstlastname" title="state region" />
        <input name="postalcode" type="text" id="firstlastname" title="postal zip code" /     


but I want to have less lines because there is only text input
maybe do the foreach loop with only one input

  $arr = array("first_name","last_name","email","address1","city","country","state","postalcode","phone","creditcard","cvv2");
    foreach ($arr as &$colname) {




first_name input name is css id firstlastname
last_name  input name is css id  firstlastname
email  input name is css id  pass1
address1  input name is css id  pass1
ASKER CERTIFIED SOLUTION
Slick812

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros