We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Accessing form elements from PHP

steva
steva asked
on
Medium Priority
299 Views
Last Modified: 2012-05-11
I have a form that asks for comments. The form is submitted to a PHP action program that emails off the contents and redisplays the form.  But the form is displayed by just including a form.html file, so it's just the generic form that gets generated again.  But I'd like to display "Thank you for your comments." in  the comment textarea element when I display the form the second time, so I need some way to get a hold of input#comments, which is a textarea in the  form, from php,   so I can set value to "Thank you for your comments."

Thanks for any suggestions
Comment
Watch Question

Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Freelancer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Dave,

Yes, it's looking like that's the only way to do it.

marcusG,

All I meant by "PHP action program" is the PHP program called by the form action attribute. Sorry for not saying that more clearly.  And again, as per your example, it looks like the only way to get a slightly different form the second time is to create it from whole cloth.

Ray,
New to PHP, not new to programming.  I have three PHP books I'm working from::

 "PHP & MySQL for Dummies"  by Valade,
 "PHP, MySQL & JavaScript" by Nixon, and
 "PHP and MySQL Web Development"  by Welling and Thomson.

 If I feel I need another book I'll look at the SitePoint book you suggested.  I don't think any of them, though,  would have told me how to access form elements from PHP because apparently it can't be done.  I thought there might be a way because I know you can do it from ASPX.

Thanks for the sample code.  I'll put that in my toolbox.  Your solution is to not repaint the form at all if the input is ok, and just say Thank You, but I think  I would prefer, in my case,  to show the form with the Thank You in the textarea when I'm done, so I'll go ahead and create a form2.html with the Thank You  and include it after sending the email.

Most Valuable Expert 2011
Author of the Year 2014

Commented:
If you're not new to programming and you have Welling, then I have a different suggestion.  Look up "PHP 5 in Practice" by Elliott White.  It's a great cookbook!
Bruce SmithSoftware Engineer II

Commented:
Or you could use a session variable to trigger a thank you message. Once the form is submitted toggle a session variable from false to true. Add a conditional statement right below the form that 'echoes' "Thank You" if the session variable is true. If it's false, echo nothing. Make sure that the action of your form is the same page.

With session variables, you can also customize the "Thank You" message to the respected author of the comment. So if the comment author's name is 'Dave' you could tailor your "Thank You" message to "Thanks for your comments, Dave!"

I hope this helps some.

Cheers

Author

Commented:
Ray,
I just ordered PHP 5 in Practice.  Thanks!

patsmitty:

That sounds like a great idea.  Thanks!  Sorry all the question points are gone.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
You'll love it.  I know Eli personally.  He was a core developer of Digg.  All the best, ~Ray
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.