PHP Array/WordPress/Form Processing Problem

This is a little tricky to explain, so I'll try to be as clear as possible.

I have 2 forms that work on an existing website. They are written in PHP. I'm trying to move them into a WordPress installation using exec-php plugin to run the php within the pages.The forms render  correctly, but when I try to submit them, only 1 or 2 of the required fields ask for verification, and only 3 of the required fields are being written to the database. I'm getting the following error messages from CheckRequiredFields_func.php upon submission:

Warning: reset() [function.reset]: Passed variable is not an array or object in /var/www/html/beta/functions/CheckRequiredFields_func.php  on line 21

Warning: Variable passed to each() is not an array or object in /var/www/html/beta/functions/CheckRequiredFields_func.php on line 23

As far as I can tell, there is nothing wrong with the arrays. I can get them to print.

I've attached the entire code for the file CheckRequiredFields_func.php.

I've also attached the entire code for one of the submission forms.They both generate the same type of errors.

You can see the problems in action here.

I'm trying to avoid having to re-write this stuff, but if I have to, so be it.

Thanks in advance for any help.

Lisa



<?
/*
  +----------------------------------------------------------------------+
  CheckRequiredFields:
    - checks required fields to ensure some value has been entered
  
  Input:
    none
  
  Output:
    $errors (an array of error messages)
  
  Notes:
    - uses strlen() as check
  
  Last Modified: 06.21.01 (Mike Angel)
  +----------------------------------------------------------------------+
*/
global $required_fields;

reset($required_fields);

while(list($key,$value) = each($required_fields)){
  //must set to global to access
  global ${$key};
  
  if (strlen($_POST[$key]) < 1 or (eregi("^file|image",$key) and !is_uploaded_file($_FILES[$key]['tmp_name']))){
    //add error
    $errors[] = 'Please complete missing info: <span class="yellowtext"><b>'.$value.'</b></span>';
    }
  }

return $errors;
?>

Open in new window

report-a-litterer.php
lisacowanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

drunkenmsCommented:
These warnings shows to you all your mistakes. At first try to check $required_fields by code "var_dump($required_fields);" after stroke "global $required_fields;". In your example we must be sure about array values in your function.

Also as small tip to you. Before using functions for arrays. Try check variables for array type. Like code here:Snippet ID=601845
<?
/*
  +----------------------------------------------------------------------+
  CheckRequiredFields:
    - checks required fields to ensure some value has been entered
  
  Input:
    none
  
  Output:
    $errors (an array of error messages)
  
  Notes:
    - uses strlen() as check
  
  Last Modified: 06.21.01 (Mike Angel)
  +----------------------------------------------------------------------+
*/
global $required_fields;

if(is_array($required_fields)){ //$required_fields is array?
  reset($required_fields);

  while(list($key,$value) = each($required_fields)){
    //must set to global to access
    global ${$key};
  
    if (strlen($_POST[$key]) < 1 or (eregi("^file|image",$key) and !is_uploaded_file($_FILES[$key]['tmp_name']))){
    //add error
      $errors[] = 'Please complete missing info: <span class="yellowtext"><b>'.$value.'</b></span>';
      }
    }
} else {
  $errors[] = '$required_fields is not Array'; //if not we must know about it
}

return $errors;
?>

Open in new window

0
lisacowanAuthor Commented:
Thanks for the input.

These changes confirmed that the file CheckRequiredFields_func.php does not see the variable $required_fields as an array. What I don't understand is why these files work just fine in another part of the site (outside of WordPress) but on the same server. Also, if I add the var_dump($required_fields); statement to the form, report-a-litterer.php, I get the var dump.

Do you have any other suggestions as to what is going on? I'm not sure how to implement your javascript tip.

Thanks,
Lisa
0
NerdsOfTechTechnology ScientistCommented:
How are you populating the array that you globalized? Can you post entire code? Are you posting from another page etc? Thanks.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

lisacowanAuthor Commented:
The array is being populated at the very top of the attached code snippet.

Lisa

<?php


//FORM PROCESSING FROM OLD SITE -- DO NOT TOUCH------------------------------------------
//FORM PROCESSING FROM OLD SITE -- DO NOT TOUCH------------------------------------------
//FORM PROCESSING FROM OLD SITE -- DO NOT TOUCH------------------------------------------


require('includes/config.php');
require('includes/functions.php');
//TrapOldBrowsers();
require('includes/mysql_connect.php');

//process form?
if (array_key_exists('_submitted',$_POST)) {
  $required_fields = array(
                           'gotcha_date'   => 'Date',
                           'gotcha_time'   => 'Time',
                           'ampm'          => 'AM/PM',
                           'location'      => 'Location',
                           'license_plate' => 'License plate #',
                           'make_car'      => 'Make of car',
                           'what_littered' => 'What was littered',
                           'who_littered'  => 'Who littered'
                           );
  
  //check required fields
  $errors = CheckRequiredFields();
  
  //validate date
  $gotcha_date = $_POST['gotcha_date'];
  if (preg_match("/^\d{1,2}\/\d{1,2}\/\d{4}$/",$gotcha_date)) {
    $temp = explode('/',$gotcha_date);
    if (!checkdate($temp[0],$temp[1],$temp[2])) {
      $errors[] = 'Date is invalid: <span class="yellowtext"><b>'.$gotcha_date.'</b></span>';
    }
  } else {
    $errors[] = 'Dates must be in the following format: <span class="yellowtext"><b>MM/DD/YYYY</b></span>';
  }
  
  //validate time
  $gotcha_time = $_POST['gotcha_time'];
  if (preg_match("/^\d{1,2}:\d{2}$/i",$gotcha_time)) {
    $temp = explode(":",$gotcha_time);
    if (!($temp[0] >= 0 and $temp[0] < 25 and $temp[1] >= 0 and $temp[1] < 60)) {
      $errors[] = 'Time is invalid: <span class="yellowtext"><b>'.$gotcha_time.'</b></span>';
    }
  } else {
    $errors[] = 'Time must be in the following format: <span class="yellowtext"><b>HH:MM</b></span>';
  }
  
  //validate license plate
  if (preg_match("/[^[:alnum:]]/",$license_plate)) {
    $errors[] = 'License plate is invalid: <span class="yellowtext"><b>Please use capital letters, no spaces and no dashes.</b></span>';
  }
  
  if (count($errors) < 1){
    //stripslashes
    StripslashesAll();
	
	$sql = "INSERT INTO gotcha (date_occurred, time_occurred, location, license, car_make, what_littered, who_littered, comments, created, status) VALUES ('". addslashes($gotcha_date) ."', '". addslashes($gotcha_time .' '. $ampm) ."', '". addslashes($location) ."', '". addslashes(strtoupper($license_plate)) ."', '". addslashes($make_car) ."', '". addslashes($what_littered) ."', '". addslashes($who_littered) ."', '". addslashes($comments) ."', NOW(), 0)";
    mysql_query($sql);
	
    //send email
    //$to       = "dcarter@enviromedia.com";
    $to       = "info@dontmesswithtexas.org";
    $subject  = "Don't Mess With Texas - Report a Litterer";
    $body     = "Date: $gotcha_date\n";
    $body    .= "Time: $gotcha_time $ampm\n";
    $body    .= "Location: $location\n";
    $body    .= "License plate #: $license_plate\n";
    $body    .= "Make of car: $make_car\n";
    $body    .= "What was littered: $what_littered\n";
    $body    .= "Who littered: $who_littered\n";
    $body    .= "Comments:\n";
    $body    .= "--- $comments\n\n";
    $body    .= $VOTE_TEXT;
    $headers  = "From: info@dontmesswithtexas.org\n";
    mail($to, $subject, $body, $headers);
    
    //set success flag
    $success = true;
    }
  else{
    
    // convert license plate to all caps
    $license_plate = strtoupper($license_plate);
    }
  }
  
  


//END FORM PROCESSING----------------------------------------------------------
//END FORM PROCESSING----------------------------------------------------------
//END FORM PROCESSING----------------------------------------------------------








?>

	<h2 id="top">Report a Litterer</h2>
	
<?
//IF SUCCESS --------------------------------------------------------
//IF SUCCESS --------------------------------------------------------
//IF SUCCESS --------------------------------------------------------

if ($success){
  ?>
  <p><strong>Message received!</strong></p>
  <p>Thanks for your report. Your commitment to litter prevention is appreciated. Please let your family and friends know about this page and how they can report litterers.  Together we can make a difference in the Lone Star State.</p>
  <?
  }
else{
}


//IF NOT SUCCESS --------------------------------------------------------
//IF NOT SUCCESS --------------------------------------------------------
//IF NOT SUCCESS --------------------------------------------------------

if (!$success){
	if (!count($errors)) {
?>
<p class="big">While some Texans enjoy a hearty game of backyard washer toss, others prefer something far more sinister: the one-two trash toss from their car windows. We&#8217;re talking about cigarette butts, fast-food wrappers and the like. They&#8217;re small, but they&#8217;re still trash.</p>
 
<p>So what do you do when you see trash being tossed out of a car window or accidentally flying out of a truck bed? Instead of hog-tying the offender to your car, we suggest turning them in through the Texas Department of Transportation&#8217;s Report a Litterer Program.</p>
            
<ol>
	<li>
		<p>When you see litter exit a vehicle, intentionally or accidentally, write down the following information&mdash;license plate number, make and color of vehicle, date and time, location, who tossed the litter and what was tossed. Now fill in below; be as accurate as possible and submit:</p>
    <ul>
     	<li>Texas license plate number (Texas plates only)</li>
        <li> Make of vehicle </li>
        <li>Time of day</li>
        <li> Location</li>
        <li> Date</li>
        <li> Who tossed (driver, passenger or accidental)</li>
        <li> What was tossed</li>
      </ul>
    </li>
    
    <li>TxDOT compares the information to our vehicle registration database and when an exact match is located, we send the litterer a Don't Mess with Texas litterbag along with a letter reminding them to keep their trash off of our roads.</li>
</ol> 

<p>And you can feel good about doing something to clean up our beloved Lone Star State.</p>
<p><a href="faqs.php">FAQ</a></p>

<?php
	}//close if no errors
	//error messages
	if (count($errors)){
	?>
	<h3>Please note the problems listed below:</h3>
	<ul>
	<?
	while(list($key, $value) = each($errors)){ print('<li class="alertBad">'.$value.'</li>'); }
	echo '</ul>';
	}//close if errors
	?>

    <form method="post" action="<? print($PHP_SELF); ?>" name="form">
	<input type="hidden" name="_submitted" value="1"/>
	
	<ul>

		<li><strong>*Indicates a required field. This form is intended for use of reporting litterers only.</strong></li>
		
        <li>Information about the littering incident:</li>
        
        
        <li>
        	<label for="gotcha_date"><? RequiredField($action,$gotcha_date,'Date'); ?></label>
			<input type="text" name="gotcha_date" maxlength="32" value="<?= $gotcha_date ?>">
			<span class="smalltext">MM/DD/YYYY</span>
		</li>
				
				
		<li>	
		  	<label for="gotcha_time"><? RequiredField($action,$gotcha_time,'Time'); ?></label>
		  	<input type="text" name="gotcha_time" maxlength="32" value="<?= $gotcha_time ?>">
		  	<span class="smalltext">HH:MM</span>
		</li>
		  	
		<li>	  	
			<label for="ampm">*AM/PM</label>
            <select name="ampm">
            <option value=""></option>
            <option value="AM"<? if ('AM' == $ampm) print(' selected'); ?>>AM</option>
            <option value="PM"<? if ('PM' == $ampm) print(' selected'); ?>>PM</option>
            </select><br />
		</li>


		<li>
			  <label for="location"><? RequiredField($action,$location,'Location'); ?></label>
              <input type="text" name="location" maxlength="255" value="<?= $location ?>">
        </li>      
              
              
		<li>
			  <label for="license_plate"><? RequiredField($action,$license_plate,'License plate #'); ?></label>
              <input type="text" name="license_plate" maxlength="32" value="<?= $license_plate ?>">
			  <span class="smalltext">Please use capital letters, no spaces and no dashes.</span>
        </li>      
             
              
        <li>      
			  <label for="make_car"><? RequiredField($action,$make_car,'Make of car'); ?></label>
              <input type="text" name="make_car" maxlength="32" value="<?= $make_car ?>">
        </li>  
              
              
        <li>      
			  <label for="what_littered"><? RequiredField($action,$what_littered,'What was littered'); ?></label>
              <select name="what_littered">
              <option value="">please select</option>
              <option value="Cigarette butt"<? if ('Cigarette butt' == $what_littered) print(' selected'); ?>>Cigarette butt</option>
              <option value="Cup/can/bottle"<? if ('Cup/can/bottle' == $what_littered) print(' selected'); ?>>Cup/can/bottle</option>
              <option value="Misc. trash"<? if ('Misc. trash' == $what_littered) print(' selected'); ?>>Misc. trash</option>
              <option value="Fast food trash"<? if ('Fast food trash' == $what_littered) print(' selected'); ?>>Fast food trash</option>
              </select>
        </li>
          
              
        
        <li>      
			  <label for="who_littered"><? RequiredField($action,$who_littered,'Who littered'); ?></label>
              <select name="who_littered">
              <option value="">please select</option>
              <option value="Driver"<? print($who_littered == 'Driver' ? ' selected' : ''); ?>>Driver</option>
              <option value="Passenger"<? print($who_littered == 'Passenger' ? ' selected' : ''); ?>>Passenger</option>
              <option value="Truck Bed"<? print($who_littered == 'Truck Bed' ? ' selected' : ''); ?>>Truck Bed</option>
              </select>
	    </li>


		<li>
              <label for="comments">Comments</label>
              <textarea name="comments"><?= $comments ?></textarea>
      </li>
           
           
      <li>         
            <input type="submit" name="action" value="Send" class="submitbtn" />
			<input type="reset" name="Clear" value="Clear" class="submitbtn" />
	  </li>
</ul>
</form>

	


<?php
}//close if not success
?>

Open in new window

0
drunkenmsCommented:
Liza, can you populate to us code for these function? "CheckRequiredFields();"
0
lisacowanAuthor Commented:
CheckRequiredFields(); first shows up in the attached code file.
<?

function TrapOldBrowsers(){ global $FUNCTION_PATH; return include('../TrapOldBrowsers_func.php'); }
function UnsetAll(){ global $FUNCTION_PATH; return include('functions/UnsetAll_func.php'); }
function StripslashesAll(){ global $FUNCTION_PATH; return include('functions/StripslashesAll_func.php'); }
function RequiredField($action,$field,$title,$field_type = ''){ global $FUNCTION_PATH; return include('functions/RequiredField_func.php'); }
function CheckRequiredFields(){ global $FUNCTION_PATH; return include('functions/CheckRequiredFields_func.php'); }
function CheckRequiredFieldsEspanol(){ global $FUNCTION_PATH; return include('functions/CheckRequiredFieldsEspanol_func.php'); }
function ValidEmailFormat($email){ global $FUNCTION_PATH; return include('functions/ValidEmailFormat_func.php'); }
function FormatInput($string){ global $FUNCTION_PATH; return include('functions/FormatInput_func.php'); }
function UnFormatInput($string){ global $FUNCTION_PATH; return include('functions/UnFormatInput_func.php'); }
function PadString($string,$char,$length){ global $FUNCTION_PATH; return include('functions/PadString_func.php'); }
function SelectYear($selected_year,$number_of_years,$offset = 0){ global $FUNCTION_PATH; return include('functions/SelectYear_func.php'); }
function SelectMonth($selected_month){ global $FUNCTION_PATH; return include('functions/SelectMonth_func.php'); }
function SelectDay($selected_day){ global $FUNCTION_PATH; return include('functions/SelectDay_func.php'); }
function AddslashesArray($array) { global $FUNCTION_PATH; return include('functions/AddslashesArray_func.php'); }
function SelectStateNoDB($selected_state){ global $FUNCTION_PATH; return include('functions/SelectStateNoDB_func.php'); }
function CleanFilename($string) { global $FUNCTION_PATH; return include('functions/CleanFilename_func.php'); }
function ClearPost() { global $FUNCTION_PATH; return include('functions/ClearPost_func.php'); }
function ConvertQuotes($string) { global $FUNCTION_PATH; return include('functions/ConvertQuotes_func.php'); }
function ConvertToMySQLDate($string) { global $FUNCTION_PATH; return include('functions/ConvertToMySQLDate_func.php'); }
function FormField($title, $invalid, $required = false) { global $FUNCTION_PATH; return include('functions/FormField_func.php'); }
function FormField2($title, $invalid, $required = FALSE) { global $FUNCTION_PATH; return include('functions/FormField_func.php'); }
function GetPost($allowable_tags = '<a><b><i><u><br><p><ul><ol><li><span>') { global $FUNCTION_PATH; return include('functions/GetPost_func.php'); }
function ReturnPost() { global $FUNCTION_PATH; return include('functions/ReturnPost_func.php'); }
function ValidFormat($string, $type, $regex = '') { global $FUNCTION_PATH; return include('functions/ValidFormat_func.php'); }
?>

Open in new window

0
drunkenmsCommented:
Liza, your mistake at this position:

7 stroke:
function CheckRequiredFields(){
global $FUNCTION_PATH;
//you use global for $FUNCTION_PATH, but not using for your $required_fields, and as result, your included code is evaluating in the local space of the function CheckRequiredFields()
return include('functions/CheckRequiredFields_func.php');
}

for check this, try:
- one:
in that function CheckRequiredFields, add argument like local copy of  $required_fields:

function CheckRequiredFields($required_fields){...


and later use that function as:
...
$errors = CheckRequiredFields($required_fields);
...

Also in your file CheckRequiredFields_func.php you can commented global $required_fields;


as second tip, try:
in your function CheckRequiredFields, type this:

function CheckRequiredFields(){
global  $FUNCTION_PATH;
 global $required_fields;
CheckRequiredFields()
return  include('functions/CheckRequiredFields_func.php');
}

I think that may be help $)
0
lisacowanAuthor Commented:
Thanks again for the input, but it doesn't seem to be helping. I'm getting some new error messages and they page is not rendering at all. What I still don't understand is why the page works on another part of the site, just not here. Do you have any suggestions for that?

Lisa
0
drunkenmsCommented:
1. What errors, do you have?

2. This code working on another part with initial condititions?

Can you show code of that another part?
0
lisacowanAuthor Commented:
Thanks again for the help.

1. You can see the errors by trying to submit the form.

http://dontmesswithtexas.org/beta/?page_id=24

2. Yes, the code works on the other part of the site with the initial conditions.

http://www.dontmesswithtexas.org/report-a-litterer.php.

Please do not submit this form. It is live for the client.
0
gwkgCommented:
I would try disabling all plugins or changing the name of the $required_fields variable, just to rule out a conflict.
0
lisacowanAuthor Commented:
I've tried all of the suggestions here and then some. So, I rewrote the form to simplifiy it as a restart. It is still not writing to the database, I can't figure out why.The code is very basic, and I don't see any syntax errors. I'm also not getting any errors from ini_set....

Any other ideas?

Thanks in advance!

Lisa


<?php

/* This script adds an entry to the database */

ini_set ('display_errors', 1);

if(isset($_POST['submitted'])) { // handle the form

 $comments = $_POST['comments'];

	// connect and select:
	//deleted for security
	
	//Validate the form data:
	$problem = FALSE;
	if (!empty($_POST['date_occurred']) ) {
		$date_occurred = mysql_real_escape_string(trim($_POST['date_occurred']));
	} else {
		print '<p class="error">Please enter the date of the offense.</p>';
		$problem = TRUE;
	}
	
	if (!empty($_POST['time_occurred']) ) {
		$time_occurred = mysql_real_escape_string(trim($_POST['time_occurred']));
	} else {
		print '<p class="error">Please enter the time.</p>';
		$problem = TRUE;
	}
	
	if (!empty($_POST['ampm']) ) {
		$ampm = mysql_real_escape_string(trim($_POST['ampm']));
	} else {
		print '<p class="error">Please enter AM or PM.</p>';
		$problem = TRUE;
	}
	
	if (!empty($_POST['location']) ) {
		$location = mysql_real_escape_string(trim($_POST['location']));
	} else {
		print '<p class="error">Please enter the location.</p>';
		$problem = TRUE;
	}

	
	if (!empty($_POST['license']) ) {
		$license = mysql_real_escape_string(trim($_POST['license']));
	} else {
		print '<p class="error">Please enter the license plate.</p>';
		$problem = TRUE;
	}
	
		if (!empty($_POST['car_make']) ) {
		$car_make = mysql_real_escape_string(trim($_POST['car_make']));
	} else {
		print '<p class="error">Please enter the car make.</p>';
		$problem = TRUE;
	}
	
	
	if (!empty($_POST['what_littered']) ) {
		$what_littered = mysql_real_escape_string(trim($_POST['what_littered']));
	} else {
		print '<p class="error">Please enter what was littered.</p>';
		$problem = TRUE;
	}
	
	
	if (!empty($_POST['who_littered']) ) {
		$who_littered = mysql_real_escape_string(trim($_POST['who_littered']));
	} else {
		print '<p class="error">Please enter your who littered.</p>';
		$problem = TRUE;
	}
	
	if (!$problem) {//there is no problem so insert into database
	
		  
	
	$sql = "INSERT INTO gotcha (gotcha_id, date_occurred, time_occurred, location, license, car_make, what_littered, who_littered, comments, created, status) VALUES ('','$date_occurred', '$time_occurred', '$ampm', '$location', '$license', '$car_make', 'addslashes', '$who_littered', '$comments', NOW(), 0)";
	
    //send email
    //$to       = "dcarter@enviromedia.com";
    $to       = "info@dontmesswithtexas.org";
    $subject  = "Don't Mess With Texas - Report a Litterer";
    $body     = "Date: $gotcha_date\n";
    $body    .= "Time: $gotcha_time $ampm\n";
    $body    .= "Location: $location\n";
    $body    .= "License plate #: $license_plate\n";
    $body    .= "Make of car: $make_car\n";
    $body    .= "What was littered: $what_littered\n";
    $body    .= "Who littered: $who_littered\n";
    $body    .= "Comments:\n";
    $body    .= "--- $comments\n\n";
    $body    .= $VOTE_TEXT;
    $headers  = "From: info@dontmesswithtexas.org\n";
    mail($to, $subject, $body, $headers);
    
    //set success flag
    $success = true;
    }
  else{
    
    // convert license plate to all caps
    $license_plate = strtoupper($license_plate);
    }
  }
  
  


//END FORM PROCESSING----------------------------------------------------------
//END FORM PROCESSING----------------------------------------------------------
//END FORM PROCESSING----------------------------------------------------------








?>

	<h2 id="top">Report a Litterer</h2>
	
<?
//IF SUCCESS --------------------------------------------------------
//IF SUCCESS --------------------------------------------------------
//IF SUCCESS --------------------------------------------------------

if ($success){
  ?>
  <p><strong>Message received!</strong></p>
  <p>Thanks for your report. Your commitment to litter prevention is appreciated. Please let your family and friends know about this page and how they can report litterers.  Together we can make a difference in the Lone Star State.</p>
  <?
  }
else{
}


//IF NOT SUCCESS --------------------------------------------------------
//IF NOT SUCCESS --------------------------------------------------------
//IF NOT SUCCESS --------------------------------------------------------

if (!$success){
	if (!count($errors)) {
?>
<p class="big">While some Texans enjoy a hearty game of backyard washer toss, others prefer something far more sinister: the one-two trash toss from their car windows. We&#8217;re talking about cigarette butts, fast-food wrappers and the like. They&#8217;re small, but they&#8217;re still trash.</p>
 
<p>So what do you do when you see trash being tossed out of a car window or accidentally flying out of a truck bed? Instead of hog-tying the offender to your car, we suggest turning them in through the Texas Department of Transportation&#8217;s Report a Litterer Program.</p>
            
<ol>
	<li>
		<p>When you see litter exit a vehicle, intentionally or accidentally, write down the following information&mdash;license plate number, make and color of vehicle, date and time, location, who tossed the litter and what was tossed. Now fill in below; be as accurate as possible and submit:</p>
    <ul>
     	<li>Texas license plate number (Texas plates only)</li>
        <li> Make of vehicle </li>
        <li>Time of day</li>
        <li> Location</li>
        <li> Date</li>
        <li> Who tossed (driver, passenger or accidental)</li>
        <li> What was tossed</li>
      </ul>
    </li>
    
    <li>TxDOT compares the information to our vehicle registration database and when an exact match is located, we send the litterer a Don't Mess with Texas litterbag along with a letter reminding them to keep their trash off of our roads.</li>
</ol> 

<p>And you can feel good about doing something to clean up our beloved Lone Star State.</p>
<p><a href="faqs.php">FAQ</a></p>

<?php
	}//close if no errors
	//error messages
	if (count($errors)){
	?>
	<h3>Please note the problems listed below:</h3>
	<ul>
	<?
	while(list($key, $value) = each($errors)){ print('<li class="alertBad">'.$value.'</li>'); }
	echo '</ul>';
	}//close if errors
	?>

    <form method="post" action="<? print($PHP_SELF); ?>" name="form">
	<input type="hidden" name="_submitted" value="1"/>
	
	<ul>

		<li><strong>*Indicates a required field. This form is intended for use of reporting litterers only.</strong></li>
		
        <li>Information about the littering incident:</li>
        
        
        <li>
        	<label for="date_occurred">Date</label>
			<input type="text" name="date_occurred" maxlength="32" value="<?php if (isset($_POST['date_occurred'])) echo $_POST['date_occurred']; ?>">
			<span class="smalltext">MM/DD/YYYY</span>
		</li>
				
				
		<li>	
		  	<label for="gotcha_time">Time</label>
		  	<input type="text" name="time_occurred" maxlength="32" value="<?php if (isset($_POST['time_occurred'])) echo $_POST['time_occurred']; ?>">
		  	<span class="smalltext">HH:MM</span>
		</li>
		  	
		<li>	  	
			<label for="ampm">*AM/PM</label>
            <select name="ampm">
            <option value=""></option>
            <option value="AM">AM</option>
            <option value="PM">PM</option>
            </select><br />
		</li>


		<li>
			  <label for="location">Location</label>
              <input type="text" name="location" maxlength="255" value="<?php if (isset($_POST['location'])) echo $_POST['location']; ?>">
        </li>      
              
              
		<li>
			  <label for="license_plate">License Plate</label>
              <input type="text" name="license" maxlength="32" value="<?php if (isset($_POST['license'])) echo $_POST['license']; ?>">
			  <span class="smalltext">Please use capital letters, no spaces and no dashes.</span>
        </li>      
             
              
        <li>      
			  <label for="make_car">Make of car</label>
              <input type="text" name="car_make" maxlength="32" value="<?php if (isset($_POST['car_make'])) echo $_POST['car_make']; ?>">
        </li>  
              
              
        <li>      
			  <label for="what_littered">What was littered</label>
              <select name="what_littered">
              <option value="">please select</option>
              <option value="Cigarette butt">Cigarette butt</option>
              <option value="Cup/can/bottle">Cup/can/bottle</option>
              <option value="Misc. trash">Misc. trash</option>
              <option value="Fast food trash">Fast food trash</option>
              </select>
        </li>
          
              
        
        <li>      
			  <label for="who_littered">Who littered</label>
              <select name="who_littered">
              <option value="">please select</option>
              <option value="Driver">Driver</option>
              <option value="Passenger">Passenger</option>
              <option value="Truck Bed">Truck Bed</option>
              </select>
	    </li>


		<li>
              <label for="comments">Comments</label>
              <textarea name="comments" value="<?php if (isset($_POST['comments'])) echo $_POST['comments']; ?>"</textarea>
      </li>
           
           
      <li>         
            <input type="submit" name="action" value="Send" class="submitbtn" />
			<input type="reset" name="Clear" value="Clear" class="submitbtn" />
	<input type="hidden" name="submitted" value="true" />
	  </li>
</ul>
</form>

	


<?php
}//close if not success
?>

Open in new window

0
lisacowanAuthor Commented:
I forgot to add in the previous message that the email is also not being generated.

thanks,
Lisa
0
lisacowanAuthor Commented:
I figured out part of the mail problem was that I had fields mis-named, so they are now fixed.
0
lisacowanAuthor Commented:
I got the form to work the way I wanted it to, but I am still open to suggestions as to why the original form did not work in WordPress but did work on the same server outside of WordPress. I'll still award points to the person who can help me with that issue.

Thanks,
Lisa
0
drunkenmsCommented:
Lisa, Sorry for late , i'm sick yesterday.
As i understand, your link here http://dontmesswithtexas.org/beta/?page_id=24 is working? =)
0
NerdsOfTechTechnology ScientistCommented:
Its working over here too... Can you post a new url for the broken code? Thanks.
0
lisacowanAuthor Commented:
0
NerdsOfTechTechnology ScientistCommented:
password protected...
0
NerdsOfTechTechnology ScientistCommented:
send new url please :)
0
lisacowanAuthor Commented:
http://dontmesswithtexas.org/beta/?page_id=24

Duh. Sorry about that. I've only had one cup of coffee. Here's the real page:

http://dontmesswithtexas.org/beta/?page_id=24

Lisa
0
NerdsOfTechTechnology ScientistCommented:
LOL that's the same one that you fixed already. I say award yourself points on this one. :)
0
lisacowanAuthor Commented:
Now, I am fully awake. Let's try this one:

http://dontmesswithtexas.org/beta/?page_id=400

Thanks for your patience!

Lisa


0
drunkenmsCommented:
page not found?)
"What you are looking for doesn't seem to be on this page..."
0
NerdsOfTechTechnology ScientistCommented:
reduce points and award some to yourself and the experts who stuck w/ you :)
0
lisacowanAuthor Commented:
I am not getting a page not found error. I'm getting 2 errors that state:

Warning: reset() [function.reset]: Passed variable is not an array or object in /var/www/html/beta/functions/CheckRequiredFields_func.php  on line 21

Warning: Variable passed to each() is not an array or object in /var/www/html/beta/functions/CheckRequiredFields_func.php on line 23

The code for CheckRequiredFields_func.php is attached.

The file where the array required fields is declared is also attached.
<?
/*
  +----------------------------------------------------------------------+
  CheckRequiredFields:
    - checks required fields to ensure some value has been entered
  
  Input:
    none
  
  Output:
    $errors (an array of error messages)
  
  Notes:
    - uses strlen() as check
  
  Last Modified: 06.21.01 (Mike Angel)
  +----------------------------------------------------------------------+
*/
global $required_fields;

reset($required_fields);

while(list($key,$value) = each($required_fields)){
  //must set to global to access
  global ${$key};
  
  if (strlen($_POST[$key]) < 1 or (eregi("^file|image",$key) and !is_uploaded_file($_FILES[$key]['tmp_name']))){
    //add error
    $errors[] = 'Please complete missing info: <span class="yellowtext"><b>'.$value.'</b></span>';
    }
  }

return $errors;
?>

Open in new window

report-a-litterer.php
0
lisacowanAuthor Commented:
Nerds of Tech,

I like your idea, however, I have a more gnarly form on the site with the same problem that I'm trying to fix. The bottom line is that it works outside of WordPress, but not inside it, and I cannot figure out why. I've upgraded to the latest version. I've written to the writer of the plugin that I'm using, but he hasn't answered. The ISP doesn't have any answers. I'm stuck. Do you have any other ideas on how to debug this???

Thanks,
Lisa
0
lisacowanAuthor Commented:
PS, I really don't want to re-write the 2nd form. It's way more complicated than what I am used to.

Lisa
0
lisacowanAuthor Commented:
Thanks for the help, guys.

Lisa
0
NerdsOfTechTechnology ScientistCommented:
maybe you are better off modifying the check required fields function to explicitly take parameters from the form. Or at least modify the page that controls the function:

functions/CheckRequiredFields_func.php

I would post / look at that file for answers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.