Page 1 of 1

_post inside a function

Posted: Thu Jul 01, 2010 12:10 am
by Da_Elf
i know with functions i need to pass my variables into the function but how about this situation. it doesnt seem to work
ive got a few forms and i want to use 1 function to deal with them (each having a different button so i tried

Code: Select all

function try($button){
  if(isset($_POST['$button'])){
  $field1=$_POST['field1'];
  echo $field1." was inserted when ".$button." was pressed";
  }
}
try(help);
id like it to echo the info from the text box called field1 as well as work with different buttons from different forms

Re: _post inside a function

Posted: Thu Jul 01, 2010 12:41 am
by cpetercarter

Code: Select all

try("help");

Re: _post inside a function

Posted: Thu Jul 01, 2010 12:47 am
by Da_Elf
doesnt work. i figure i had to change it to this

Code: Select all

function try($button, $field1){
  if(isset($button)){
  echo $field1." was inserted when ".$button." was pressed";
  }
}
try($_POST['help'], $_POST['field1']);
this seems to work now

Re: _post inside a function

Posted: Thu Jul 01, 2010 1:05 am
by requinix

Code: Select all

if(isset($_POST['$button'])){
Variables don't work when you put them in single-quoted strings.

Code: Select all

if(isset($_POST[$button])){