Jump to content

name variable not being sent to server from form


johnmerlino

Recommended Posts

Hey all,

 

I have a situation where there's multiple forms on a single page and when the user clicks the button, I don't want them to be navigated away from page but rather the transaction occurs on same page. Hence, everything occurs in a file called file_generator.php.  I have these two forms:

 

<form action="" method="post" enctype="multipart/form-data">
<tr>
	<td>Upload the data</td>
	<td><input type="file" name="file" /> </td>
</tr>
<tr>	
	<td><input type="submit" name="upload" value="Generate List" /></td>
</tr>
</form>

<form action="" method="post">
<tr>
	<td>Add Content:</td>
	<td><textarea rows="2" cols="20"></textarea></td>
</tr>
<tr>	
	<td>Get the output:</td>
	<td><input type="submit" name="download" value="Get List" /></td>
</tr>
</form>

 

Then when the form gets submitted it checks which form was submitted:

 

foreach($_POST as $name => $value){
switch($name){
	case 'upload':
		upload_data();
		break;
	case 'download':
		download_data();
		break;
}
}

 

So if the user wants to upload  a file, this function gets called:

 

function upload_data(){
$file = $_POST['file'];
if(isset($file)){
	if(file_is_valid($file)){
		echo "true";
	}
}
else {
	echo "No file chosen";
}
}

 

For some reason, it triggers the else above, even though I selected a file, and that $file variable therefore should be set.

 

Thanks for response

To add to Mikesta's statement which is also a valid point, "file_is_valid" isn't a predefined PHP function, so unless you have created this function...it will always return FALSE...

I think you want is_file instead...?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.