Jump to content

[SOLVED] Where am I using incorrect variable to pass argument in form?


DLR

Recommended Posts

Hi,

I'm trying to write a simple input and validation form that can be reused with different variable for the field name and values.

 

I've got the input side working the way it should, but cann seem to passon the results to the next part of the programme.

 

Can you help me find my error?

 

Thanks a lot - this has me really frustrated !


[color=orange]//use hidden value "show" to display form only if button has not been clicked[/color]
if($_POST['show']) {
      [color=orange]//at this point I have a "POST" variable created by function input_text
      //using print_r($_POST) I can see the variable 'name' has the value 'new test  script' this point.
      //I cannot get the to save the POST variable as a SESSION variable.[/color]

      validate_text($POST[$variable_value]);   [color=orange]//brought through from function input_text?[/color]

      echo $_SESSION['variable_value'] ; [color=red]// blank result[/color]
      
} else {
   
  [color=orange] // show form[/color]
   echo '<form action = "test.php" method="post" >' ;
   
   $name = "name";    
   input_text($name,"new test script");    [color=orange]// arguments are: variable name  , variable default value[/color]
   echo '<button type="submit" > Enter </button>';
   echo '<input type="hidden" name="show" value="1">';
   echo "</form>";
}

[color=orange]//**************************************************************************[/color]
function input_text($variable_name,$variable_value) {
    echo "<input type = 'text' name = '" . $variable_name . "' ";
    echo " value = ' " . htmlentities($variable_value) . " ' >";
}

function validate_text($value) {
    $_SESSION['variable__value'] = htmlentities($_POST[$variable_value]); 
}

Blank, because $_SESSION['variable_value'] does not get a value

 

However  $_POST['name'] has the value of " new test script" - which is the input from the input form (if I change the value of the input this works correctly).

 

So how do I convert the POST value to a SESSION value? 

 

I set the name of the variable with $name - "name"  , so what do I call the POST variable?

No that does not work either

 

I assess the problem as being one of understanding how to call the POST variable.

 

I comes through as $_POST['name'] fine - but how do I access the 'name' bit when the 'name' bit is generic (ie will be used with many differet variables?

 

Something you have written has triggered off an idea save the 'name' as a session and call it up in the function validate - it works!!

 

I cannot tell you how long I have played with this !!!

 

Thanks for the input

David

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.