Avatar of rgb192
rgb192
Flag for United States of America asked on

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

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" /    
>';

      }

Open in new window



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" /     

Open in new window



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
PHP

Avatar of undefined
Last Comment
rgb192

8/22/2022 - Mon
Meir Rivkin

can u explain again what u want to achieve?
rgb192

ASKER
many html lines of text input
with just one line of <input> in php code repeated with a foreach loop
ASKER CERTIFIED SOLUTION
Member_2_248744

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
rgb192

ASKER
this will loop through all the values

thanks
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes