Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2013
    Location
    Calgary AB,Canada
    Posts
    55
    Thanks
    28
    Thanked 1 Time in 1 Post

    HTML Forms - Need Information

    Hi,

    I am a Junior Web Developer, just got into this 3 months ago. I need to understand the basics in the following code :

    Code:
    <form method="post" action="contact_touch_media_test.php" name="contact-us" id="contact-us"  onsubmit="return checkForm();" >
    <input type="submit" name="submit" value=" Send " />

    Can anybody explain me what happens (in sequence) immediately after submit button is clicked ?
    If the checkForm() validation routine returns "false" the value of submit button becomes "false" ? Please explain me the mechanism behind it ?

    I am just coding this without understanding what is happening behind the scene.

    And also on the server side I am having this following code :

    PHP Code:
    <?php
    if (isset($_POST['submit']))
    echo(
    "sendContactEmail();");
    ?>
    what is the value of $_POST['submit'] if the validation routine checkForm() returns "false" or will it be "send" ?

    OR

    Is it , that the submit button will not get activated if this checkForm() routine returns "false".

    Please explain.

    thanks a bunch,

    Isaac

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,789
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    The checkForm() function inside the onsubmit event handler is a JavaScript function. JavaScript is a client-side technology, that means it is parsed and executed by the browser (the “client”) while PHP is parsed and executed on the server. Both technologies never interact directly with each other.

    So, what happens now is that when the JS function checkForm() is returning “false”, the submit event is prevented all along and PHP never even sees anything sent to itself. PHP doesn’t even know that any interaction has taken place on the page because JS prevented it from being sent to the server. Makes sense?

    “return false” in JavaScript events is basically preventing the default event from occurring, that is, following links when clicked or submitting a form when submit button is pressed, for example.

  • #3
    New Coder
    Join Date
    Jun 2013
    Location
    Calgary AB,Canada
    Posts
    55
    Thanks
    28
    Thanked 1 Time in 1 Post
    Thanks a lot for the explanation. Thanks again.

    So I have a few questions on this.

    1. Is "onSubmit" an event hanler ?
    2. Could you please explain me the meaning of "(isset($_POST['submit']))" ?


    thanks a lot.


    Isaac

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,789
    Thanks
    6
    Thanked 1,022 Times in 995 Posts

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The event handler is "onsubmit" - not "onSubmit". JavaScript is case sensitive and as a JavaScript event handler the best place to place the code is in the separate JavaScript file and not by jumbling the JavaScript with the HTML.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New Coder
    Join Date
    Jun 2013
    Location
    Calgary AB,Canada
    Posts
    55
    Thanks
    28
    Thanked 1 Time in 1 Post
    Thank you.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •