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

  • SEARCH
  • Home
  • 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 8340089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:04:44+00:00 2026-06-09T05:04:44+00:00

My situation I have a piece of javascript that does several manipulations on a

  • 0

My situation

I have a piece of javascript that does several manipulations on a webform on form.php. The form is set to action="form.php" and thus loads itself upon submission. The webform is only built if (!isset($_POST['submit'])), so after posting, the input elements and containers that make up the webform are not there. This is generally how the code is structured:

<?php if (!isset($_POST['submit'])) { 
//the form has not been submitted
?>
  <form action="<?php $_SERVER['PHP_SELF']?>" method="post" id="form" name="form">
    <!-- general input elements -->
    <input type="submit" name="submit" value="Send">
  </form>
<?php }
else {
// the form has been submitted
  // posted values are submitted to a database
}
?>

The javascript still tries to do manipulations on these elements, though. Since these aren’t there anymore, errors occur. I could use a bunch of if (HTMLElement) statements for every manipulation to a certain HTMLElement, but I hope there is a more solid, more general solution.

The question

Given that the form submits to its page and that it’s not an option to simply keep showing the form after POSTing, do you have a suggestion how I can detect the POSTing of the webform and shut certain parts of my javascript down?

A more general question would be:

How can a php POST be detected by javascript?

  • 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-06-09T05:04:47+00:00Added an answer on June 9, 2026 at 5:04 am

    One thing that comes to mind is something like this:

    <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') $isPost = true; ?>
    
    // later on in your script
    
    <?php if (!$isPost): ?>
    <script type="text/javascript">
    // the JS code that manipulates your form
    </script>
    <?php endif; ?>
    

    Basically, if the form was posted, don’t render the JS code that manipulates it. If that code is mixed with other code you always want included, then you’ll have to work it a little differently. In that case you could try:

    <script type="text/javascript">
    var isPost = <?php echo $isPost ? 'true' : 'false' ?>;
    
    if (!isPost) {
        document.getElementById('blah').doSomething();
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where there is a small piece of Java code that
In a new piece of code I have several different classes that refer to
We have a piece of functionality that is used by several different applications (clients)
Using Python 2.7 Situation: I have some piece of Python code (that the user
Situation: I have an index page which loads pages into it with ajax as
Situation I have a client library that uses the Windows Azure AppFabric Service Bus
I have situation, where running a query that filters by an indexed column in
This is a pretty odd situation I have here. I have used a piece
I have seen that the situation is very problematic after reading these: IE6/IE7 css
Here is the situation. I have a thread that gets started with the click

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.