Call to function from action attribute of form tag

Status
Not open for further replies.

parkourmumbai

New Member
Messages
34
Reaction score
0
Points
0
Is it possible to give a call to a function from the 'action' attribute of a form tag, instead of the action attribute set to another webpage or a php page?

I have a dynamically generated webpage which displays comments for a particular aspect of my website, sort of like comments are displayed in wordpress blog articles.
But I'm not using any blogging/CMS/or other package for the website, the entire thing, backend/frontend/business logic et al, is hand-coded.

In the page, the comments are displayed below the data with which they are connected, and at the bottom I have a small form with 2 inputboxes and 1 textarea to enter the comment along with the person's details.

When the user clicks the submit button, I need my php scripts within the webpage to do some complex checking and validation, give the user a javascript dialog box if any fields are left blank or don't pass validation, and pass an insert statement to the db using parameterized queries, and refresh the page to display the latest comment. So all my code for the webpage itself, the form processing, the interactions with the db at the time of insert, and the validation, needs to be on a single webpage.

I am encapsulating most of the validation and insert functionality into a function, and need to know if it is possible to send a call to the function from the action attribute of the form tag, instead of having it navigate to another page/file which holds all the processing code.
 

dickey

New Member
Messages
128
Reaction score
0
Points
0
I don't know if this works but try to put
action="Javascript:function()"
 

parkourmumbai

New Member
Messages
34
Reaction score
0
Points
0
Thanks man, but I've solved my problem. I've finally decided to give in and go the intermediate form processing page route, so I don't need to call a function from within the action tag anymore. All the functionality has been shifted to the other webpage processing the form.

Issue resolved.
Edit:
How do you close your own threads?
 
Last edited:

dickey

New Member
Messages
128
Reaction score
0
Points
0
when posting a quick reply there is an extra check box below the 'quote message in reply'

If you still want to try then the solution is to remove the action property.
and put the javscript function in the onclick event of the submit button. :)
 

parkourmumbai

New Member
Messages
34
Reaction score
0
Points
0
If you still want to try then the solution is to remove the action property.
and put the javscript function in the onclick event of the submit button. :)
Already done that, but what about server-side executing php functions?


And I don't get that extra checkbox. Must have something to do with my newbie status on the message boards.
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
If you look at the post-its at the top of this forum you'll the close threads option is not working since... May I think.
 

parkourmumbai

New Member
Messages
34
Reaction score
0
Points
0
Actually, I only saw the other sticky at the top of the board which said, rather pleaded with users to close their own threads after they were done, and that the moderator was sick of closing everyone's threads. ;)

Anyway, before I get the ability to close this thread, or a mod comes along to do the same, could someone please answer this quick question -

Is it possible to give a function call to a php function from the action attribute of a form tag? I know javascript works with the onsubmit attribute.

And @dickey,
Actually you don't need to remove the action attribute if you're using the onsubmit attribute. I've used both in my form, and they work well together. It first executes the function called from onsubmit, and then goes on to process whatever's in the action attribute, no clashes.
 

xmakina

New Member
Messages
264
Reaction score
0
Points
0
not like javascript, no.

BUT you can make a hidden input containing the action and then an IF statement in the PHP file. I do that a lot with my scripts (keeps the user on one page but does 2 or 3 different things)

HTML:
<form action="response.php" method="GET">
<input name="action" type="hidden" value="change">
<input type="text" value="name">
<input type="submit">
</form>

<form action="response.php" method="GET">
<input name="action" type="hidden" value="delete">
<input type="submit">
</form>

and in the PHP File

PHP:
function change(){
//Code
}
function delete(){
//Code
}

if($_GET['action'] == "change"){
change();
}
elseif($_GET['action'] == "delete"){
delete()
}
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Actually, I only saw the other sticky at the top of the board which said, rather pleaded with users to close their own threads after they were done, and that the moderator was sick of closing everyone's threads. ;)
If you read further, the last post was made by another mod saying it didn't work ^^
 
Status
Not open for further replies.
Top