PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,451 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,577 people online right now. Registration is fast and FREE... Join Now!




How to ask user to enter data

 

How to ask user to enter data

ho-ho

1 Jul, 2009 - 08:11 AM
Post #1

New D.I.C Head
*

Joined: 4 May, 2009
Posts: 39

Hi, I a Data.php page in which the user enters the data. Once the data is entered , it is directed to another page called validating.php. However if the user does not enter the data, I am sending the page back to Data.php using header. It works just fine.I want to know how can I ask the user to enter data once it's back to Data.php and where would that code be placed.
Thanks.
CODE


//Data.php
<form id="form1" name="form1" method="post" action="validate.php.php">
  <label>First Name:</label>
  <label>
  <input type="text"   name ="FN" />

//validate.php

if(isset($_POST['Submit']))
  {
if(!empty($FN))
    {
   $FN = $_POST['FN'];
   }
   else
   if(empty($FN))
   {
    Header('Location: Data.php');
    exit;
    }
}


User is offlineProfile CardPM
+Quote Post


CTphpnwb

RE: How To Ask User To Enter Data

1 Jul, 2009 - 08:58 AM
Post #2

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
Instead of posting to another file and deciding where to go from there, I'd use $_SERVER['php_self'] and do all the validation in the same page. Then if everything validates I'd do a header command to go to the appropriate page. Of course, this means that you need to do validation before showing the form, but that's easy:

CODE
If(isset($POST))
{
// code to validate
}
// if post has validated, header will have been sent to go to different file
// if not, show form:
?>
<html>
.
.
.
<form action="<?php echo $_SERVER['php_self']; ?>" >
.
.
.

User is offlineProfile CardPM
+Quote Post

ho-ho

RE: How To Ask User To Enter Data

1 Jul, 2009 - 09:13 AM
Post #3

New D.I.C Head
*

Joined: 4 May, 2009
Posts: 39

Thanks
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:52AM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month