Jump to content

getting variables from a form in oop


1internet

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/275568-getting-variables-from-a-form-in-oop/
Share on other sites

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.

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.