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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:10:33+00:00 2026-05-24T12:10:33+00:00

I want to redirect to the page which has a form when user submit

  • 0

I want to redirect to the page which has a form when user submit the form without any parameters, also I want to return an error message, how can I redirect from controller to the form?

<form action="controllers/Customer.controller.php" method="post">

    <label for="cellPhoneNo">cell phone number</label>
    <input type="text" name="cellPhoneNo" class="textField"/>

    <label for="telephone">telephone number</label>
    <input type="text" name="telephone" class="textField"/>

    <input type="submit" name="searchCustomer" value="بحث"/>
</form>

and here’s the Customer.controller.php page

  if(trim($_POST['cellPhoneNo']) == "" && trim($_POST['telephone']) ==""){

  //include('Location:index.php'); //what I supposed to write here?
   echo "empty";
}
  • 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-24T12:10:34+00:00Added an answer on May 24, 2026 at 12:10 pm

    Not knowing the structure of your framework, you can use php’s header

    if(trim($_POST['cellPhoneNo']) == "" && trim($_POST['telephone']) ==""){
    
       $_SESSION['error'] = 'Fields cannot be empty!';
       header('Location: myformlocation.php');
       exit(); 
    }
    

    And just above your form:

    <?php if(isset($_SESSION['error'] )) : ?>
    
    <div class="error"><?php echo $_SESSION['error'];?></div>
    
    <?php 
    unset($_SESSION['error']); 
    endif; ?>
    
    
    <form action="controllers/Customer.controller.php" method="post">
    

    So, whenever the form submits, if fields are empty, the form page is reloaded and, since $_SESSION error is now set, it will be displayed. You might want to make a function out of $_SESSION[‘error’] displaying, so you won’t writing all that code in each form.

    EDIT after comment:
    Uhm, I’m not really sure to understand your question, you can use either $_GET:

    header("Location: ../index.php?page=customerSearch"); 
    

    and you retrieve it in index with
    $pageToInclude = $_GET['page']; //properly sanitized

    or use

    $_SESSION['pageToInclude'] = 'CustomerSearch'; 
    $_SESSION['error'] = 'Fields cannot be empty!';
    header('Location: myformlocation.php');
    ....
    

    and in index you use

    $pageToInclude = isset($_SESSION['pageToInclude']) ? $_SESSION['pageToInclude'] : 'someotherdefaultpage';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to redirect users to an error page if they enter any URL
I'm looking to redirect users to a new page once the form has been
i want to do these thing: 1.open the login_view (which is the page user
OK so I have a User which has_one Template and I want a page
Iam working on Ubuntu.(Linux) I want to redirect from the page one.php to two.php,
i want to redirect peaple who goes in my site to other page if
I want to make my php page only accessible from another page redirect and
i want a handler to redirect to a web-forms page, pre-filling in the values
I want to pass a few variables to another page. Currently I'm using response.redirect
I want to know whether 301 redirect always preserve referrer. I make a page

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.