ihw13 Posted December 13, 2007 Share Posted December 13, 2007 I asked this question way earlier and didn't get the right answer because I think I asked it wrong. Basically I have a game type that needs user input at certain points and then needs to act on that input. Here's the code I currently have that doesn't work well: <?php class form{ function show_form() { echo'<form method="POST" action="'; echo "#$form->process_form()"; echo '">'; echo '<input type="radio" name="response" value="f"> Follow Move <input type="radio" name="response" value="s">Sit In<br> <input type="submit" name="submit" value="Submit">'; echo '<input type="hidden" name="submit_check" value="1"/> </form>'; } function process_form() { return $_POST['response']; } } ?> Yes I realize the form is written poorly, but that's not the issue. Basically in another function I call $form->show_form(); then I call $response=$form->process_form(); somehow I need to display the form, process it, and return the value of 'response' to the original function where I called $form->show_form();. Ideally I could call this function once something like $form=$form->xform(); where the xform() function would display and process the form and return the value of 'response' into the $form variable which I can then work with. Hopefully that makes sense, thanks in advance. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2007 Share Posted December 13, 2007 The action="..." parameter of a form must be a URL. When a browser submits form data, it makes a http request for the URL in the action="..." parmater and then sends the POST (or GET) data to the server. You cannot put a php class function in the action="..." parameter for a couple of reasons, 1) the browser has absolutely no knowladge of what code exists in a php file on the server and 2) your must supply a URL, as that is the only way the http/https protocol works. Even if you were using AJAX, you are still making a http request for a URL. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 14, 2007 Share Posted December 14, 2007 Your code is way to complicated for the job at hand. It doesn't really require a class anyway tbh unless you're going to add a lot to it. <?php if (!$_POST) { echo' <form method="POST" action="'.$_SERVER['PHP_SELF'].'"> <input type="radio" name="response" value="f">Follow Move <input type="radio" name="response" value="s">Sit In<br> <input type="submit" name="submit" value="Submit"> <input type="hidden" name="submit_check" value="1"/> </form> '; } else { echo $_POST['response']; } } ?> Do that. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 I think he means He wants to get the RESPONSE back to the form. right? Quote Link to comment 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.