Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.