how to get value of Multiple text inputs with same name - php

i have just created one form that have some input fields with the same name . i want store all those value in one variable after submitting a form .
the code is
<div class="selectContainer">
<label>Number Of Person:</label>
<select id="ddTest" name="person">
<option value="">select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="hidden is1">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is2">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is2">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is3">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is3">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is3">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>`
how to store this value in one variable .? please help i am new to php

$name = $_POST['name'];
$age = $_POST['age'];
for($l=0; $l < count($name); $l++)
{ //your condition
}
don't forget to add this in your html
<label>Name</label>
<input type="text" size="20" name="name[]" id="name" >
</td>
<td>
<label>Age</label>
<input type="text" size="20" name="age[]" id="age" >
</td>

Create an array using [] for all similar names:
<input type="text" name="name[]" >
<input type="text" name="age[]" >
And then you can iterate over them:
for($i = 0; $i <= count($_POST['name']); $i++) {
echo $_POST['name'][$i] . "<br>";
echo $_POST['age'][$i] . "<br>";
}

Related

How to execute the php script for this?

I have an HTML form which I will tailor later as a personal feedback form, if someone submits the form, I want the responses to be sent to my email id. I googled about it and apparently, it can be done with PHP but I'm not familiar with the PHP script, can someone give me a headstart using the first few labels, I will try to write the rest on my own, this is the code
<form id="survey-form">
<div class="form-group">
<label id="name-label" for="name">Name</label>
<input
type="text"
name="name"
id="name"
class="form-control"
placeholder="Enter your name"
required
/>
</div>
<div class="form-group">
<label id="email-label" for="email">Email</label>
<input
type="email"
name="email"
id="email"
class="form-control"
placeholder="Enter your Email"
required
/>
</div>
<div class="form-group">
<label id="number-label" for="number"
>Age<span class="clue">(optional)</span></label
>
<input
type="number"
name="age"
id="number"
min="10"
max="99"
class="form-control"
placeholder="Age"
/>
</div>
<div class="form-group">
<p>Which option best describes your current role?</p>
<select id="dropdown" name="role" class="form-control" required>
<option disabled selected value>Select current role</option>
<option value="student">Student</option>
<option value="job">Full Time Job</option>
<option value="learner">Full Time Learner</option>
<option value="preferNo">Prefer not to say</option>
<option value="other">Other</option>
</select>
</div>
<div class="form-group">
<p>Would you recommend freeCodeCamp to a friend?</p>
<label>
<input
name="user-recommend"
value="definitely"
type="radio"
class="input-radio"
checked
/>Definitely</label
>
<label>
<input
name="user-recommend"
value="maybe"
type="radio"
class="input-radio"
/>Maybe</label
>
<label
><input
name="user-recommend"
value="not-sure"
type="radio"
class="input-radio"
/>Not sure</label
>
</div>
<div class="form-group">
<p>
What is your favorite feature of freeCodeCamp?
</p>
<select id="most-like" name="mostLike" class="form-control" required>
<option disabled selected value>Select an option</option>
<option value="challenges">Challenges</option>
<option value="projects">Projects</option>
<option value="community">Community</option>
<option value="openSource">Open Source</option>
</select>
</div>
<div class="form-group">
<p>
What would you like to see improved?
<span class="clue">(Check all that apply)</span>
</p>
<label
><input
name="prefer"
value="front-end-projects"
type="checkbox"
class="input-checkbox"
/>Front-end Projects</label
>
<label>
<input
name="prefer"
value="back-end-projects"
type="checkbox"
class="input-checkbox"
/>Back-end Projects</label
>
<label
><input
name="prefer"
value="data-visualization"
type="checkbox"
class="input-checkbox"
/>Data Visualization</label
>
<label
><input
name="prefer"
value="challenges"
type="checkbox"
class="input-checkbox"
/>Challenges</label
>
<label
><input
name="prefer"
value="open-source-community"
type="checkbox"
class="input-checkbox"
/>Open Source Community</label
>
<label
><input
name="prefer"
value="gitter-help-rooms"
type="checkbox"
class="input-checkbox"
/>Gitter help rooms</label
>
<label
><input
name="prefer"
value="videos"
type="checkbox"
class="input-checkbox"
/>Videos</label
>
<label
><input
name="prefer"
value="city-meetups"
type="checkbox"
class="input-checkbox"
/>City Meetups</label
>
<label
><input
name="prefer"
value="wiki"
type="checkbox"
class="input-checkbox"
/>Wiki</label
>
<label
><input
name="prefer"
value="forum"
type="checkbox"
class="input-checkbox"
/>Forum</label
>
<label
><input
name="prefer"
value="additional-courses"
type="checkbox"
class="input-checkbox"
/>Additional Courses</label
>
</div>
<div class="form-group">
<p>Any comments or suggestions?</p>
<textarea
id="comments"
class="input-textarea"
name="comment"
placeholder="Enter your comment here..."
></textarea>
</div>
<div class="form-group">
<button type="submit" id="submit" class="submit-button">
Submit
</button>
</div>
</form>

Form submittion wont read required in the select tag

I have a page where the users can register accounts which looks like this:
The problem is, when the user doesn't or forgot to fill up gender, it just submits the form without an error even if I have a required function on the select tag. It's only the gender that I'm having problems with. The required function works with the other fields.
here's my form:
<div class="main">
<div class="one">
<div class="register">
<center><h3>Add Account</h3></center>
<form name="reg" action="code_exec.php" onsubmit="return validateForm()" method="post">
<div>
<label>ID</label>
<input type="text" name="id" required>
</div>
<div>
<label>First Name</label>
<input type="text" name="firstname" required>
</div>
<div>
<label>Last Name</label>
<input type="text" name="lastname" required>
</div>
<div>
<label>Email</label>
<input type="text" name="email" placeholder="user#teamspan.com" required>
</div>
<div>
<label>Username</label>
<input type="text" name="username" required>
</div>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<div>
<label>Street Address</label>
<input type="text" name="street" required>
</div>
<div>
<label>Town/Suburb</label>
<input type="text" name="town" required>
</div>
<div>
<label>City</label>
<input type="text" name="city" required>
</div>
<div>
<label>Phone No.</label>
<input type="text" name="phone">
</div>
<div>
<label>Landline No.</label>
<input type="text" name="landline">
</div>
<div>
<label>Gender</label>
<select name="gender" required>
<option disabled selected hidden>Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div>
<label>User Levels</label>
<select name="user_levels" required>
<option disabled selected hidden>Select Access Level</option>
<option value="0">Employee</option>
<option value="1">Administrator</option>
<option value="2">Manager</option>
<option value="1">HR</option>
</select>
</div>
<div>
<label>Date</label>
<input type="text" readonly="readonly" name="date" value="<?php echo date("Y/m/d");?>" required>
</div>
<div>
<label>Sick Leave</label>
<input type="text" name="sickleave" required>
</div>
<div>
<label>Vacation Leave</label>
<input type="text" name="vacationleave" required>
</div>
<div>
<label>Picture (Link)</label>
<input type="text" name="picture" value="img/emp/" required>
</div>
<div>
<label></label>
<input type="submit" name="submit" value="Add Account" class="button" style="color: white;" />
<a href="hr_panel.php"><input type="button" value="Back" class="button" style="color: white;" />
</div>
</form>
</div>
</div>
You need to give value="" on first option i.e.Select Gender. Try following code
<div class="main">
<div class="one">
<div class="register">
<center><h3>Add Account</h3></center>
<form name="reg" action="code_exec.php" onsubmit="return validateForm()" method="post">
<div>
<label>ID</label>
<input type="text" name="id" required>
</div>
<div>
<label>First Name</label>
<input type="text" name="firstname" required>
</div>
<div>
<label>Last Name</label>
<input type="text" name="lastname" required>
</div>
<div>
<label>Email</label>
<input type="text" name="email" placeholder="user#teamspan.com" required>
</div>
<div>
<label>Username</label>
<input type="text" name="username" required>
</div>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<div>
<label>Street Address</label>
<input type="text" name="street" required>
</div>
<div>
<label>Town/Suburb</label>
<input type="text" name="town" required>
</div>
<div>
<label>City</label>
<input type="text" name="city" required>
</div>
<div>
<label>Phone No.</label>
<input type="text" name="phone">
</div>
<div>
<label>Landline No.</label>
<input type="text" name="landline">
</div>
<div>
<label>Gender</label>
<select name="gender" required>
<option disabled selected value="">Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div>
<label>User Levels</label>
<select name="user_levels" required>
<option disabled selected hidden>Select Access Level</option>
<option value="0">Employee</option>
<option value="1">Administrator</option>
<option value="2">Manager</option>
<option value="1">HR</option>
</select>
</div>
<div>
<label>Date</label>
<input type="text" readonly="readonly" name="date" value="<?php echo date("Y/m/d");?>" required>
</div>
<div>
<label>Sick Leave</label>
<input type="text" name="sickleave" required>
</div>
<div>
<label>Vacation Leave</label>
<input type="text" name="vacationleave" required>
</div>
<div>
<label>Picture (Link)</label>
<input type="text" name="picture" value="img/emp/" required>
</div>
<div>
<label></label>
<input type="submit" name="submit" value="Add Account" class="button" style="color: white;" />
<a href="hr_panel.php"><input type="button" value="Back" class="button" style="color: white;" />
</div>
</form>
</div>
</div>
Because you havent put value="" in Option
Try By This
<option value="" disable hidden>Select Gender</option>

How to make two rows insert with one button Laravel using ajax

i want to make two inserts in same table.
The table is based on this fields (locale, project_id(foreign key), title, caption).
And the controller looks like here:
public function storeTranslation(Request $request)
{
$projecttranslation = new ProjectTranslation();
$projecttranslation->locale = $request->input("locale");
$projecttranslation->project_id = $request->input("project");
$projecttranslation->title = $request->input("title");
$projecttranslation->caption = $request->input("caption");
$projecttranslation->save();
}
The form for the moment looks like here:
<div id="form2" style="display:none;" class="col-md-6">
<div class="col-md-">
<h3>Crear nueva traduccion</h3>
<form enctype="multipart/form-data" id="myFormTraduccion" name="myFormTraduccion"><!--FIRST FORM TO TRANSLATE -->
<input type="hidden" name="_token" value="{{ Session::token() }}">
<div class="form-group">
<label name="Language">Language:</label>
<input type="text" id="locale" name="locale" value="en" class="form-control form-control-sm">
<label name="Project">Project id:</label>
<input type="number" id="project" name="project" class="form-control form-control-sm">
<label name="Title">Title:</label>
<input type="text" id="title" name="title" class="form-control form-control-sm">
<label name="Caption">Caption:</label>
<input type="text" id="caption" name="caption" class="form-control form-control-sm"><br>
<input type="submit" value="Crear Traduccion" id="createtranslatesubmit" class="btn btn-danger btn-md">
<br><br><br>
</div>
</form> <!-- FIRST FORM TO TRANSLATE END HERE -->
<form enctype="multipart/form-data" id="myFormTraduccion2" name="myFormTraduccion2"> <!--SECOND FORM TO TRANSLATE -->
<input type="hidden" name="_token" value="{{ Session::token() }}">
<div class="form-group">
<label name="title">Language:</label>
<input type="text" id="locale" name="locale" value="es" disabled class="form-control form-control-sm">
<label name="order">Project id:</label>
<input type="number" id="project" name="project" class="form-control form-control-sm">
<label name="public">Title:</label>
<input type="text" id="title" name="title" class="form-control form-control-sm">
<label name="caption">Caption:</label>
<input type="text" id="caption" name="caption" class="form-control form-control-sm"><br>
<input type="submit" value="Crear Traduccion" id="createtranslatesubmit2" class="btn btn-danger btn-md">
<br><br><br>
</div>
</form> <!--SECOND FORM TO TRANSLATE END HERE -->
</div>
</div>
And the ajax look like this:
$("#createtranslatesubmit").click(function(){
$("#myFormTraduccion").submit();
});
$("#myFormTraduccion").submit(function(e){
e.preventDefault();
$.ajax({
url:'/admin/projects/postUploadTranslation',
type:'POST',
data:$('#myFormTraduccion').serializeArray(),
success: function(){
$("#form2").fadeOut(1000);
$("#form3").fadeIn(2000);
}
});
});
This create only with the first form, the first translation.
I think i should change the view code to this (Two same inputs for each field of database):
<div id="form2" style="display:none;" class="col-md-6">
<div class="col-md-">
<h3>Crear nueva traduccion</h3>
<form enctype="multipart/form-data" id="myFormTraduccion" name="myFormTraduccion"><!--FIRST FORM TO TRANSLATE -->
<input type="hidden" name="_token" value="{{ Session::token() }}">
<div class="form-group">
<label name="Language">Language:</label>
<input type="text" id="locale" name="locale" value="en" class="form-control form-control-sm">
<label name="Project">Project id:</label>
<input type="number" id="project" name="project" class="form-control form-control-sm">
<label name="Title">Title:</label>
<input type="text" id="title" name="title" class="form-control form-control-sm">
<label name="Caption">Caption:</label>
<input type="text" id="caption" name="caption" class="form-control form-control-sm">
<label name="title">Language:</label>
<input type="text" id="locale" name="locale" value="es" class="form-control form-control-sm">
<label name="order">Project id:</label>
<input type="number" id="project" name="project" class="form-control form-control-sm">
<label name="public">Title:</label>
<input type="text" id="title" name="title" class="form-control form-control-sm">
<label name="caption">Caption:</label>
<input type="text" id="caption" name="caption" class="form-control form-control-sm"><br>
<input type="submit" value="Crear Traduccion" id="createtranslatesubmit" class="btn btn-danger btn-md">
<br><br><br>
</div>
</form> <!-- FIRST FORM TO TRANSLATE END HERE -->
</div>
</div>
That's correct? The problem to "store" the data, i think will be a foreach in controller.
And finally, i don't have any idea, how to pass the data in the ajax, with a formdata maybe?
Thanks a lot, any help will be appreciated!
When you submit a form, you send to the server the data of that specific form. Your approach of using multiple forms doesn't work here, because you want to send all data with only 1 specific form submit.
So you have to only create 1 form and separate the different translations with a numeric reference.
Your HTML (note the -0 and -1 used to separate id and name of each input element) :
<form enctype="multipart/form-data" id="myFormTraduccion" name="myFormTraduccion"><!--FIRST FORM TO TRANSLATE -->
<input type="hidden" name="_token" value="{{ Session::token() }}">
<div class="form-group">
<label name="Language">Language:</label>
<input type="text" id="locale-0" name="locale-0" value="en" class="form-control form-control-sm">
<label name="Project">Project id:</label>
<input type="number" id="project-0" name="project-0" class="form-control form-control-sm">
<label name="Title">Title:</label>
<input type="text" id="title-0" name="title-0" class="form-control form-control-sm">
<label name="Caption">Caption:</label>
<input type="text" id="caption-0" name="caption-0" class="form-control form-control-sm">
<label name="title">Language:</label>
<input type="text" id="locale-1" name="locale-1" value="es" class="form-control form-control-sm">
<label name="order">Project id:</label>
<input type="number" id="project-1" name="project-1" class="form-control form-control-sm">
<label name="public">Title:</label>
<input type="text" id="title-1" name="title-1" class="form-control form-control-sm">
<label name="caption">Caption:</label>
<input type="text" id="caption-1" name="caption-1" class="form-control form-control-sm"><br>
<input type="submit" value="Crear Traduccion" id="createtranslatesubmit" class="btn btn-danger btn-md">
<br><br><br>
</div>
</form>
The controller:
public function storeTranslation(Request $request)
{
$projecttranslation0 = new ProjectTranslation();
$projecttranslation0->locale = $request->input("locale-0");
$projecttranslation0->project_id = $request->input("project-0");
$projecttranslation0->title = $request->input("title-0");
$projecttranslation0->caption = $request->input("caption-0");
$projecttranslation0->save();
$projecttranslation1 = new ProjectTranslation();
$projecttranslation1->locale = $request->input("locale-1");
$projecttranslation1->project_id = $request->input("project-1");
$projecttranslation1->title = $request->input("title-1");
$projecttranslation1->caption = $request->input("caption-1");
$projecttranslation1->save();
}
Of course, it can be easily generalized for N multiple transations and not only 2.
try this out:
<div id="form2" style="display:none;" class="col-md-6">
<div class="col-md-">
<h3>Crear nueva traduccion</h3>
<form enctype="multipart/form-data" id="myFormTraduccion" name="myFormTraduccion"><!--FIRST FORM TO TRANSLATE -->
<input type="hidden" name="_token" value="{{ Session::token() }}">
<div class="form-group">
<label name="Language">Language:</label>
<input type="text" id="locale" name="ProjectTranslation[0][locale]" value="en" class="form-control form-control-sm">
<label name="Project">Project id:</label>
<input type="number" id="project" name="ProjectTranslation[0][project]" class="form-control form-control-sm">
<label name="Title">Title:</label>
<input type="text" id="title" name="ProjectTranslation[0][title]" class="form-control form-control-sm">
<label name="Caption">Caption:</label>
<input type="text" id="caption" name="ProjectTranslation[0][caption]" class="form-control form-control-sm">
<label name="title">Language:</label>
<input type="text" id="locale" name="ProjectTranslation[1][locale]" value="es" class="form-control form-control-sm">
<label name="order">Project id:</label>
<input type="number" id="project" name="ProjectTranslation[1][project]" class="form-control form-control-sm">
<label name="public">Title:</label>
<input type="text" id="title" name="ProjectTranslation[1][title]" class="form-control form-control-sm">
<label name="caption">Caption:</label>
<input type="text" id="caption" name="ProjectTranslation[1][caption]" class="form-control form-control-sm"><br>
<input type="submit" value="Crear Traduccion" id="createtranslatesubmit" class="btn btn-danger btn-md">
<br><br><br>
</div>
</form> <!-- FIRST FORM TO TRANSLATE END HERE -->
</div>
So you will get array of ProjectTranslation at controller side
Now at controller side
public function storeTranslation(Request $request)
{
$form_data = $request->get('ProjectTranslation');
foreach($form_data as $form){
$projecttranslation = ProjectTranslation::create($form);
$projecttranslation->save();
}
}

PHP - dynamic fields array not

I have a form with dynamic fields. When I add a dynamic field and do a var_dump of that field, I am getting only the first result.
Form:
<div class="form-group halltype">
<label class="col-sm-2 col-sm-2 control-label">HallType</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="title1[]" placeholder="Main Title"><br />
<input type="text" class="form-control" name="title2[]" placeholder="Title 2"><br />
<input type="text" class="form-control" name="seating[]" placeholder="Seating Capacity"><br />
<input type="text" class="form-control" name="floating[]" placeholder="Floating Capacity"><br />
</div>
</div>
<div class="form-group addhalltype">
<label class="col-sm-2 col-sm-2 control-label"></label>
<div class="col-sm-10">
<input type="button" class="btn btn-info" id="">Add Hall Type</button>
</div>
Jquery:
$(".addhalltype").click(function() {
$halltype = '<div class="form-group halltype"><label class="col-sm-2 col-sm-2 control-label">HallType</label><div class="col-sm-10"><input type="text" class="form-control" name="title1[]" placeholder="Main Title"><br /><input type="text" class="form-control" name="title2[]" placeholder="Title 2"><br /><input type="text" class="form-control" name="seating[]" placeholder="Seating Capacity"><br /><input type="text" class="form-control" name="floating[]" placeholder="Floating Capacity"><br /></div></div>';
$($halltype).insertBefore(".addhalltype");
});
and if I do var_dump($_POST['title1']), I get
array(1) {
[0]=>
string(4) "1212"
}
you are printing $_POST['title1'] in var_dump it will show you only value that u inserted for name="title1[]".
Here you are using dynamic array but with different name ie name equal to title1[] title1[] seating[] and floating[].
if you want to get all the post values in one name like title[0],title[1],...title[n] to get the result in this format you have to write your above code with this format.
<input type="text" class="form-control" name="title[]" placeholder="Main Title"><br />
<input type="text" class="form-control" name="title[]" placeholder="Title 2"><br />
<input type="text" class="form-control" name="title[]" placeholder="Seating Capacity"><br />
<input type="text" class="form-control" name="title[]" placeholder="Floating Capacity"><br />

loop to reduce writing many form containers

I have 12 forms that need to be in my page, however they don't really differ that much, for example:
<label>Player 1*</label>
<div class="form-group">
<input class="form-control" name="h-p1-fn" placeholder="First name" type="text"/>
</div>
<div class="form-group">
<input class="form-control" name="h-p1-ln" placeholder="Last name" type="text" />
</div>
<div class="form-group">
<input class="form-control" name="h-p1-nr" placeholder="Number" type="number" min="0" max="99" step="1" />
</div>
<label>Player 2*</label>
<div class="form-group">
<input class="form-control" name="h-p2-fn" placeholder="First name" type="text" />
</div>
<div class="form-group">
<input class="form-control" name="h-p2-ln" placeholder="Last name" type="text" />
</div>
<div class="form-group">
<input class="form-control" name="h-p2-nr" placeholder="Number" type="number" min="0" max="99" step="1" />
</div>
As you can see the forms do not differ much. The only differences:
labels increment(Player 1*, Player 2*, Player 3* and etc. the asterisk is for labels 1 to 5), input name increments (h-p1-fn, h-p2-fn and so on).
How can i reduce this code, maybe using a loop? All of this is in a .php file, so it would be better if it were an loop.
You can do this way:
<?php
for($i=1; $i<=12; $i++) {
?>
<label>Player <?php echo $i; ?>*</label>
<div class="form-group">
<input class="form-control" name="h-p<?php echo $i; ?>-fn" placeholder="First name" type="text"/>
</div>
<div class="form-group">
<input class="form-control" name="h-p<?php echo $i; ?>-ln" placeholder="Last name" type="text" />
</div>
<div class="form-group">
<input class="form-control" name="h-p<?php echo $i; ?>-nr" placeholder="Number" type="number" min="0" max="99" step="1" />
</div>
<?php } ?>
what you want can be achieved with this code
$cnt=1;
for($i=0;$i<5;$i++){
echo '
<label>Player .'$cnt'.*</label>
<div class="form-group">
<input class="form-control" name="h-p.'$cnt'.-fn" placeholder="First name" type="text" />
</div>
<div class="form-group">
<input class="form-control" name="h-p.'$cnt'.-ln" placeholder="Last name" type="text" />
</div>
<div class="form-group">
<input class="form-control" name="h-p.'$cnt'.-nr" placeholder="Number" type="number" min="0" max="99" step="1" />
</div>';
$cnt++;
}
You can also try this:
for($i=0;$i<=12;$i++){
?>
<label>Player<?php echo $i ?>*</label>
<div class="form-group">
<input class="form-control" name="h-p<?php echo $i; ?>-fn" placeholder="First name" type="text" />
</div>
<div class="form-group">
<input class="form-control" name="h-p<?php echo $i; ?>-ln" placeholder="Last name" type="text" />
</div>
<div class="form-group">
<input class="form-control" name="h-p<?php echo $i; ?>-nr" placeholder="Number" type="number" min="0" max="99" step="1" />
</div>
<?php
}

Categories