[web] PHP function question

Started by
10 comments, last by Kylotan 18 years, 1 month ago
Quote:Original post by Third
No, I don't want it to be dynamic. I'll try generalizing my question more. Is it possible to create a function in PHP that builds something in HTML, such as a radio box or a select box in my case. This function would then need to return the value that is selected by the user. The form is a POST form and the action upon the user hitting the submit button is it goes to another page.

No, not to my knowledge.
Don't Temp Fate..
Advertisement
Quote:Original post by Third
I'll try rephrasing what I want to do. I have a function that builds a select drop down box. I want this function to return the value that the user selects.


Nope, can't happen. The PHP just builds the HTML to send to the browser. It's packed up and gone home by the time the end user even sees the form, and doesn't come into play again until they submit the form, in which case it'll come up in the $_POST variables on whatever page you submit to. PHP function can't return user input - they only ever get it from arrays like $_GET, $_POST, and $_COOKIES, which are populated before a script starts running.

I am not entirely sure what you're trying to achieve. There is hardly ever a good reason to dynamically change the 'name' of an HTML form element as you need to know what it is called in order to process it when it is submitted. Instead you will check the value associated with that name in the $_POST array in whichever file handles the submitted form, as opposed to sending the form to the user. (Although many people combine both functions into one page.)

This topic is closed to new replies.

Advertisement