DLR Posted June 6, 2009 Share Posted June 6, 2009 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]); } Link to comment https://forums.phpfreaks.com/topic/161188-solved-where-am-i-using-incorrect-variable-to-pass-argument-in-form/ Share on other sites More sharing options...
gevans Posted June 6, 2009 Share Posted June 6, 2009 Are you starting the session?? session_start(); Link to comment https://forums.phpfreaks.com/topic/161188-solved-where-am-i-using-incorrect-variable-to-pass-argument-in-form/#findComment-850579 Share on other sites More sharing options...
DLR Posted June 6, 2009 Author Share Posted June 6, 2009 Yes Link to comment https://forums.phpfreaks.com/topic/161188-solved-where-am-i-using-incorrect-variable-to-pass-argument-in-form/#findComment-850581 Share on other sites More sharing options...
gevans Posted June 6, 2009 Share Posted June 6, 2009 Ok, what currently happens when you submit the form? Check all the variables are as you excpect on the receiving page Link to comment https://forums.phpfreaks.com/topic/161188-solved-where-am-i-using-incorrect-variable-to-pass-argument-in-form/#findComment-850585 Share on other sites More sharing options...
DLR Posted June 6, 2009 Author Share Posted June 6, 2009 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? Link to comment https://forums.phpfreaks.com/topic/161188-solved-where-am-i-using-incorrect-variable-to-pass-argument-in-form/#findComment-850592 Share on other sites More sharing options...
gevans Posted June 6, 2009 Share Posted June 6, 2009 function validate_text($value) { $_SESSION['variable__value'] = htmlentities($_POST[$value]); } Try that Link to comment https://forums.phpfreaks.com/topic/161188-solved-where-am-i-using-incorrect-variable-to-pass-argument-in-form/#findComment-850593 Share on other sites More sharing options...
DLR Posted June 6, 2009 Author Share Posted June 6, 2009 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 Link to comment https://forums.phpfreaks.com/topic/161188-solved-where-am-i-using-incorrect-variable-to-pass-argument-in-form/#findComment-850599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.