/    Sign up×
Community /Pin to ProfileBookmark

Add extra field twice

I got help writing php to add an extra row of input fields when the user clicks a button:
<?php
$rowsx=1;
if(isset($_POST[“rowsx”])){
$rowsx=$_
POST[“rowsx”];
}
for($e=1;$e<=$rowsx;$e++){
?>
<td><tr>
<div align=”center”>Quantity –
<input name=”product_options_amount<?php echo $e ?>” type=”text” id=”product_options_amount” value=”<?php echo($_POST[“product_options_amount”.$e]);?>” style=”text-align:center” size=”3″ />
</div></td>
<td>
<div align=”center”>Color –
<select name=”product_options_color<?php echo $e ?>” id=”product_options_color” >
<option value=”White”<?php if(isset($_
POST[“product_options_color”.$e])){if($_POST[“product_options_color”.$e]===”white”){echo ” selected”;}}?>>White</option>
<option value=”Black”<?php if(isset($_
POST[“product_options_color”.$e])){if($_POST[“product_options_color”.$e]===”black”){echo ” selected”;}}?>>
Black
<option value=”Red”<?php if(isset($_
POST[“product_options_color”.$e])){if($_POST[“product_options_color”.$e]===”2″){echo ” selected”;}}?>>Red</option>

</div></td>
</tr>
<?php
}
?>
<input type=”hidden” name=”rowsx” value=”<?php echo $rowsx+1; ?>” />
<input name=”submit” type=”submit” value=”Add another row” />

It works great, but I need one more thing. When the user adds another line, I need it to create a textbox for each line added. This textbox will be in another form. I think you’d put the php in the second form and use the variable $e, but I’m not sure how. Thanks.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @LocalHero spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...