Jump to content

call a function from a form action


blueman378

Recommended Posts

ho guys, well i have a function that is included in all pages on the site,

 

however i was wondering if i can call it from a form action,

 

so something similar to

 

echo "<form action=\"$catadmin->show_subs($_POST[mainid]);\" method=\"post\">";

obviously that wont work, i know i could do it through having a variable it sends bit i was wondering if it is possible to call it to run directly from the form action?

Link to comment
Share on other sites

If you want to do something with the user's input after displaying the page but BEFORE form submission, you can use javascript.

 

If you want to do something AFTER form submission then you can do that in the script which receives the form data.

 

If you want to do something BEFORE form display, then you can do that in the script which displays the form.

 

That covers all 3 situations (before form display, after display but before submission, and after submission).

 

Does that make sense?  I'm not sure which of those 3 situations you want in your example.

Link to comment
Share on other sites

yeah im more curious than anything,

 

like i am doing it after the form has been submitted and a new page loads,

i know i can have eg a hidden field in the form and check if that is set if it si then run the function i was jsut wondering if it is possible to run it directly from the action buti  giess not|

 

thanks

Link to comment
Share on other sites

You can't run a php function directly from a form action .. but there are a number of alternatives depending on what you want.

 

1.  Use AJAX to send a request to php, and use javascript to display the response in the browser (or to modify the form before submission)

2.  Just submit the form with a hidden variable set and have php pick up on that, and do whatever you want it to do.

 

AJAX is the solution when you want to fetch data from php without reloading and redisplaying the entire page.

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.