Passing variable not passing!

This is driving me crazy (and, beleive me, that is a VERY SHORT DRIVE)

One of my variables is not passing. Cannot see why but maybe a new set of eyes can see it.

In the function VerifyForm, the $values is not getting transferred from the form to this function. I have a couple of echo statement in this to try to see what is going on. Get at name of blank even if I put something in it. Form is here if you want to see what it actually does. Code and form match so not sure what else is needed to see.

On line 63 (these are not numbered here, darn it) is where the data should be entered and picked up.

this is almost complete, just trying to get the verification done, so the rest of the VerifyForm code will come when I can figure out how to pass the proper stuff back and forth.

Thanks
F

Any help is great…

Here is the code:

<?php
	session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>SACCC Form</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <style type="text/css" media="screen">
  	@import "css/main.css";
	  @import "css/top-positioned-labels.css";
   .mWaiver {
      width: 100%;
      margin-left: -50%;  
      padding: 0;
      margin: 0;
   }
   
   .error_msg {
      margin: 0;
      font-size: .8em;
      font-weight: 700;
      color: red;
   }
   <script type="text/javascript" src="jsquery/jquery.js"></script> 
  </style>
</head>
<body>
<?php

function VerifyForm(&$values, &$errors) 
  { 
  
  if (strlen($values['name']) == 0){
  $errors['name'] = 'REQUIRED: Enter Name';
    echo 'Name ['.$values[name].'] is empty being passed and error is '.$errors['name'].'<br>';
  } 
  return (count($errors) == 0); 
  }

function DisplayForm($values, $errors) { ?>

  <div id="page">
		<div id="header">
			<h1>
				SACCC Registration Form
			</h1>
         <p style="margin-top: -35px; color:#FFF;">All items marked with an asterisk (*) are required.</p>
		</div>
		<div id="content">
		  <form method="post" action="<?= $_SERVER['PHP_SELF'] ?>"> 
<!--      <form action="mail.php" method="post">    -->
			<fieldset style="margin-left: 20px;">
					<legend>
						<span>Contact Details</span>
					</legend>
					<ol>
						<li>
							<label for="participants_name">
								* Name:                      
							</label>
							<input type="text" class="text"  id="participants_name" name="participants_name" value="<?= htmlentities($values['name']) ?>" />

                <span class="error_msg">
                      <?= $errors['name'] ?>
                    </span>    
						</li>
						<li>
							<label for="email">
								* Email address:
							</label>
							<input id="email" name="email" class="text" type="text" />
						</li>
						<li>
							<label for="phone">
								Telephone:
							</label>
							<input id="phone" name="phone" class="text" type="text" />
						</li>
					</ol>
				</fieldset>         
            <fieldset>
            	<legend>
               	<span>Vehicle Information</span>
               </legend>
               <ol>
               	<li>
                  	<label for="VehicleYr">
                     	* Vehicle Year:
                     </label>
                      <input id="VehicleYr" name="VehicleYr" class="text" type="text" size="4" maxlength="4"/>
                  </li>
                  <li>
                  	<label for="VehicleMkMdl">
                     	* Vehicle Make, Model
                     </label>
                      <input id="VehicleMkMdl" name="VehicleMkMdl" class="text" type="text" size="65"/>
                  </li>
               </ol>
            </fieldset>
                     
				<fieldset class="clearleft">
					<legend>
						<span>Delivery Address</span>
					</legend>
					<ol>
						<li>
							<label for="address1">
								* Address 1:
							</label>
							<input id="address1" name="address1" class="text" type="text" />
						</li>
						<li>
							<label for="address2">
								Address 2:
							</label>
							<input id="address2" name="address2" class="text" type="text" />
						</li>
						<li>
							<label for="city">
								* City:
							</label>
							<input id="city" name="city" class="text" type="text" />
						</li>
						<li>
							<label for="state">
								* State:
							</label>
							<input id="state" name="state" class="text" type="text" />
						</li>                  
						<li>
							<label for="zipcode">
								* Zip code:
							</label>
							<input id="zipcode" name="zipcode" class="text textSmall" type="text" />
						</li>

					</ol>
				</fieldset>


				<fieldset class="mWaiver">
            	<legend>
               	<span>HOLD HARMLESS AGREEMENT</span>
               </legend>
                <ol>
                  <li><label>
I HAVE READ THE DESCRIPTION OF THE ACTIVITY FOR WHICH I HAVE APPLIED, AND I AM AWARE THAT THESE ACTIVITIES
SUBJECT ME TO PHYSICAL RISKS AND DANGERS. NEVERTHELESS, I VOLUNTARILY AGREE TO ASSUME ANY AND ALL RISKS OF INJURY OR
DEATH, AND TO RELEASE, DISCHARGE, AND HOLD HARMLESS ALL OF THE ENTITIES OR PERSONS MENTIONED ABOVE WHO, THROUGH
NEGLIGENCE OR CARELESSNESS, MIGHT OTHERWISE BE LIABLE TO ME, OR MY HEIRS, PERSONAL REPRESENTATIVES, NEXT OF KIN,
SPOUSE OR ASSIGNS. It is understood and agreed that this waiver, release, and assumption of risk is to be binding on my HEIRS, PERSONAL
REPRESENTATIVES, NEXT OF KIN, SPOUSE and ASSIGNS. I have carefully READ this Agreement and fully UNDERSTAND its content.<br />
I hereby give the Spokane Area Classic Chevy Club permission to use photographs and/or likenesses of my car without limitation and without compensation to me.
                   <li>
                   <label for="waiverAgree"><em> * </em><input id="waiverAgree" name="waiverAgree" class="checkbox" type="checkbox" value="1" />	
                   I/we have read the above agreement and agree to its terms 
                   </label>
                  </li>
              
										<label for="earlyPay"><em> * </em><input id="earlyPay" name="earlyPay" class="checkbox" type="checkbox" value="1" />
										
											I/we agree to pay the registration fee of $10.00 upon arrival at the show.
										</label>
									
                  </ol>
            </fieldset>
	<span style="padding-left:10px; margin-left: 5%; float:left;"><input type="submit" name="task" value="Register" /></span>
	

	
	<span style="padding-left: 10px; margin-left: 5%; float:left; "><input type="submit" name="task" value="Return to main page" /></span>
			</form>
         
         <?php	} ?>
		</div>
	</div>
</body>
</html>

<?php
function ProcessForm($values) 
  { 
  $papaya = $_POST['papaya']; 
  $carrot = $_POST['carrot']; 
  $guava = $_POST['guava']; 
  $name = $_POST['name']; 
  $address1 = $_POST['address1']; 
  }
if ($_SERVER['REQUEST_METHOD'] == 'POST') 
  { 
  $formValues = $_POST; 
  $formErrors = array(); 
  if (!VerifyForm($formValues, $formErrors)) { 
  echo 'Error part of POST<br>displaying form with data and errors<br>';
  DisplayForm($formValues, $formErrors);  }
  else     {
  echo 'Processing form' ;
  ProcessForm($formValues);     }
  } 
  else 
  DisplayForm(null, null); 
  ?>

Okay, let’s trace things back.

<?= htmlentities($values['name']) ?>

Is <?= a supported short-tag by your PHP server? use <?php instead just to be sure.

Where does $values come from? It comes from the call to DisplayForm
Where does the call to DisplayForm get $formValues from? Well, it get passed in to VerifyForm which is able to change $formValues since the function uses a pass by reference. Don’t do that. There’s no need to allow changes to that variable so don’t allow the potential for problems to occur.

That’s not the cause of the problem though, but there is a scripting problem in the VerifyForm function none-the-less, where $values[name] should be $values[‘name’] instead.

You also need to check that $values[‘name’] exists, otherwise you’re going to get undefined index notices.

Before:


if (strlen($values['name']) == 0){ 
    $errors['name'] = 'REQUIRED: Enter Name'; 
    echo 'Name ['.$values['name'].'] is empty being passed and error is '.$errors['name'].'<br>'; 
}

After:


$name = '';
if (isset($values['name'])) {
    $name = $values['name'];
}
if (strlen($name) == 0){ 
    $errors['name'] = 'REQUIRED: Enter Name'; 
    echo 'Name ['.$name.'] is empty being passed and error is '.$errors['name'].'<br>'; 
}

But that’s not solving your problem.

What the problem is, is that your form is using “participants_name” for the form field, but your PHP script is expecting ‘name’ instead. That’s yer problem.

Doh!!! Can’t see the forest for the trees…

Thanks for the help… working now but… have another question on another part in another area.

F