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

Related Questions

I am working on a basic HTML page that requires the user to send
I am looking for a tool to send html emails from WCF Service. Currently
i've been trying to send data to the following form from my view. i
QUESTION: Is it better to send large data blobs in JSON for simplicity, or
I have a simple html form with two controls: input-text and input-file I need
I'm using the PHP native mail() function to send HTML emails and have a
Which is better in AJAX request, Response with ready HTML or response with just
Can anyone tell me the best way to send some xml data from one
I have an HTML form which contains a drop down, a tinyMCE textarea, and
Im trying to post to a multipart html form using CURLs CURLOPT_POSTFIELDS, but I

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.