Jump to content

Same document form execution


Ch3vr0n

Recommended Posts

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.

Link to comment
Share on other sites

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>";
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.