Forum Moderators: coopster

Message Too Old, No Replies

Trying to combine a form page with a submit page

         

outdoorxtreme1

3:35 am on Jan 8, 2006 (gmt 0)

10+ Year Member



I want to add the following 2 pages of code together so that it is on one page. I am not sure how to go about doing it. Can anyone help me?

First page of code (form)
<form action="/index.php?page=ATVing_Submit" method="post">
<table>
<tr>
<td valign="top" id="fillinform">
<table WIDTH="450">
<tr>
<td valign="top" colspan="2">
<input type="hidden" name="triptype" value="ATV" />
<font FACE="Arial, Helvetica, sans-serif" size="1">
<strong>ATV Area:</strong><br />
<input type="text" size="29" maxlength="50" name="triplocation" value="{triplocation}" />
<br />
</font>
</td>
</tr>
<tr>
<td valign="top" colspan="2">
<font FACE="Arial, Helvetica, sans-serif" size="1">
<strong>State:</strong><br />
<select name="state" size="1">
<option selected="selected" value=""></option>
<option value="OH">Ohio</option>
<option value="PA">Pennsylvania</option>
<option value="NY">New York</option>
<option value="WV">West Virginia</option>
</select>
<br />
</font>
</td>
</tr>
<tr>
<td valign="top" colspan="2">
<font FACE="Arial, Helvetica, sans-serif" size="1">
<strong>Miles Traveled:</strong><br />
<input type="text" size="29" maxlength="50" name="miles" value="{miles}" />
<br />
</font>
</td>
</tr>
<tr>
<td valign="top" colspan="2"><strong>Trip Organizer:</strong><br />
<input type="text" size="29" maxlength="50"
name="triporganizer" value="{triporganizer}" />
<br />
</td>
<td valign="top">
</td>
<td valign="top">
</td>
</tr>
<tr>
<td valign="top" colspan="2" style="white-space:nowrap;"><strong>Trip Start:</strong><br />
<select name="TSpickMonth" size="1">
{TSpickMonth}
</select>
<select name="TSpickDay" size="1">
{TSpickDay}
</select>
<select name="TSpickYear" size="1">
{TSpickYear}
</select>
</td>
<td valign="top" colspan="2">
</td>
</tr>
<tr>
<td valign="top" colspan="2" style="white-space:nowrap;"><strong>Trip Finish:</strong><br />
<select name="TFpickMonth" size="1">
{TFpickMonth}
</select>
<select name="TFpickDay" size="1">
{TFpickDay}
</select>
<select name="TFpickYear" size="1">
{TFpickYear}
</select>
</td>
<td valign="top" colspan="2"><br />
</td>
</tr>
<tr>
<td colspan="2" valign="top"><strong>Trip Report Author:</strong><br />
<input type="text" size="29" maxlength="50" name="author" value="{author}" /> </td>
<td colspan="2" valign="top"><strong>Email:</strong><br />
<input type="text" size="29" maxlength="50" name="email" value="{email}" /> </td>
</tr>
</table>
</td>
</tr></table>
<table>
<tr>
<td valign="top" id="fillinform">
<strong>Participant Names:</strong>
<table border="0" WIDTH="456">
<tr>
<td>
1 <input type="text" size="25" maxlength="50" name="p1" value="{p1}" /><br>
2 <input type="text" size="25" maxlength="50" name="p2" value="{p2}" /><br>
3 <input type="text" size="25" maxlength="50" name="p3" value="{p3}" /><br>
4 <input type="text" size="25" maxlength="50" name="p4" value="{p4}" /><br>
5 <input type="text" size="25" maxlength="50" name="p5" value="{p5}" /><br>
6 <input type="text" size="25" maxlength="50" name="p6" value="{p6}" /><br>
7 <input type="text" size="25" maxlength="50" name="p7" value="{p7}" /><br>
8 <input type="text" size="25" maxlength="50" name="p8" value="{p8}" /><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table>
<tr>
<td valign="top" id="fillinform">
<strong>Photo Slideshow Link:</strong><br>
(must include [)<br>...]
<table
border="0" WIDTH="456">
<tr>

<td>
<input type="text" size="70" maxlength="100" name="photolink" value="{photolink}" /><br>
</td>
</tr>
</table>
</td>
</tr></table>
<table>
<tr>
<td valign="top" id="fillinform">
<strong>Type your trip report below:</strong><br />
<textarea name="report" rows="15" cols="55" wrap="on" class="input350">{report}</textarea>
<br>
<center>
<input id="Submit" type="submit" style="font-size:smaller;width:7em;" name="screen" value="Submit">
</center>
</td>
</tr>
</TABLE>
<TABLE WIDTH="273">
<TR>
<td valign="top">
<p>
</p>
</td>
</tr>
</table>

Second page of code (submit}

<?
// initialize var for storing possible error messages
$errmsg = '';

// check rivername
if (empty($_POST['triplocation'])) {
$errmsg .= '<font color=#FF0000><li>Your report has no [ATV area]</li></font><br>';
}

// check state
if (empty($_POST['state'])) {
$errmsg .= '<font color=#FF0000><li>Your report has no [state]</li></font><br>';
}

// check author
if (empty($_POST['author'])) {
$errmsg .= '<font color=#FF0000><li>Please identify the [trip report author]</li></font><br>';
}

// check report
if (empty($_POST['report'])) {
$errmsg .= '<font color=#FF0000><li>Please fill in your [trip report]</li></font><br>';
}

// check to see if anything was placed in our error var, meaning there was an error
if (!empty($errmsg)) {
include 'atv_form.php';

} else {
$host = "localhost";
$user = "neohoutd_nsutika";
$pass = "72spoke";
$dbname = "neohoutd_data";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$startdate = mktime(0,0,0,$TSpickMonth,$TSpickDay,$TSpickYear);
$enddate = mktime(0,0,0,$TFpickMonth,$TFpickDay,$TFpickYear);

$sql_query = mysql_query("INSERT INTO trip_log(triptype, triplocation, state, rivercondition, riverclass, triporganizer, GaugeFT, GaugeCFS, GaugeID, author, email, p1, p2, p3, p4, p5, p6, p7, p8, report, photolink, videolink1, videolink2, videolink3, miles, startdate, enddate) VALUES ('$triptype', '$triplocation', '$state', '$rivercondition', '$riverclass', '$triporganizer', '$GaugeFT', '$GaugeCFS', '$GaugeID', '$author', '$email', '$p1', '$p2', '$p3', '$p4', '$p5', '$p6', '$p7', '$p8', '$report', '$photolink', '$videolink1', '$videolink2', '$videolink3', '$miles', '$startdate', '$enddate')")
or die (mysql_error());

header("Location: /trip_log.php");
}
?>

simon2263

8:51 am on Jan 8, 2006 (gmt 0)

10+ Year Member



You need an if-statement to decide whether to display the form or process the data, along the lines of:

if (<condition>) {
// display form
}
else {
// process data
}

The condition should probably test that at least one of the form fields is empty (indicating a possible first visit to the page). Within the display form section, you would then need to distinguish between a partially-filled form and a completely empty form. Also the action on the form only needs to be "#", which indicates to the browser that the data should go back to the same page.

Otherwise, I think the code can stay as-is.

Simon