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

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.