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";
}
Not knowing the structure of your framework, you can use php’s header
And just above your form:
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:
and you retrieve it in index with
$pageToInclude = $_GET['page'];//properly sanitizedor use
and in index you use