Jump to content

Recommended Posts

Hi,

 

I am trying to get this form to work however I am getting now where.

 

Part of HTML Form code


<form action="<? echo $PHP_SELF; ?>" method="post">
<input type="text" size="60" name="Title" value="<? echo $Title; ?>">
<input type="hidden" name="Returned" value="1">
<input type="hidden" name="CalendarDetailsID" value="">
<input type="hidden" name="LocationID" value="<? echo $LocationID; ?>">
<input type="submit" value="Add Event >>"></form>

Then I have some PHP code which is

if ($Returned == 1 AND !$Title) {
......

Also

} elseif ($Returned == 1) {

 

Every time I don't fill in the title it loops back to a blank form, instead of getting an error

If I do fill in the title it still loops back to the form and does not submit to database

 

What I am trying to do is use the hidden Returned code with the value 1, to submit the form to the database or give an error, but it is just looping

 

Has anyone got any ideas of the problem ?

 

I am running PHP 5.2.5 I think or that what phpinfo tells me, but cPanel tells me 5.2.3.

 

Regards,

Garry

 

Link to comment
https://forums.phpfreaks.com/topic/86628-solved-php_self-if-and-html-form/
Share on other sites

Hi,

 

The code I didn't write it a script that doesn't work so the php code for the daily event is below, hope this is what you wanted

 

if ($Returned == 1 AND !$Title) {
commonHeader($glbl_SiteTitle);
echo "<center><font color=\"red\"><b>You did not specify an EVENT NAME OR TITLE. Please complete the form below.</b></font></center><p>\n\n";

// the common data checks out, lets check our other data
} elseif ($Returned == 1) {

	// set the Active state based on the config option
	if ($glbl_ApprovePublicSubmission != 1) {
	$Active = 1;
	} else {
	$Active = 0;
	}

	// START CHECKS FOR DAILY EVENTS
	if ($EventType == "Daily") {
		// check the start date
		if (!checkdate($DailyStartMonth, $DailyStartDay, $DailyStartYear)) {
		commonHeader("Add an item");
		echo "<center><font color=\"red\"><b>You specified an INVALID START DATE. Please complete the form below.</b></font></center><p>\n\n";
		$Stop = 1;

		// check the end date
		} elseif ($DailyStopMonth AND (!checkdate($DailyStopMonth, $DailyStopDay, $DailyStopYear))) {
		commonHeader($glbl_SiteTitle);
		echo "<center><font color=\"red\"><b>You specified an INVALID END DATE. Please complete the form below.</b></font></center><p>\n\n";
		$Stop = 1;
		} 

	// Compile the dates
	$StartDate = $DailyStartYear."-".$DailyStartMonth."-".$DailyStartDay;
	$StopDate = $DailyStopYear."-".$DailyStopMonth."-".$DailyStopDay;

		// make sure the start comes before the stop
		if ($DailyStopYear) {
		$result = mysql("$DBName","SELECT (TO_DAYS('$StopDate') - TO_DAYS('$StartDate'))") or die(mysql_error());
			while ($row = mysql_fetch_row($result)) {
			$dateDiff = $row[0];
			}
		} else {
		$dateDiff = 0;
		}
        
                // somebody was trying to trick by making a stop date
        	        // before it was started
		if ($dateDiff < 0) {
		commonHeader($glbl_SiteTitle);
		echo "<center><font color=\"red\"><b>Your END DATE COMES BEFORE YOUR START DATE. Please complete the form below.</b></font></center><p>\n\n";

		// all of our checks on the surface data was good
		} elseif ($Stop != 1) {

			// check to see if the CalendarLocation already exists
			if (!$EventLocationID) {
			$result = mysql("$DBName","SELECT EventLocationID FROM phpCalendar_EventLocations WHERE
			LocationID = '$LocationID' AND Title = '$CLTitle' AND Address1 = '$Address1' AND
			Address2 = '$Address2' AND City = '$City' AND State = '$State'") or die(mysql_error());
			$CountLocations = mysql_num_rows($result);
			} else {
			$CountLocations = 99;
			}

			if ($CountLocations > 0 AND $CountLocations < 99) {
				while($row = mysql_fetch_row($result)) {
				$EventLocationID = $row[0];
				}
			} elseif ($CountLocations != 99 AND $CLTitle) {
			mysql("$DBName","INSERT INTO phpCalendar_EventLocations VALUES (
			'$CLTitle','$Address1','$Address2','$City','$State','$Zip','$LocationID','')") or die(mysql_error());

			$result = mysql("$DBName","SELECT LAST_INSERT_ID() FROM phpCalendar_EventLocations") or die(mysql_error());
				while ($row = mysql_fetch_row($result)) {
				$EventLocationID = $row[0];
				}
			}

			// if the web address doesn't begin with http://
			if ($ContactWeb AND !eregi("http://",$ContactWeb)) {
			$ContactWeb = "http://".$ContactWeb;
			}

			// format the times
			if ($StartPeriod == PM AND $StartHour != 12) {
			$StartHour += 12;
			} elseif ($StartPeriod == AM AND $StartHour == 12) {
			$StartHour = 0;
			}
			if ($EndPeriod == PM AND $EndHour != 12) {
			$EndHour += 12;
			} elseif ($EndPeriod == AM AND $EndHour == 12) {
			$EndHour = 0;
			}

		$StartTime = $StartHour.":".$StartMinute;
		$EndTime = $EndHour.":".$EndMinute;

		// we can insert now
		mysql("$DBName","INSERT INTO phpCalendar_Details VALUES (
		'$Title','$Details','$ContactName','$ContactPhone','$ContactEmail','$ContactWeb',
		'$EventLocationID','$StartTime','$EndTime','$ShowStart','$ShowEnd',
		'$LocationID','$CalendarDetailsID')") or die(mysql_error());

		$result = mysql("$DBName","SELECT LAST_INSERT_ID() FROM phpCalendar_Details") or die(mysql_error());
			while ($row = mysql_fetch_row($result)) {
			$CalendarDetailsID = $row[0];
			}

		mysql("$DBName","INSERT INTO phpCalendar_Daily VALUES(
		'$StartDate','$StopDate','$Active','$LocationID','$CalendarDetailsID')") or die(mysql_error());


			// do we send a notification and to whom?
			if ($glbl_ApprovePublicSubmission == 1 AND ($glbl_ApprovalBySiteAdmin == 1 OR !$LocationID)) {
			$MailTo = $glbl_AdminEmail;
			$AddrVar = $glbl_AdminRoot;
			} elseif ($glbl_ApprovePublicSubmission == 1) {
			$result = mysql("$DBName","SELECT Email FROM phpCalendar_AdminUsers WHERE LocationID = '$LocationID'") or die(mysql_error());
				while ($row = mysql_fetch_row($result)) {
				$MailTo = $row[0];
				}

			$AddrVar = $glbl_WebAdminRoot;
			}

			// what if we still don't have an address?
			if (!$MailTo) {
			$MailTo = $glbl_AdminEmail;
			$AddrVar = $glbl_AdminRoot;
			}

$Message = "
A request has been generated from your web site for
a calendar submission to be approved. Visit the address:
".$glbl_WebAddress.$AddrVar."

Once logged in, select the \"Pending event administration\"
link.

Thank you.
";

		mail($MailTo, $glbl_EmailSubject, $Message, "From: $glbl_MailFrom", "-f$MailTo");

		Header("Location: ./thankyou.php?LocationID=$LocationID");
		exit;
		}
		// END CHECKS FOR DAILY EVENTS

 

Regards,

Garry

Hi,

 

Thought I would post the form code to

 

<form action="<? echo $PHP_SELF; ?>" method="post">


<center>

<!-- TABLE FOR DAILY EVENTS -->
<center>
<table width="100%" border="0" cellpadding="4" bgcolor="#C9C9C9">
<tr>
<td valign="top" colspan="2"><center>
<b>One-Time Events</b>
</center></td>
</tr>
<tr>
<td valign="top" colspan="2">
<?
if ($EventType == "Daily") {
echo "<input type=\"radio\" name=\"EventType\" value=\"Daily\" CHECKED> ";
} else {
echo "<input type=\"radio\" name=\"EventType\" value=\"Daily\"> ";
}
?>
Check here if this is a one-time event or multiple day event that will only happen once.
  <a href="./calDaily.php" onClick=return(openSmallWindow('./calDaily.php'))>What's This?</a>
</td></tr>

<tr>
<td valign="top"><b>Start date:</b><br>
<?
if (!$DailyStartYear) {
$DailyStartYear = date("Y");
}
if (!$DailyStartMonth) {
$DailyStartMonth = date("m");
}
if (!$DailyStartDay) {
$DailyStartDay = date("d");
}

// get the month
echo "<select name=\"DailyStartMonth\">\n";
for ($i = 1; $i <= 12; $i++) {	
	if ($i < 10 AND !ereg("^0",$i)) {
	$i = "0".$i;
	}
$showMonth = date("F",mktime(0,0,0,$i,1,date("Y")));
	if ($DailyStartMonth == $i) {
	echo "<option value=\"$i\" SELECTED> $showMonth </option>\n";
	} else {
	echo "<option value=\"$i\"> $showMonth </option>\n";
	}
}
echo "</select>  \n\n";

// get the day
echo "<select name=\"DailyStartDay\">\n";
for ($i = 1; $i <= 31; $i++) {	
	if ($i < 10 AND !ereg("^0",$i)) {
	$i = "0".$i;
	}
$showDay = date("dS",mktime(0,0,0,01,$i,$DailyStartYear));
	if ($DailyStartDay == $i) {
	echo "<option value=\"$i\" SELECTED> $showDay </option>\n";
	} else {
	echo "<option value=\"$i\"> $showDay </option>\n";
	}
}
echo "</select>  \n\n";

// get the year
echo "<select name=\"DailyStartYear\">\n";
for ($i = (date("Y") - 1); $i <= (date("Y") + 5); $i++) {	

	if ($DailyStartYear == $i) {
	echo "<option value=\"$i\" SELECTED> $i </option>\n";
	} else {
	echo "<option value=\"$i\"> $i </option>\n";
	}
}
echo "</select>  \n\n";
?>
</td>

<td valign="top"><b>End date:</b><br>
<?
// get the month
echo "<select name=\"DailyStopMonth\">\n";
echo "<option value=\"\"> None </option>\n";
for ($i = 1; $i <= 12; $i++) {	
	if ($i < 10 AND !ereg("^0",$i)) {
	$i = "0".$i;
	}
$showMonth = date("F",mktime(0,0,0,$i,1,date("Y")));
	if ($DailyStopMonth == $i) {
	echo "<option value=\"$i\" SELECTED> $showMonth </option>\n";
	} else {
	echo "<option value=\"$i\"> $showMonth </option>\n";
	}
}
echo "</select>  \n\n";

// get the day
echo "<select name=\"DailyStopDay\">\n";
echo "<option value=\"\"> None </option>\n";
for ($i = 1; $i <= 31; $i++) {	
	if ($i < 10 AND !ereg("^0",$i)) {
	$i = "0".$i;
	}
$showDay = date("dS",mktime(0,0,0,01,$i,$DailyStartYear));
	if ($DailyStopDay == $i) {
	echo "<option value=\"$i\" SELECTED> $showDay </option>\n";
	} else {
	echo "<option value=\"$i\"> $showDay </option>\n";
	}
}
echo "</select>  \n\n";

// get the year
echo "<select name=\"DailyStopYear\">\n";
echo "<option value=\"\"> None </option>\n";
for ($i = (date("Y") - 1); $i <= (date("Y") + 5); $i++) {	

	if ($DailyStopYear == $i) {
	echo "<option value=\"$i\" SELECTED> $i </option>\n";
	} else {
	echo "<option value=\"$i\"> $i </option>\n";
	}
}
echo "</select>  \n\n";
?>
</td>
</tr>
</table>
</center>
<center>
<input type="hidden" name="Returned" value="1">
<input type="hidden" name="CalendarDetailsID" value="">
<input type="hidden" name="LocationID" value="<? echo $LocationID; ?>">
<input type="submit" value="Add Event >>">
</form>

 

Regards,

Garry

when you post a form you need to define the information that is being sent

 

For example you are sending the feild from your form called Returned. When you want to call on that information from that feiled you need to do something like

 

$return = $_POST['Returned']

 

that sets $return to = the information from the feiled Returned in your form

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.