Results 1 to 2 of 2

Thread: Php form field issue with date/time picker.

  1. #1
    Join Date
    Sep 2011
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Php form field issue with date/time picker.

    If it isn't a php problem I am sorry just let me know where to post it. I have a form that I am working on for submitting an incident report. I have a working version with straight text boxes that works with PHP just fine. However, I just added the Any+Time™ DatePicker/TimePicker to the form. I have the pickers working great, however when I click submit the fields go blank and return to the form as though they were not filled in. How do I fix it so the text in the fields submit to the form and pass through the array? the form is located at http://www.dacc.edu/documents/incident_report2.php

    Any help pointing me in the right direction would be appreciated. Thanks in advance!
    Code:
     
    	<?php
    		$problems = array();
    		$showform = 0;
    		 $errorMessage = "";
    		
    		function validate($field, $value) {
    		
    			
    				if ($value == "") {
    					return 0;
    				} else {
    					return 1;
    				}
    				}
    			if($_POST) {
    		
    		$fields = array('name','title', 'date', 'time',  'building', 'room', 'location', 'occurrence','person', 'title1', 'phone1', 'explanation', 'security', 'police', 'witness', 'acttaken', 'followact');
    			$x = 0 - 1;
    			
    			foreach($fields as $field) {
    			
    				if(isset($_POST[$field])) {
    					$validation = validate($field, $_POST[$field]);
    					if ($validation == 1) {
    						$x++;	
    						$info[$x] = $_POST[$field];
    					} else {
    						$problems[$field] = 1;
    						$showform = 1;
    					}
    				} else {
    					$problems[$field] = 1;
    					$showform = 1;
    				}
    			}
    		
    		} else {
    			$showform = 1;
    		}
    		
    		if(count($problems) < 1 && $_POST) {
    		
    			// DO THE MAILING HERE
    
    			$fields = array('title', 'name','date', 'time', 'building', 'room', 'location', 'title1','person',  'phone1', 'title2', 'person2', 'phone2','title3','person3',  'phone3','title4','person4',  'phone4','occurrence','obscene','altercation1', 'altercation2', 'sexharass', 'property', 'harm', 'drugs', 'other',  'explanation', 'security', 'police', 'witness','wtitle1', 'wperson',  'wphone1', 'wtitle2', 'wperson2', 'wphone2','wtitle3','wperson3',  'wphone3', 'acttaken', 'followact');
    			
    			
    			$to2 = "aabdelzaher@dacc.edu";
    		
    			$subject = "Incident / Unusual Occurrence Report";
    			$headers  ='MIME-Version: 1.0' .PHP_EOL;
    			$headers .='Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
    			$headers .= "From: noreply@dacc.edu\r\n" . "X-Mailer: php";
    			$greet = "The following was submitted on " . date("F j, Y, g:i a") . "<p><p>";
    			
    
    			$body =   $greet  ; 
    		
    
    			$cn = 1;
    	
    			
    			foreach($fields as $efield) {
    			
    				
    				if(isset($_POST[$efield])) {
    				
    					if($efield == "type3" || $efield == "type4" || $efield == "type5" || $efield == "type6" || 	$efield == "type7" || $efield == "type8" || $efield == "type9" ) {
    						$body.= "<strong>". "Type of Occurrence:".  "</strong> &nbsp;&nbsp;" . $_POST[$efield] . "<p>";
    							$cn++;
    						
    
    
    						} elseif($efield == "title") {
    							$body.= "<strong>"."Name of Person Filing Report: " ."</strong>" . $_POST[$efield] 	" ";
    
    						} elseif($efield == "name") {
    							$body.= "   " . $_POST[$efield] . "<p><hr color=' #33cc66'>";					
    						} elseif($efield == "date") {
    							$body.= "<strong>". "Date of Occurrence : "."</strong>" . $_POST[$efield] . " &nbsp; ";
    			                       } elseif ($efield == "time") {
    							$body.= "<strong>"."Time: " ."</strong>". $_POST[$efield] . "</p>";
    						} elseif ($efield == "building") {
    							$body.= "<strong>"."Building: ". "</strong>" . $_POST[$efield] . " &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;  ";
    						} elseif ($efield == "room") {
    							$body.= "<strong>"."Room: "."</strong>" . $_POST[$efield] . "<p>";
    						} elseif ($efield == "location") {
    							$body.= "<strong>"."Description of Location: ". "</strong>" . $_POST[$efield] . "<p><hr color=' #33cc66'>";
    						} elseif ($efield == "title1") {
    							$body.= "<strong>"."First Person involved: ". "</strong>" . $_POST[$efield] . "&nbsp;&nbsp; ";
    						} elseif ($efield == "person") {
    							$body.= "&nbsp;&nbsp;&nbsp;" . $_POST[$efield] . "<p>";
    									
    						} elseif ($efield == "phone1") {
    							$body.= "<strong>". "Phone : ". "</strong>" . $_POST[$efield] . "<p><hr color=' #33cc66'>";
    						}  elseif ($efield == "explanation") {
    							$body.= "<strong>"."Detailed Explanation: ". "</strong>" . $_POST[$efield] . "<p><hr color=' #33cc66'>";
    						} elseif ($efield == "security") {
    							$body.= "<strong>"."Security called: ". "</strong>" . $_POST[$efield] . "<p>";
    						} elseif ($efield == "police") {
    		                                	$body.= "<strong>"."Police called: "."</strong>" . $_POST[$efield] . "<p>";
    						} elseif ($efield == "witness") {
    							$body.= "<strong>"."Were there witnesses: "."</strong>" . $_POST[$efield] . "<p><hr color=' #33cc66'>";
    						} elseif($efield == "wtitle1" && $_POST[$efield] != '') {
    							$body.= "<strong>"."Witness: "."</strong>" . $_POST[$efield] . "&nbsp;&nbsp; ";
    						} elseif($efield == "wperson" && $_POST[$efield] != '') {
    							$body.= "&nbsp;&nbsp;" . $_POST[$efield] . "<p>";
    						} elseif($efield == "wphone1" && $_POST[$efield] != '') {
    							$body.= "<strong>"."Phone : "."</strong>" . $_POST[$efield] . "<p><hr color=' #33cc66'>";
    						 }elseif($efield == "wtitle2" && $_POST[$efield] != '') {
    							$body.= "<strong>"."Second witness: ". "</strong>" . $_POST[$efield] . "&nbsp;&nbsp; ";
    						} elseif($efield == "wperson2" && $_POST[$efield] != '') {
    							$body.= " &nbsp;&nbsp; " . $_POST[$efield] . "<p>";
    						} elseif($efield == "wphone2" && $_POST[$efield] != '') {
    							$body.= "<strong>"."Phone : ". "</strong>" . $_POST[$efield] . "<p><hr color=' #33cc66'>";
    				
    						} elseif($efield == "wtitle3" && $_POST[$efield] != '') {
    							$body.="<strong>". "Third witness: ". "</strong>" . $_POST[$efield] . " &nbsp;&nbsp; ";
    						} elseif($efield == "wperson3" && $_POST[$efield] != '') {
    							$body.= "&nbsp;&nbsp;  " . $_POST[$efield] . "<p>";
    				
    						} elseif($efield == "wphone3" && $_POST[$efield] != '') {
    							$body.= "<strong>". "Phone: "."</strong>" . $_POST[$efield] . "<p><hr color=' #33cc66'>";
    						} elseif ($efield == "acttaken") {
    							$body.= "<strong>"."Immediate Action Taken: " ."</strong>". $_POST[$efield] . "<p><hr 	color=' #33cc66'>";
    						} elseif ($efield == "followact") {
    							$body.= "<strong>". "What Follow-up Action will be taken: " "</strong>". $_POST[$efield] . "<p><hr color=' #33cc66'>";
    }
    				}
    			}
    			
    			//mail($to, $subject, $body, $headers);
    			mail($to2, $subject, $body, $headers);
    		//	mail($to3, $subject, $body, $headers);
    			?>
    			<p class="style1">Your report has been submitted.<br><br></p>
    			<?php
    		
    		}
    		
    		if($showform == 1) {
    	?>
    	
    	<?php if(count($problems) > 0) { ?>
    		<p><strong><font color="red">PLEASE CORRECT ANY FIELDS WITH A RED * BY 
    		THEM</font></strong></p>
    	<?php } ?></font></p>
    
    
    
    	<form action="" method="post" name="incidentreport" onSubmit="return IsValidTime(document.incidentreport.time.value);">
    
    		<fieldset>
    			<legend>
    				<span lang="en-us">Incident Report</span>
    			</legend>
    						<div class="style6">
    						<div class="style6">
    			<div class="style7">
    			<br>
    	<table style="width: 100%">
    		<tr>
    			<td style="width: 248px" class="style1"><font size="-1" face="Arial, Helvetica, sans-														serif" align="left">
    				<label class="formtext" for="name">Name(s):<span lang="en-us">(required)</span> <?php 							if(isset($problems['name'])) {?><font color="red">*</font><?php } ?></label><br>
    			
    				<input class="inputstyle" type="text" name="name" value="<?php 	  if(isset($_POST['name'])){ print($_POST['name']); }?>" style=" width: 288px">     								</font>
    			</td>
    			
    			<td style="width: 148px" class="style1"><font size="-1" face="Arial, Helvetica, sans-serif" 			 			align="left">
    						
    				<label class="formtext" for="title">Title:(required) <?php if(isset($problems['title'])) {?><font 				color="red">*</font><?php } ?></label><br>
    			
    				<input class="style6" type="text" name="title" value="<?php if(isset($_POST['title'])){ 				   								     print($_POST['title']); }?>" style=" width: 132px"></font>
     			</td>	
    		</tr>
    	</table>
    		
    		
    		<p>
    		</p>
    		
    	<table >
    		<tr>
    			<td style="width: 272px" class="style6"><font size="-1" face="Arial, Helvetica, sans-serif" >
    			
    				
    				<label class="formtext" for="date" >Date of Occurrence:(required) <?php  if(isset($problems['date'])) {?><font 								color="red">*</font><?php } ?><br></label>
    				<input type="text" id="date" size=20   value="<?php if(isset($_POST['date'])){ 				                            print($_POST['date']); }?>" style="width: 229px" >
    	</font></td>
    			<td style="width: 154px" class="style1"><font size="-1" face="Arial, Helvetica, sans-serif" 								          align="left">
    		
    
     	<label class="formtext" for="time">Time of Occurrence: <?php if(isset($problems['time'])) {?><font color="red">*</font><?php } ?></label><br>
    
    	</font><span class="style8">
    <input type="text" id="time" value="<?php if(isset($_POST['time'])){ 				                          print($_POST['time']); }?>"> </span></td></tr>		
    		
    
    	<script type="text/javascript">
      AnyTime.picker( "date",
        { format: "%W, %M %d, %Y", firstDOW: 1 } );
      $("#time").AnyTime_picker(
        { format: "%h:%i:%p", labelTitle: "Time",
          labelHour: "Hour", labelMinute: "Minute" }
    Last edited by Inky1231; 02-06-2012 at 08:59 PM. Reason: fixing format

  2. #2
    Join Date
    Sep 2011
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I figured out what was wrong, the form field had an ID but not a name It's all good now

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •