Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5841559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:54:19+00:00 2026-05-22T11:54:19+00:00

I’m using a PHP file (as part of a wordpress plugin), which contains several

  • 0

I’m using a PHP file (as part of a wordpress plugin), which contains several functions.
One of them builds an html form and another one deals with the submitted form.
I’ve added to the function that builds the form a submit() function in which I call an asynchronous function.
In order for it to finish before the form is submitted I’m using preventDefault() and a call to submit() when the async function finishes.
The problem is that my call to submit() after preventDefault() causes different results in the PHP function that handles the submitted form than the original submit.

Here’s the PHP code:

if(isset($_POST['submit-reg']))
{
    $output = sreg_process_form($atts); 
    return $output;
}
else
{
    $data = array();
    $form = simplr_build_form($data, $atts);        
    return $form;               
}

When I don’t use preventDefault() and submit() the condition is positive and the form is submitted normally.
When I do use them the second part is executed and the form is being rebuilt instead of submitted.
So the question is: what in preventDefault() and then submit() causes isset($_POST['submit-reg'])) to be false and how can I fix it?
edit: Here’s the JS:

$('#simplr-reg').submit(function(event)
{           
    event.preventDefault();
    codeAddress(function(success){}); //callback from googlemaps
});

function codeAddress(callback)
{               
    var geocoder = new google.maps.Geocoder();

    geoCodingStarted = true;

    geocoder.geocode( { 'address': address}, function(results, status)
    {
        if (status == google.maps.GeocoderStatus.OK) 
        {   
            var latitude = results[0].geometry.location.lat();
            var longitude = results[0].geometry.location.lng();
            $("input[name=latitude]").val(latitude); 
            $("input[name=longitude]").val(longitude);      

            $('#simplr-reg').submit();          
        }                   
    });         
}  // end of code address
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:54:20+00:00Added an answer on May 22, 2026 at 11:54 am

    When you submit the form via normal methods then submit-reg is set. When you use preventDefaul() and send the form asynchronously then the value is never set, because the form is never submited, altough it’s processed asynchronously. You should use another method to check is the form is being processed or built. Perhaps a hidden field. or another flag set dinamicaly on the page.

    From the W3C

    17.13.3 Processing form data

    When the user submits a form (e.g., by
    activating a submit button), the user
    agent processes it as follows.

    Step one: Identify the successful controls

    Step two: Build a form data set

    A form data set is a sequence of
    control-name/current-value pairs
    constructed from successful controls

    Step three: Encode the form data set

    The form data set is then encoded
    according to the content type
    specified by the enctype attribute of
    the FORM element.

    Step four: Submit the encoded form
    *data set*

    Finally, the encoded data is sent to
    the processing agent designated by the
    action attribute using the protocol
    specified by the method attribute.

    This specification does not specify
    all valid submission methods or
    content types that may be used with
    forms. However, HTML 4 user agents
    must support the established
    conventions in the following cases:

    • If the method is "get" and the action
      is an HTTP URI, the user agent takes
      the value of action, appends a `?’ to
      it, then appends the form data set,
      encoded using the
      “application/x-www-form-urlencoded”
      content type. The user agent then
      traverses the link to this URI. In
      this scenario, form data are
      restricted to ASCII codes.
    • If the method is "post" and the action is an
      HTTP URI, the user agent conducts an
      HTTP “post” transaction using the
      value of the action attribute and a
      message created according to the
      content type specified by the enctype
      attribute. For any other value of
      action or method, behavior is
      unspecified.

    User agents should render the response
    from the HTTP “get” and “post”
    transactions.

    When you use preventDefault() you prevent this from happening making the variable ´submit-reg` unexistant because it is never set.

    More info from jQuery site

    Now when the form is submitted, the
    message is alerted. This happens prior
    to the actual submission, so we can
    cancel the submit action by calling
    .preventDefault() on the event object
    or by returning false from our
    handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm making a simple page using Google Maps API 3. My first. One marker
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
In order to apply a triggered animation to all ToolTip s in my app,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.