I'm new to php. I have a jQuery script that will generate new elements. The user clicks submit and is taken to page2.php. That's where I need a php loop to determine how many text inputs the user created.
page1.php
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.min.js'> </script>
<script type='text/javascript'>
$(document).ready(function() {
$('#btn').click(function() {
var x = parseInt($('#hidtxt').val()) + (1*1);
var z = "<input type='text' id='txt" + x + "' name='txt" + x + "' size='10'/>";
$('#main').append(z);
$('#hidtxt').val(x);
});
});
</script>
</head>
<body>
<form name='myform' action='page2.php' method='post'/>
<input type='hidden' value='1' name='hidtxt' id='hidtxt'/>
<div id='main'>
<input type='text' id='txt1' name='txt1' size='10'/>
</div>
<input type='button' id='btn' name='btn' value='Add Text Box'/>
<input type='submit' value='Submit' id='subBtn' name='subBtn'/>
</form>
</body>
</html>
Then page2.php
<?php
//CREATE LOOP TO POST ALL TEXT INPUTS
$val1 = $_POST['txt1'];
$val2 = $_POST['txt2'];
....
....
$valx = $_POST['txtx'];
?>