Jump to content

Recommended Posts

I have a PHP question I was hoping you can help me with.

Let me try to explain. you can demo at http://vsk-ayc.totalh.com/index.php?page=181

 

This code is written to be used in TinyPortal for SMF

 

I have a series of forms each submits to the next

 

form #1 Gets Information about the host of a race:

global $user_info, $context, $settings, $options, $txt, $scripturl;

//////ENTRY FORM//////

//Hosting Information
echo '
<form action="'.$scripturl.'?page=182'.$GET['page'].'" method="post">
<INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
<hr style="width: 100%; height: 2px;" />
<h4>HOSTING INFORMATION</h4>
<hr style="width: 100%; height: 2px;" />
<table>
<tr>
<td align="left"><p><b>HOST :</b></p><input type="text" name="host" id="host" value="', $context['host'], '" tabindex="', $context['tabindex']++, '" size="40" /><a href="', $scripturl, '?action=findmember;input=host;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);"><img src="', $settings['images_url'], '/icons/assist.gif" alt="', $txt['find_members'], '" /></a> <a href="', $scripturl, '?action=findmember;input=host;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);">', $txt['find_members'], '</a></td>
<td align="left"><p><b>DATE :</b></P><input type="date type" name="date" id="date" value</a><b> yyyy/mm/dd</b></td>
</tr>
<tr>
<td><b>NUMBER OF BOATS IN RACE: </b><input type="text" name="boats" maxlength="2" size="3" /></td>
</tr>
<tr>
<td align="left"><p><b>RACE TYPE :</b></p><SELECT id="factor" name="factor" style="WIDTH: 200px" value ="';
if (isset($_POST['points'])) echo $_POST['factor'];
echo '" />
					<OPTION value="1" selected>Fleet Race</OPTION>
					<OPTION value="1">Match Race</OPTION>
					<OPTION value="2">Club Race</OPTION>
					<OPTION value="3">Championship Series</OPTION>
				</SELECT></td></tr>
</table>
<tr>
<td><INPUT type="submit" value="Submit"><INPUT type="reset" value="Reset"></td>
</tr>
</table><br></form>';

 

then posts that information into the fields of a new form which gathers finish information:

 

//////ENTRY PAGE 2//////

if (isset($_POST['submitted'])) {

echo'
<hr style="width: 100%; height: 2px;" />
<h4>HOSTING INFORMATION</h4>
<hr style="width: 100%; height: 2px;" />
<form action="'.$scripturl.'?page=183'.$GET['page'].'" method="post">
<INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
<table>
<tr><td><p><b>HOST :</b></P><input type="text" name="host" value="' . $_POST['host'] . '" /></td></tr>
<tr><td><p><b>DATE :</b></P><input type="text" name="date" value="' . $_POST['date'] . '" /></td></tr>
<tr><td><p><b>Number of Boats :</b></P><input type="text" name="boats" value="' . $_POST['boats'] . '" /></td></tr>
<tr><td><p><b>Race Factor :</b></P><input type="text" name="factor" value="' . $_POST['factor'] . '" /></td></tr>
</table>

<hr style="width: 100%; height: 2px;" />
<h4>ENTER RESULTS</h4>
<hr style="width: 100%; height: 2px;" />
<table>
<tr>
<td><p><input type="text" name="name" id="name" value="', $context['name'], '" tabindex="', $context['tabindex'], '" size="40" /> <a href="', $scripturl, '?action=findmember;input=name;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);"><img src="', $settings['images_url'], '/icons/assist.gif" alt="', $txt['find_members'], '" /></a> <a href="', $scripturl, '?action=findmember;input=name;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);">', $txt['find_members'], '</a></td>

<td><SELECT id="points" name="points" style="WIDTH: 60px" value ="';
if (isset($_POST['points'])) echo $_POST['points'];
echo '" />
<OPTION value="DNF" selected>DNF</OPTION>
<OPTION value="DNS">DNS</OPTION>
<OPTION value="0">1</OPTION>
<OPTION value="3">2</OPTION>
<OPTION value="5.7">3</OPTION>
<OPTION value="8">4</OPTION>
<OPTION value="10">5</OPTION>
<OPTION value="11.7">6</OPTION>
<OPTION value="13">7</OPTION>
<OPTION value="14">8</OPTION>
<OPTION value="15">9</OPTION>
<OPTION value="16">10</OPTION>
<OPTION value="17">11</OPTION>
<OPTION value="18">12</OPTION>
<OPTION value="19">13</OPTION>
<OPTION value="20">14</OPTION>
<OPTION value="21">15</OPTION>
<OPTION value="22">16</OPTION>
<OPTION value="23">17</OPTION>
<OPTION value="24">18</OPTION>
<OPTION value="25">19</OPTION>
<OPTION value="26">20</OPTION>
<OPTION value="27">21</OPTION>
<OPTION value="28">22</OPTION>
<OPTION value="29">23</OPTION>
<OPTION value="30">24</OPTION>
<OPTION value="31">25</OPTION>
<OPTION value="32">26</OPTION>
<OPTION value="33">27</OPTION>
<OPTION value="34">28</OPTION>
<OPTION value="35">29</OPTION>
<OPTION value="36">30</OPTION>
</SELECT></td>
</tr>
<tr>
<td><INPUT type="submit" value="Submit"><INPUT type="reset" value="Reset"></td>
</tr>
</table></form>';
}

 

Finally it finish with a points calculation which will later be set to submit to a database. (i don't have the code finished yet!):

 

 //POINTS CALCULATION
if ($_POST['points'] == "DNF")
$points = ($_POST['boats'] +1) * $_POST['factor'];

else if ($_POST['points'] == "DNS")
$points = ($_POST['boats'] +1) * $_POST['factor'];

else
$points = $_POST['points'] * $_POST['factor'];

if (isset($_POST['submitted'])) {

echo'
<hr style="width: 100%; height: 2px;" />
<h4>Points Calculation</h4>
<hr style="width: 100%; height: 2px;" />
<form action="'.$scripturl.'?page=171'.$GET['page'].'" method="post">
<INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
<table>
<tr><td><p><b>HOST :</b></P><input type="text" name="host" value="' . $_POST['host'] . '" /></td></tr>
<tr><td><p><b>DATE :</b></P><input type="text" name="date" value="' . $_POST['date'] . '" /></td></tr>
<tr><td><p><b>Number of Boats :</b></P><input type="text" name="boats" value="' . $_POST['boats'] . '" /></td></tr>
<tr><td><p><b>Race Factor :</b></P><input type="text" name="factor" value="' . $_POST['factor'] . '" /></td></tr>
</table>
<hr style="width: 100%; height: 2px;" />
<table>
<tr>
<td><p><b>Member :</b></P><input type="text" name="member" value="' . $_POST['name'] . '" /></td>
<td><p><b>Points This Race :</b></P><input type="text" name="position" value="' . $_POST['points'] . '" /></td>
<td><p><b>Ladder Points :</b></P><input type="text" name="points" value="' . $points . '"/></td>
</tr>
<TR>
			<TD>
			<INPUT type="submit" value="Submit">
			<INPUT type="reset" value="Reset"></TD>
		</TR>
</table></form>';
}

 

What I need to know is how to display these fields dynamically so that lets say if 20 boats are entered on the first page, 20 fields are created on the second page, and 20 results posted on the third?

 

the fields that need to be dynamic are:

 

<tr>
<td><p><input type="text" name="name" id="name" value="', $context['name'], '" tabindex="', $context['tabindex'], '" size="40" /> <a href="', $scripturl, '?action=findmember;input=name;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);"><img src="', $settings['images_url'], '/icons/assist.gif" alt="', $txt['find_members'], '" /></a> <a href="', $scripturl, '?action=findmember;input=name;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);">', $txt['find_members'], '</a></td>

<td><SELECT id="points" name="points" style="WIDTH: 60px" value ="';
if (isset($_POST['points'])) echo $_POST['points'];
echo '" />
					<OPTION value="DNF" selected>DNF</OPTION>
					<OPTION value="DNS">DNS</OPTION>
					<OPTION value="0">1</OPTION>
					<OPTION value="3">2</OPTION>
					<OPTION value="5.7">3</OPTION>
					<OPTION value="8">4</OPTION>
					<OPTION value="10">5</OPTION>
					<OPTION value="11.7">6</OPTION>
					<OPTION value="13">7</OPTION>
					<OPTION value="14">8</OPTION>
					<OPTION value="15">9</OPTION>
					<OPTION value="16">10</OPTION>
					<OPTION value="17">11</OPTION>
					<OPTION value="18">12</OPTION>
					<OPTION value="19">13</OPTION>
					<OPTION value="20">14</OPTION>
					<OPTION value="21">15</OPTION>
					<OPTION value="22">16</OPTION>
					<OPTION value="23">17</OPTION>
					<OPTION value="24">18</OPTION>
					<OPTION value="25">19</OPTION>
					<OPTION value="26">20</OPTION>
					<OPTION value="27">21</OPTION>
					<OPTION value="28">22</OPTION>
					<OPTION value="29">23</OPTION>
					<OPTION value="30">24</OPTION>
					<OPTION value="31">25</OPTION>
					<OPTION value="32">26</OPTION>
					<OPTION value="33">27</OPTION>
					<OPTION value="34">28</OPTION>
					<OPTION value="35">29</OPTION>
					<OPTION value="36">30</OPTION>
				</SELECT></td>
</tr>

Link to comment
https://forums.phpfreaks.com/topic/83250-solved-dynamic-form-elements/
Share on other sites

ok I have part one figured out and have changed my code as follows:

//////ENTRY PAGE 2//////

$times = $_POST['boats'];
$x = 0;

if (isset($_POST['submitted'])) {

echo'
<hr style="width: 100%; height: 2px;" />
<h4>HOSTING INFORMATION</h4><hr style="width: 100%; height: 2px;" />
<form action="'.$scripturl.'?page=183'.$GET['page'].'" method="post">
<INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
<table>
<tr><td><p><b>HOST :</b></P><input type="text" name="host" value="' . $_POST['host'] . '" /></td></tr>
<tr><td><p><b>DATE :</b></P><input type="text" name="date" value="' . $_POST['date'] . '" /></td></tr>
<tr><td><p><b>Number of Boats :</b></P><input type="text" name="boats" value="' . $_POST['boats'] . '" /></td></tr>
<tr><td><p><b>Race Factor :</b></P><input type="text" name="factor" value="' . $_POST['factor'] . '" /></td></tr>
</table>
<hr style="width: 100%; height: 2px;" />
<h4>ENTER RESULTS</h4>
<hr style="width: 100%; height: 2px;" />';


while ($x < $times) {
echo'

<table>
<tr>
<td><p><input type="text" name="name[ ]" id="name" value="', $context['name'], '" tabindex="', $context['tabindex'], '" size="40" /> <a href="', $scripturl, '?action=findmember;input=name;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);"><img src="', $settings['images_url'], '/icons/assist.gif" alt="', $txt['find_members'], '" /></a> <a href="', $scripturl, '?action=findmember;input=name;quote=1;sesc=', $context['session_id'], '" onclick="return reqWin(this.href, 350, 400);">', $txt['find_members'], '</a></td>

<td><SELECT id="points" name="points[ ]" style="WIDTH: 60px" value ="';
if (isset($_POST['points'])) echo $_POST['points'];
echo '" />
					<OPTION value="DNF" selected>DNF</OPTION>
					<OPTION value="DNS">DNS</OPTION>
					<OPTION value="0">1</OPTION>
					<OPTION value="3">2</OPTION>
					<OPTION value="5.7">3</OPTION>
					<OPTION value="8">4</OPTION>
					<OPTION value="10">5</OPTION>
					<OPTION value="11.7">6</OPTION>
					<OPTION value="13">7</OPTION>
					<OPTION value="14">8</OPTION>
					<OPTION value="15">9</OPTION>
					<OPTION value="16">10</OPTION>
					<OPTION value="17">11</OPTION>
					<OPTION value="18">12</OPTION>
					<OPTION value="19">13</OPTION>
					<OPTION value="20">14</OPTION>
					<OPTION value="21">15</OPTION>
					<OPTION value="22">16</OPTION>
					<OPTION value="23">17</OPTION>
					<OPTION value="24">18</OPTION>
					<OPTION value="25">19</OPTION>
					<OPTION value="26">20</OPTION>
					<OPTION value="27">21</OPTION>
					<OPTION value="28">22</OPTION>
					<OPTION value="29">23</OPTION>
					<OPTION value="30">24</OPTION>
					<OPTION value="31">25</OPTION>
					<OPTION value="32">26</OPTION>
					<OPTION value="33">27</OPTION>
					<OPTION value="34">28</OPTION>
					<OPTION value="35">29</OPTION>
					<OPTION value="36">30</OPTION>
				</SELECT></td>
</tr>';
++$x;
}
echo'
<tr>
<td><INPUT type="submit" value="Submit"><INPUT type="reset" value="Reset"></td>
</tr>
</table></form>';
}

 

now how do I change this so that it displays the results in a new form text box in code section 3?

also the //POINTS CALCULATION no longer works because of the array i am assuming?

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.