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 335099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:07:02+00:00 2026-05-12T10:07:02+00:00

Is it better to send an html form to a seperate page, or send

  • 0

Is it better to send an html form to a seperate page, or send it back to the same page??

i keep hearing to seperate logic from presentation, so I was wondering if I should seperate my forms from my form handlers as well.

As of now, Im doing this…

<?php

if(isset($_POST['submitted'])){

  //Validate the form
  if(empty($_POST['name'])){
    $errors['name'] = 'Please enter your name';
  }

  //IF no errors INSERT INTO database and redirect
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <input type="text" name="name" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" />
  <?php if(isset($errors['name'])) echo '<span class="error">'.$errors['name'].'</span>'; ?>
  <input type="submit" />
</form>

Is this good, or should I completely seperate the php from the form and just include one into the other… or something of the sort

  • 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-12T10:07:02+00:00Added an answer on May 12, 2026 at 10:07 am

    I actually find having the submission processing logic in a separate file that would be included (in my class a class) allows you to keep your logic away from the presentation, but have the errors of validation/etc appear directly on your form where you expect them to. A small example of what I propose:

    <?php // form.php
      $form = array(
         "test"=>"default value",
      );
      $errors = array();
    
      if (count($_POST)) {
        include "form.process.php";
      }
    
      if (count($errors)) {
        echo "<ul class='errors'>";
        foreach ($errors as $error) {
          echo "<li>".htmlentities($error)."</li>";
        } 
        echo "</ul>";
      }
    ?>
    <form method="POST"> <!-- no action means submit to the same page you are on -->
    <input type='text' name='test' value='<?php echo $form["test"]; ?>'/>
    <input type='submit'>
    </form>
    

    Then in form.process.php

     <?php
       if (isset($_POST['test')) {
         $test = $form['test'] = $_POST['test'];
         if (!trim($test)) // empty string? {
           $errors[] = "Please fill in test field";
         }
       }
    
       if (!count($errors)) {
         header("Location: formsubmitted.php");
         exit;
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 250k
  • Answers 250k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is one of those questions where you need to… May 13, 2026 at 9:21 am
  • Editorial Team
    Editorial Team added an answer There's no reason to use list comprehension here. Python 3.x:… May 13, 2026 at 9:21 am
  • Editorial Team
    Editorial Team added an answer The onsubmit handler on your <form> is looking for a… May 13, 2026 at 9:21 am

Related Questions

I would like to send a print job to the printer without the user
I want to bounce an idea around. I have been building web services and
I am using XAMPP on a localhost windows VISTA m/c...using gmail as smpt server
What I'm trying to do is provide a form where a user can type

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.