Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag 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
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

can u explain again what u want to achieve?
Avatar of 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
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

this will loop through all the values

thanks