Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button Control

Status
Not open for further replies.

YoungManRiver

IS-IT--Management
Feb 9, 2004
220
0
0
US
All,

Have a file posted at:


with 5 buttons. Problem is I'm having trouble getting the buttons to differentiate themselves. Been trying to use the function "set_but" to solve this, but not sure I'm calling it correct nor setting up the passing of vars to it right.

The purpose of this file, is to read in an Excel file (thus TBS Excel class) and then write data to another Excel file. Right now, I'm using MySQL to hold the R:C mapping between the files and have not yet set up any MySQL queries, until I can the button to perform their various functions.

Buttons are:

  • [li]Browse - From built in <input type=file> field,[/li]
    [li]View Input File - Uses TBS Excel Class to open originating file,[/li]
    [li]Process - Scrapes the data from file1 into file2,[/li]
    [li]View Output File - Process file, if not already done and opens target file with TBS Excel Class,[/li]
    [li]Print Output - Process file, if not already done and print out the resulting target file.[/li]

Right now all the buttons, other than "Browse" are just opening the originating file.

Kinda new on the PHP side, so still feeling my way.

All help appreciated!

Thanks!

YMR
 
YMR

enquote your html attributes. particularly the name attribute. apart from being 'wrong', if you do not, any information after the first space will not be transmitted to in the form variables.

don't use $HTTP_POST_VARS, this is deprecated. use $_POST instead.

i have not fully followed your code but i cannot see what this is doing
Code:
#
$but_vin = "<input type=button name=iview value=View ".
#
              "onclick=\"document.forms['scrub'].submit(set_but('infile'));\">";
it looks like you are trying to call a php function from within a javascript function. i was not aware that the js form.submit() function took an argument either.

if you want to differentiate the button that is clicked when you are in a php script follow this logic

Code:
<?php
$potentialValues = array (
							'oview',
							'print',
							'proc'
							);
switchboard();
			
function displayForm($message){
	$buttons = getButtons('&nbsp;');
	$textElement = empty($_POST['textElement']) ? '' : trim($_POST['textElement']);
	echo <<<HTML
<style>
#message {width: 50%; color: red; border:dotted thin red; height: 5em;}
#form {width: 50%}
</style>
<div id="message">$message</div>
<div id="form">
<form method="post" action="{$_SERVER['PHP_SELF']}">
<fieldset>
	<legend>Test Form</legend>
	<input type="text" name="textelement" value="$textElement" /> <br/>
$buttons
</fieldset>
</form>
</div>
HTML;
}

function getButtons($sep){
	global $potentialValues;
	$output = array();
	foreach ($potentialValues as $button){
		$output[] = "\t<input type=\"submit\" name=\"submit\" value=\"$button\">";
	}
	return implode($sep & "\r\n", $output);
}

function parseForm(){
	global $potentialValues;
	if (!isset($_POST['submit'])){
		return 'Form was not submitted';
	}
	if (!in_array($_POST['submit'], $potentialValues)){
		return 'Form was spoofed';
	}
	return "Button pressed was " . trim($_POST['submit']);
}

function switchboard(){
	$message = parseForm();
	displayForm($message);
}
	
?>
 
please re-read my post above. there are several elements of advice/best practice that your revised code ignores.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top