Jump to content

PHP Forms - adding user specified number of form rows


PHP_Idiot

Recommended Posts

Hi as you may of guessed from the screen name I'm new to this.

 

I need to develop a page that records tournament information and feeds it back into my database.

I have a drop down list that calls venue names from my database, another to enter the date field and a third to ask how many players results need recording.

 

what I need the form to do then is create the required number form input rows ( same as number of player results that need recording).

The form would end up with number of players listed 1,2,3 (these become their finishing positions) etc running top to bottom, next would be an input field for the players membership number, thirdly, a ldisplay box that looks up the membership number and displays the players name as a sanity check.

 

Then when the user submits the form it saves the data to the mysql database.

 

I can make a static form but how do I get it to change the number of form rows available to match the user inputted player results number?

 

Thanks for all advice offered.

Link to comment
Share on other sites

It depends on how you want to do it...

 

If they enter the number of players and submit the page, then get that number and use it to generate the number of entries.

 

If you don't want them to submit it then it becomes a javascript issue, where you'll want to look at 'innerHTML'.

 

Your sanity check might even require the use of AJAX unless you submit the form...

Link to comment
Share on other sites

Ummm... not sure which is best.

 

What i had in mind was a page to enter the inital info, so a drop down of current venues (which I already have working) the date played (also working) and then a text entry field to input the number of players.

Then clicking the submit would take you to a form with the correct numbers of rows created.

 

However, I had imagined that the sanity check would run once the membership had been entered, without clicking any further buttons!

 

I tried the following code to create a loop but I can't get it to work, I was kinda hoping I could build it up from here!

<? 
numplayers = 20; 
for ($i = 1; $i <= $numplayers; $i++
{echo '
	<tr><table border="1">
  		<tr><th>Position</th><th>Membership Number</th><th>First Name</th><th>Last Name</th></tr>
	<td id="player.'$i'"><label>Position</label><input name="1" type="text" value="1" size="2" maxlength="2"></td>
	<td><label></label><input name="membership" type="text" size="7"></td>
		<td><label></label><input type="text" size="15" maxlength="10"></td>
		<td><input type="text" size="15" maxlength="10"></td>
	</tr>'; 
} 
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.