1internet Posted March 12, 2013 Share Posted March 12, 2013 So if you have a submit button in a class public function submit() { <input type="submit" name="'.$this->submit.'" value="'.$value.'"/>'; } But then you have a text form that wants to detect if the form has been submitted, and if it has been submitted, you want it to display the value in the field, how would you do that, as far as I could get was this, but it's not working, even after a lot of playing around. public function text($name) { $this->name = $name; $label = ucwords($this->name); $name = strtolower(str_replace(' ', '', $this->name)); if(isset($this->submit)) $this->value = $_POST[$name]; else $this->value = ''; $this->field = ' <input type="text" name="'.$name.'" value="'.$this->value.'"/>'; } So the issue is that it doesn't seem to detect if the variable has been set (form submitted). I am guessing there is some way to do this. Quote Link to comment https://forums.phpfreaks.com/topic/275568-getting-variables-from-a-form-in-oop/ Share on other sites More sharing options...
jcbones Posted March 12, 2013 Share Posted March 12, 2013 You should be checking $_SERVER['REQUEST_METHOD'] http://php.net/manual/en/reserved.variables.server.php to see if the form is submitted. Quote Link to comment https://forums.phpfreaks.com/topic/275568-getting-variables-from-a-form-in-oop/#findComment-1418273 Share on other sites More sharing options...
akphidelt2007 Posted March 13, 2013 Share Posted March 13, 2013 Gonna need a little bit more information than this. But just some inconsistencies I see from the little bit of code you submitted. In the submit field you have the name as '$this->submit' but in the text function you check to see if $this->submit is set. What you want to do is check to see if $_POST[$this->submit] is set. I'm willing to take a guess that $this->submit is not being set, so therefore when you check to see if it isset, you are getting a false return and getting no value for the input. Quote Link to comment https://forums.phpfreaks.com/topic/275568-getting-variables-from-a-form-in-oop/#findComment-1418293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.