Ch3vr0n Posted March 7, 2011 Share Posted March 7, 2011 I've been using php for a while now to create forms, up until now i've always transmitted the form data to a new php document that then processes them. I wanna take this to the next level and start trying to process the data within the same document. I know this has something to do with checking if the submit button is pressed and then processing the submitted data but thats about as far as my knowledge goes. Can anyone help me out on how i can achieve this type of thing. The reason is that i've found a way to execute php code within a joomla 1.6 environment without having to use the iframe option. I know the iframe option may be easier in a way of doing things but its out of the question. The final fase of the php will output code that will trigger a specific joomla plugin to do some specific action. If i pull a php document via an iframe the plugin doesnt trigger as it only gets triggered after the joomla "afterRender" (or something" has executed. If i use the iframe option then that rendering never gets used so the plugin doesnt get triggered. So in a nutshell, i wanna create forms that submit data and that data gets processed in the same document (in this case joomla article). How do i go about doing this. Quote Link to comment https://forums.phpfreaks.com/topic/229820-same-document-form-execution/ Share on other sites More sharing options...
joel24 Posted March 7, 2011 Share Posted March 7, 2011 have an IF ISSET declaration to check whether any forms are posted, if not just echo the normal page. i.e. if (isset($_POST['submitButton'])) { //do whatever with the form } else { //form not sent, so echo form to be filled out echo "<form method='POST'> <input name='input1' type='text' /> <input type='submit' name='submitButton' value='Submit Form'/> </form>"; } Quote Link to comment https://forums.phpfreaks.com/topic/229820-same-document-form-execution/#findComment-1183801 Share on other sites More sharing options...
Ch3vr0n Posted March 7, 2011 Author Share Posted March 7, 2011 can't possibly be that simple ? What if i have multiple submit buttons on the same page (each with their own name ofc) Quote Link to comment https://forums.phpfreaks.com/topic/229820-same-document-form-execution/#findComment-1183978 Share on other sites More sharing options...
PFMaBiSmAd Posted March 7, 2011 Share Posted March 7, 2011 Yes it is that simple, however you wouldn't put the form in an else{} condition because you would want the ability to redisplay the form if there was a form processing error (without repeating code.) See the following post for how you would generally do this - http://www.phpfreaks.com/forums/index.php?topic=325639.msg1533568#msg1533568 If you have more than one form, you would just add conditional logic to test which submit button is set. Only the form processing code that is within the if(){} conditional test that is TRUE will be executed. The point of programming is to write code that does what you want, when and where you want it. You just write conditional logic so that your code does what you want it to do when the page is requested, either when it is browsed to or when your form(s) submits to it. Quote Link to comment https://forums.phpfreaks.com/topic/229820-same-document-form-execution/#findComment-1183981 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.