Jump to content

$_POST Values are Empty


unemployment

Recommended Posts

My $_POST array is not holding the gender or tos values and is showing up empty.  Any idea why? 

 

<?php

if(isset($_POST['finish']))

{

print_array($_POST);

 

$gender = (int)$_POST["gender"];

$tos = (int)$_POST["tos"];

}

?>

<form action="join.php?key=<?php echo $_GET["key"]; ?>" method="post" id="form" name="signup">

<div class="tcenter mtl mbl pbs">

<input id="termsbox" type="checkbox" name="tos" value="1" /> I agree with the <a href="terms.php">Terms and Conditions</a>.

</div>

<div class="signUp mbl pbl" id="finish">

<input type="submit" id="finish_btn" name="finish" value="Finish" /> <input type="reset" value="Clear" />

</div>

</form>

 

Link to comment
Share on other sites

Since there is no built-in print_array() function, it's likely that your user written print_array() function is wiping out the data. It's also possible that your actual form is reusing those field names (the last occurrence in the form wins) or your actual form is invalid html or you have some php code that is wiping out the values.

 

Without the full code that duplicates the symptom, no one can directly help you find the problem.

Link to comment
Share on other sites

Without the full code that duplicates the symptom, no one can directly help you find the problem.

 

Here is my full form and the php.

 

        <form action="join.php?key=<?php echo $_GET["key"]; ?>" method="post" id="form" name="signup">
	<fieldset id="fieldset1" class="fieldset2">
		<legend>Additional Information</legend>
		<div class="formElement mtl ptl">
			<div class="formFieldLabel ">
				<label for="timezone">Timezone *</label>
			</div>
			<div class="formField left">
				<select id="timezone" class="dropdown" name="timezone">
					<option value="">Select a Timezone</option>
					<?php

					foreach ($timezones as $timezone)
					{
						if ($timezone['timezone_id'] == $rtimezone)
						{
							echo "<option selected=\"selected\" value=\"${timezone['timezone_id']}\">${timezone['timezone_name']}</option>";
						}
						else
						{
							echo "<option value=\"${timezone['timezone_id']}\">${timezone['timezone_name']}</option>";
						}
					}

					?>
				</select>
			</div>
		</div>
		<div class="formElement">
			<div class="formFieldLabel">
				<label for="country" >Country *</label>
			</div>
			<div class="formField left">
				<select id="country" class="dropdown" name="country">
					<option value="">Select a Country</option>
					<?php

					foreach ($countries as $country)
					{
						if ($country["country_id"] == $rcountry)
						{
							echo "<option value=\"${country["country_id"]}\" selected=\"selected\">${country["country"]}</option>";
						}
						else
						{
							echo "<option value=\"${country["country_id"]}\">${country["country"]}</option>";
						}
					}

					?>
				</select>
			</div>
		</div>
		<div class="formElement">
			<div class="formFieldLabel ">
				<label for="state">State *</label>
			</div>
			<div class="formField left">
				<select id="state" class="dropdown" name="state" <?php if((!isset($rstate)) || ($rstate != 231)){ echo 'disabled="disabled"'; }?>>
					<option value="">Select a State</option>
					<?php

					foreach ($states as $state)
					{
						if (isset($rstate) && $state['state_id'] == $rstate)
						{
							echo "<option selected=\"selected\" value=\"${state['state_id']}\">${state['state']}</option>";
						}
						else
						{
							echo "<option value=\"${state['state_id']}\">${state['state']}</option>";
						}
					}

					?>
				</select>
			</div>
		</div>
		<div class="formElement">
			<div class="formFieldLabel">
				<label for="city" >City *</label>
			</div>
			<div class="formField">
				<input id="city" type="text"  name="city" value="<?php if(isset($_POST['city'])){ echo $_POST['city']; } ?>" />
			</div>
		</div>
		<div class="formElement">
			<div class="formFieldLabel">
				<label for="personalweb">Personal Website</label>
			</div>
			<div class="formField">
				<?php

				$isset = isset($_POST['personalweb']);

				if ($isset)
				{
					$_POST['personalweb'] = str_replace(array('http://', 'https://'), '', isset($_POST['personalweb']));
				}

				?>
				<input id="personalweb" type="text" name="personalweb" value="<?php echo ($isset) ? $_POST['personalweb'] : ''; ?>" />
			</div>
		</div>
		<div class="formElement">
			<div class="formFieldLabel">
				<label for="dayOfBirth" >Date of Birth *</label>
			</div>
			<div class="formField">
				<select name="monthofbirth" id="monthOfBirth" class="rightcolalign required reg">
					<option value="">Month</option>
					<?php

					$isset = isset($_POST['monthofbirth']);

					for($i = 1; $i < 13; ++$i)
					{
						if ($isset && $_POST['dayofbirth'] === $i)
						{
							echo "<option value=\"${i}\" selected=\"selected\">${months[$i]}</option>\n\t\t\t\t\t\t";
						}
						else
						{
							echo "<option value=\"${i}\">${months[$i]}</option>\n\t\t\t\t\t\t";
						}
					}

					?>
				</select>
				<span class="date_break">|</span>
				<select name="dayofbirth" id="dayOfBirth" class="rightcolalign required reg">
					<option value="">Day</option>
					<?php 

					$isset = isset($_POST['dayofbirth']);

					for($day = 1; $day <= 31; ++$day)
					{
						echo '<option';

						if ($isset && $_POST['dayofbirth'] === $day)
						{
							echo ' selected="selected"';
						}

						echo ">${day}</option>\n\t\t\t\t\t\t";
					}

					?>
				</select>
				<span class="date_break">|</span>
				<select name="yearofbirth" id="yearOfBirth" class="rightcolalign required reg">
					<option value="">Year</option>
					<?php

					$isset = isset($_POST['yearofbirth']);

					$start = $currentyear - 13;
					$end = $currentyear - 80;

					for($year = $start; $year >= $end; --$year)
					{
						if ($isset && $_POST['dayofbirth'] === $year)
						{
							echo "<option value=\"${year}\" selected=\"selected\">${year}</option>\n\t\t\t\t\t\t";
						}
						else
						{
							echo "<option value=\"${year}\">${year}</option>\n\t\t\t\t\t\t";
						}
					}

					?>
				</select>
			</div>
		</div>
		<div class="formElement">
			<div class="formFieldLabel">
				<label for="gender" >Gender *</label>
			</div>
			<div class="formField">
				<input class="gender_align" id="male" name="gender" type="radio" value="1" />
				<label for="male">Male</label>
				<input class="gender_align" id="female" name="gender" type="radio" value="0" />
				<label for="female">Female</label>
			</div>
		</div>
	</fieldset>
	<div class="tcenter mtl mbl pbs">
		<input id="termsbox" type="checkbox" name="tos" value="1" /> I agree with the <a href="terms.php">Terms and Conditions</a>.
	</div>
	<div class="signUp mbl pbl" id="finish">
		<input type="submit" id="finish_btn" name="finish" value="Finish" /> <input type="reset" value="Clear" />
	</div>
</form>

 

         if(isset($_POST['finish']))
{
	print_array($_POST);
	$timezone = 			(int)$_POST["timezone"];
	$country = 				(int)$_POST["country"];
	$state = 				(int)isset($_POST["state"]);
	$city = 				mres(strip_tags($_POST["city"]));
	$personalweb = 			mres(strip_tags($_POST["personalweb"]));
	$dateofbirth = 			mres(strip_tags("${_POST['yearofbirth']}-${_POST['monthofbirth']}-${_POST['dayofbirth']}"));
	$gender = 				(int)$_POST["gender"];
	$tos = 					(int)$_POST["tos"];


	if (!isset($timezone))
	{
		$errors[] = 'Timezone is a required.';
	}

	if (!isset($country))
	{
		$errors[] = 'Country is required.';
	}

	if (!isset($state))
	{
		$errors[] = 'State is required.';
	}

	if (preg_match('#^[a-z]{1,40}$#i', $city) !== 1)
	{
		$errors[] = 'City must be between 1 and 40 characters and can contain only letters.';
	}

	if (!empty($personalweb) && (filter_var($personalweb, FILTER_VALIDATE_URL) === false))
	{
		$errors[] = 'The url you entered does not appear to be valid.';
	}

	if (empty($_POST['monthofbirth']) || empty($_POST['dayofbirth']) || empty($_POST['yearofbirth']))
	{
		$errors[] = 'All date of birth fields are required.';
	}

	if (!isset($gender))
	{
		$errors[] = 'Gender is required.';
	}

	if (!isset($tos))
	{
		$errors[] = 'You must agree to the terms and conditions.';
	}

	if (empty($errors) === false)
	{
		if (count($errors) > 1)
		{
			echo "<div class=\"errormessage error lhm\">\n<ul>";

			foreach ($errors as $error)
			{
				echo "<li>",$error,"</li>\n" ;
			}

			echo '</ul></div>';
		}	
		else
		{
			echo '<p class="errormessage error">', $errors[0], '</p>';
		}

		$_POST['selector'] = 1;

		$step = 3;
	}
	else
	{
		header("location: index.php");
	}
}

Link to comment
Share on other sites

Your posted code works as expected. Did you try just the code you posted to see if it produces the problem?

 

I notice that you are reselecting/redisplaying all the previous form field values except for the two that are not working. Are you sure you are not resubmitting the form after a validation error without selecting a gender radio button and the tos checkbox?

Link to comment
Share on other sites

Your posted code works as expected. Did you try just the code you posted to see if it produces the problem?

 

I notice that you are reselecting/redisplaying all the previous form field values except for the two that are not working. Are you sure you are not resubmitting the form after a validation error without selecting a gender radio button and the tos checkbox?

 

Hmm... I still can't find the error, but I am also not reselecting the password fields and those seem to be working.

Link to comment
Share on other sites

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.