Where is my data, PHP?

So here I am just testing out a basic form and the basic test script is not giving me the output from the input fields (or any other(.

<?php
if(isset($_POST[‘submit’])){

echo “<pre>”;
print($_POST[‘name’]);
echo “<pre>”;

}
?>

The problem is with the submit key not being set. What mistake am i making.
Btw, I am getting my data back if I do:

if(isset($_POST)){

echo “<pre>”;
print($_POST[‘name’]);
echo “<pre>”;

}
?>

Why is the submit key not being set?

You needed to post your form code. Does your submit button have a name field?


<input type="submit" name="submit" value="Save" />

Maybe you misspelled it.
Maybe you’re using a browser that doesn’t always send the name/value pair of the submit button.
Maybe your form doesn’t submit via post.

print_r($_POST);
print_r($_GET);

This will show you what was sent by the browser.

As an aside, various browser inconsistencies and bugs make testing for a submit button a poor strategy to test for form submission. There’s many ways, but a simple if ($_POST) is good, and simple.

Yes My submit button has a name field with a value of submit:

<input id=“saveForm” name=“submit” class=“btTxt submit” type=“submit” value=“Submit” />

No misspellings. form is set to submit to post:
<form id=“form1” name=“form1” class=“wufoo leftLabel page” autocomplete=“off” enctype=“multipart/form-data” method=“post” action=“”>

I am using firefox.

Is if($_POST) a good way? That will check for the entire superglobal array. I want the data to be submitted after triggering the specific form submission event.
Just asking…am not an authority on these things.

If you need to differentiate between multiple different forms, use a hidden input and test for the name of it.

Here’s the whole script. Can you tell me what’s wrong?


<?php
if(isset($_POST['submit'])){

echo "<pre>";
print($_POST['name']);
echo "<pre>";

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>
Apply for Scholarship
</title>

<!-- Meta Tags -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Wufoo.com" />

<!-- CSS -->
<link rel="stylesheet" href="css/structure.css" type="text/css" />
<link rel="stylesheet" href="css/form.css" type="text/css" />
<link rel="stylesheet" href="css/theme.css" type="text/css" />

<!-- JavaScript -->
<script type="text/javascript" src="scripts/wufoo.js"></script>
</head>

<body id="public">
<div id="container">

<h1 id="logo">
		<a>Wufoo</a>
	</h1>

<form id="form1" name="form1" class="wufoo leftLabel page" autocomplete="off" enctype="multipart/form-data" method="post" action="">

<div class="info">
	<h2>Apply for Scholarship</h2>
	<div>This scholarship is applicable only for PM Academy's Certificate in Project Management Program.<br />
 Required Fields are marked by a red asterix.</div>
</div>

<ul>
		
		
	<li id="foli3" 		class="first section      ">
		<div id="instruct3">This information will never be shared with third parties but will help us know you better</div>
	</li>


<li id="foli1" 		class="altInstruct     ">
	<label class="desc" id="title1" for="Field1">
		Name
				<span id="req_1" class="req">*</span>
			</label>
	<div>
		<input id="Field1" 			name="name" 			type="text" 			class="field text large" 			value="" 			maxlength="255" 			tabindex="1" 			onkeyup="" 						/>
			</div>
		<p class="instruct" id="instruct1"><small>Please enter your full name</small></p>
	</li>


<li id="foli6" 		class="altInstruct     ">
	<label class="desc" id="title6" for="Field6">
		Email 
				<span id="req_6" class="req">*</span>
			</label>
	<div>
		<input id="Field6" 			name="email" 			type="text" 			class="field text large" 			value="" 			maxlength="255" 			tabindex="2" 						/> 
	</div>
		<p class="instruct" id="instruct6"><small>Please enter a valid email address</small></p>
	</li>


<li id="foli8" 		class="     ">
	<label class="desc" id="title8" for="Field8">
		City
				<span id="req_8" class="req">*</span>
			</label>
	<div>
		<input id="Field8" 			name="city" 			type="text" 			class="field text medium" 			value="" 			maxlength="255" 			tabindex="3" 			onkeyup="" 						/>
			</div>
	</li>


<li id="foli9" 		class="     ">
	<label class="desc" id="title9" for="Field9">
		Country
				<span id="req_9" class="req">*</span>
			</label>
	<div>
		<input id="Field9" 			name="country" 			type="text" 			class="field text medium" 			value="" 			maxlength="255" 			tabindex="4" 			onkeyup="" 						/>
			</div>
	</li>


<li id="foli7" 		class="altInstruct     ">
	<label class="desc" id="title7" for="Field7">
		Phone Number
				<span id="req_7" class="req">*</span>
			</label>
	<div>
		<input id="Field7" 			class="phone" 			name="Field7" 			tabindex="5" 			type="text" maxlength="255" value="" /> 
	</div>
			<p class="instruct" id="instruct7"><small>we will reach you directly if you are deemed eligible for the scholarship</small></p>
</li>


<li id="foli33" 		class="     ">
	<label class="desc" id="title33" for="Field33">
		When is it convenient to reach you?
			</label>
	<div>
	<input id="radioDefault_33" name="time" type="hidden" value="" />
		<span>
	<input id="Field33_0" 		name="time" 		type="radio" 		class="field radio" 		value="9 am - 12pm" 		tabindex="6" 						 checked="checked" 						/>
	<label class="choice" for="Field33_0" 		>
		9 am - 12pm</label>
		</span>
		<span>
		<input id="Field33_1" 		name="time" 		type="radio" 		class="field radio" 		value="12 pm - 5 pm" 		tabindex="7" 								/>
		<label class="choice" for="Field33_1" 		>
		  12 pm - 5 pm</label>
		</span>
		<span>
	<input id="Field33_2" 		name="time" 		type="radio" 		class="field radio" 		value="6 pm - 9 pm" 		tabindex="8" 								/>
	<label class="choice" for="Field33_2" 		>
		6 pm -  9 pm</label>
		</span>
		</div>
	</li>



	<li class="buttons ">
		<div>
<input id="saveForm" name="submit" class="btTxt submit" type="submit" value="Submit" />
							

					
					
							
				</div>
	</li>
</ul>
</form>

</div><!--container-->
<img id="bottom" src="images/bottom.png" alt="" />


</body>
</html>

<form id="form1" name="form1" class="wufoo leftLabel page" autocomplete="off" enctype="multipart/form-data" method="post" action=""> 

In that line there you’re missing a value for action. The action value is the file/script which is going to process what is submitted by the form.

Sure,

But what that means is that script is submitting to itself. The PHP code is above the doctype. see?

before the if condition, put var_dump($_POST); so that you get to see the complete data that is posted to the page.

I think $_POST is always set, even if it’s empty. So your original check of seeing if $_POST[‘submit’] was set was better.

Anyway, I copied your source ontio my server and it worked as expected.
Maybe there’s some javascript going on that’s altering the form before it’s beign submitted?

I don’t know what wufoo.js does (I know wufoo is a form-builder, but not what the script does).

Try var_dump($_POST) as suggested by Paul, it’ll show you all the info in $_POST.

If that doesn’t show anything, then you may need to make sure your PHP is running properly (or at all).

sure I can get output either ways. The question is how should i proceed in my script for collecting form data? I doing an if($_POST) a sufficient condition. Please keep in mind that I am building a multi-part form.

Ya!! it worked. Thanks a lot Immerse.