Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Call to function from action attribute of form tag

  1. #1
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Call to function from action attribute of form tag

    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.

  2. #2
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Re: Call to function from action attribute of form tag

    I don't know if this works but try to put
    action="Javascript:function()"

  3. #3
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Re: Call to function from action attribute of form tag

    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 by parkourmumbai; 10-09-2008 at 08:53 AM. Reason: Automerged Doublepost

  4. #4
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Re: Call to function from action attribute of form tag

    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.

  5. #5
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Re: Call to function from action attribute of form tag

    Quote Originally Posted by dickey View Post
    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.

  6. #6
    Salvatos's Avatar
    Salvatos is offline x10 Lieutenant Salvatos is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    Québec, Canada
    Posts
    271

    Re: Call to function from action attribute of form tag

    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.

  7. #7
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Re: Call to function from action attribute of form tag

    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.

  8. #8
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: Call to function from action attribute of form tag

    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 Code:
    <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 Code:
    function change(){
    //Code
    }
    function 
    delete(){
    //Code
    }

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

    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

  9. #9
    Salvatos's Avatar
    Salvatos is offline x10 Lieutenant Salvatos is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    Québec, Canada
    Posts
    271

    Re: Call to function from action attribute of form tag

    Quote Originally Posted by parkourmumbai View Post
    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 ^^

  10. #10
    parkourmumbai is offline x10Hosting Member parkourmumbai is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    34

    Re: Call to function from action attribute of form tag

    Allright mods, issue is resolved, you can close this thread now whenever you see this.

Closed Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. DW error message
    By bunglebrown in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 10-06-2008, 03:11 PM
  2. Replies: 5
    Last Post: 01-12-2008, 06:19 AM
  3. Easy XHTML form validation using PHP
    By Xemnas in forum Tutorials
    Replies: 0
    Last Post: 01-08-2008, 04:29 AM
  4. Call to undefined function curl_init.
    By ggreen88 in forum Free Hosting
    Replies: 5
    Last Post: 09-27-2007, 01:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers