0

I am creating a form in php. ai have given address of other file in action. LIke I have created A.php, and in action of A.php I have given address of processing file, Like takeinput.php. But now I have issue is I am validating A.php in action file that is takeinput.php. Suppose if name field is null. I have easily validate that. But what happen if error is occured. Will it again be navigated to A.php or I have to use header to navigate back to A.php

takeinput.php

$fname= $_REQUEST["fname"];
if ($fname==''){
$error='Field can't be empty.' exit();

}

Now i need to use header to locate back to A.php or it will automatically be navigated on error. I am newbie help me with concept.

Rahul Singh
  • 1,614
  • 6
  • 22
  • 39
  • 1
    Nothing is automatic. you're going to have to use header to navigate back to your original file. Or you could include the original file, which makes refilling your form variables easier but can make for strange page reloads and browser history. – enobrev Sep 28 '11 at 03:43

1 Answers1

0

You can use empty() construct to validate input. You can also use isset() construct to check whether a a variable is set and is not NULL.

if(empty($fname))
 {

 }

You can use header() construct to request a new resource.

header("Location: file.php");
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • That means no. of times on takeinput.php I am validating form I have to use header to naaavigate abck on error. – Rahul Singh Sep 28 '11 at 03:50
  • @RahulSingh : Yes but you can avoid it though the use of JavaScript especially when it is possible to validate user input at client side. – KV Prajapati Sep 28 '11 at 03:53
  • ok thats a other case. I wish to do it with pure PHP. How would I check if javascript is enabled on client side or not using PHP ? I mean I want to show him my form only on condition if javascript is enabled. – Rahul Singh Sep 28 '11 at 03:56
  • @RahulSingh - No you can't. Read this thread - http://stackoverflow.com/questions/4454551/check-if-javascript-is-enabled-with-php – KV Prajapati Sep 28 '11 at 03:58