form validation 
Author Message
 form validation

Hi,

I need to validate a form wether there are entries left unfilled. If
there are such entries, then the previous form is re-generated, with
the filled entries keep intact, and a message noting what entries to
fill.

The tracking which entries left unfilled part is done, but the
regeneration part with previous contents still eludes me. Can somebody
help me?

TIA
Xeon



Mon, 25 Jul 2005 06:20:37 GMT  
 form validation


Quote:
> Hi,

> I need to validate a form wether there are entries left unfilled. If
> there are such entries, then the previous form is re-generated, with
> the filled entries keep intact, and a message noting what entries to
> fill.

> The tracking which entries left unfilled part is done, but the
> regeneration part with previous contents still eludes me. Can somebody
> help me?

check the following website:
http://www.walkington.net/test/checkbox.php

If there is an error, the form is presented again.  I am
leaving the boxes checked just as they were submitted the first time.

The code prints out and you can see how I am doing it.

--
Alan Walkington
Technical Staff
United Defense, San Jose

Quote:
> TIA
> Xeon



Mon, 25 Jul 2005 06:33:40 GMT  
 form validation

Quote:

> The tracking which entries left unfilled part is done, but the
> regeneration part with previous contents still eludes me. Can somebody
> help me?

The simpelest approach would be something like below, this page
validates itself and does something when it all checks out.

<?php
if(isset($_POST['submitted']))
{
   $err=false;

   if(strlen($_POST['lastname'])<4)
   {
      $_POST['lastname']='';
      $err=true;
   }

   if($err)
   {
      echo "<strong> you didn't fillin all required fields</strong>";
   }
   else
   {
      die("Thank, you for completing the form");
   }

Quote:
}

?>
<form method='POST' action='<?php echo $_SERVER['PHP_SELF'];?>'>
<input type='text' name='lastname' value='<?php echo $_POST['lastname';?>'>
<input type='submit' name='submitted' value='submit'>
</form>

--

  Daniel Tryba



Mon, 25 Jul 2005 06:37:30 GMT  
 form validation


Quote:
> Hi,

> I need to validate a form wether there are entries left unfilled. If
> there are such entries, then the previous form is re-generated, with
> the filled entries keep intact, and a message noting what entries to
> fill.

Another trick you might want to consider is changing the font color
of the html control label if the field is invalid. This is friendly for the
user.

later
jim



Mon, 25 Jul 2005 16:05:02 GMT  
 form validation


Quote:



> > Hi,

> > I need to validate a form wether there are entries left unfilled. If
> > there are such entries, then the previous form is re-generated, with
> > the filled entries keep intact, and a message noting what entries to
> > fill.

> > The tracking which entries left unfilled part is done, but the
> > regeneration part with previous contents still eludes me. Can somebody
> > help me?

> check the following website:
> http://www.walkington.net/test/checkbox.php

> If there is an error, the form is presented again.  I am
> leaving the boxes checked just as they were submitted the first time.

> The code prints out and you can see how I am doing it.

> --
> Alan Walkington
> Technical Staff
> United Defense, San Jose

> > TIA
> > Xeon

I don't know if it's just me, but I tried going to this URL.  I got the page
with the checkboxes and unchecked the "repeat" box as instructed to see the
source.  It looked like it tried to display the source, but before it
completed, my browser displayed the usual 404 page not found error.

Regards,
Dang Nguyen



Mon, 25 Jul 2005 16:26:14 GMT  
 form validation

Quote:

> I don't know if it's just me, but I tried going to this URL.  I got the
page
> with the checkboxes and unchecked the "repeat" box as instructed to see
the
> source.  It looked like it tried to display the source, but before it
> completed, my browser displayed the usual 404 page not found error.

> Regards,
> Dang Nguyen

I'm sure this person is smart enough to correct that when they find out.  I
saw a little of the code and
it is well written.  Try hitting the stop button a couple times and you'll
see most of the
code before it goes to the 404 message.

What interests me being new to all this is when I tried view source it
doesnt look like the
html I'd use to construct a similar page.

for example...

<TD align ="left"><LABEL for="recruit">Is the organization you represent a
 staffing service?</LABEL>
<TD> <INPUT type= "checkbox" name= "staffing" value="yes" id="temp">
</COLGROUP>
<TR>



Mon, 25 Jul 2005 16:56:23 GMT  
 form validation

Quote:

> What interests me being new to all this is when I tried view source it
> doesnt look like the
> html I'd use to construct a similar page.

> for example...

> <TD align ="left"><LABEL for="recruit">Is the organization you represent a
>  staffing service?</LABEL>
> <TD> <INPUT type= "checkbox" name= "staffing" value="yes" id="temp">
> </COLGROUP>
> <TR>

I assume you mean the <label> tags? That's accessibility design. It is useful
for example, to allow a motor-impaired person to click anywhere on the line
(<label>) to select the checkbox. The <colgroup> is also useful for voice
readers.


Mon, 25 Jul 2005 22:24:23 GMT  
 form validation

Quote:

> I don't know if it's just me, but I tried going to this URL.  I got the
page
> with the checkboxes and unchecked the "repeat" box as instructed to see
the
> source.  It looked like it tried to display the source, but before it
> completed, my browser displayed the usual 404 page not found error.

Hmmm ...
I have tried accessing the site from work on IE5, and several varieties of
Mozilla on a *NIX platform and was unable to duplicate your problem.

The code was a demonstration of how to programatically reset checkboxs to
whatever the user had input.
----------------------------------------------------------------------------
--------------------
<?php
//  specify the number of checkboxes to create
    $maxboxes = 5;

// 'load the user names into an array
    for ($i = 0; $i < $maxboxes; $i++){
        $id = $i + 1;
        $user_names[$i] = "user $id";
    }
// and create the 'checked' value array
    for ($i = 0; $i < $maxboxes; $i++){
        $box_status[$i] = "";
    }

// if it's not the first time through, then check for 'errors'
    if (isset($_POST['submit'])){
        // all we are REALLY checking here is to see if the repeat checkbox
is set
        if ($_POST['repeat']){
            echo "To exit, you must uncheck the 'repeat' checkbox!<br><hr>";
            // set the 'box_status' array for each checked box to 'checked'
            if ((isset($_POST['boxes'])) && (is_array($_POST['boxes']))) {
                while (list($key, $value) = each($_POST['boxes'])){
                    $box_status[$value] = "checked";
                }
            }
        }else {
        // no errors? then put up final display
            finish_up();
            exit();
        }
    }
    // this is where we create the display
    echo "<html>";
    echo "<body >";
    echo "<form name=\"testForm\" METHOD=\"POST\"
ACTION=\"$_SERVER['PHP_SELF']\">";
    // make a check box for each user
    for ($i = 0; $i < $maxboxes; $i++){
        echo "<input type=\"checkbox\"  $box_status[$i]  name=\"boxes[]\"
value=\"$i\">$user_names[$i]<br>";
    }
?>

<hr>
<input type="checkbox" name="repeat" checked> Repeat!<br>
<hr>
<p><input name="submit" type="submit" value="Submit");>
</form>
</body>
</html>

<?php
function finish_up() {
// here the last time through
    global $user_names;
    echo "<html>";
    echo "<body><h4>";

    if ((!isset($_POST['boxes'])) || (!is_array($_POST['boxes']))) {
        echo "<br>No checkboxes have been selected!";
    }else{
        echo "<br>The checked boxes are:<br>";
        while (list($key, $value) = each($_POST['boxes'])){
            echo "<br>Box $value ($user_names[$value]) is checked";
        }
    }
    reset ($_REQUEST);
    echo "</p><hr></h4>";
    show_source(basename($_SERVER['PHP_SELF']));

Quote:
}

?>
----------------------------------------------------------------------------
--

--
Alan Walkington
Technical Staff
United Defense, San Jose



Tue, 26 Jul 2005 05:13:25 GMT  
 form validation
Quote:

> check the following website:
> http://www.walkington.net/test/checkbox.php

Thanks for the snippet, but how about radio buttons (which is my main problems)?

TIA
Xeon



Sat, 30 Jul 2005 09:21:49 GMT  
 form validation


Quote:

> > check the following website:
> > http://www.walkington.net/test/checkbox.php

> Thanks for the snippet, but how about radio buttons (which is my main
problems)?

this works:
------------------------------------------------------------
<?php
// if you name all your rb's in a group 'radio' (for example), you will get
// back $_REQUEST['radio'] with the value set to the value you declared
// for that particular radio button.

// in this example we will name our buttons 'radio', and give them the
// values 'upper', 'middle', and 'lower'.  we will keep the status in the
// array  '$rb'

// we will preset the array for a default value, in this case 'upper'
// the term 'checked' (in both checkboxes and radio buttons) indicates
// that the page should display the button as selected

$rb = array('upper'=>"" ,'middle'=>"", 'lower'=>"");   // as many as we need
$default = 'upper';

// if there is a value in the $_REQUEST superglobal array
// we will set it into the our status array.
// otherwise we will set our default radio button 'checked';

if (isset($_REQUEST['radio'])) {
    $index = $_REQUEST['radio'];
    $rb[$index] = 'checked';

Quote:
} else {

    $rb[$default] = 'checked';

Quote:
}

echo "<form type='post' action=$_SERVER[PHP_SELF]>\n";

// here we put out the radio button html
// each is named 'radio', so they will be grouped together
// The 'value' is the key to our array ('upper', etc) and $checked
// is 'checked' for only one

foreach($rb as $key=>$checked){
 echo "<input type='radio' name='radio' value=$key $checked>$key<br>\n";

Quote:
}

// an input button
echo "<input type='submit' value='Push Me'\n>";
echo "</form>";
?>

-------------------------------------------------------------

Quote:
> TIA
> Xeon



Sun, 31 Jul 2005 12:39:26 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Form validation q

2. Form Validation

3. Form validation and page navigation

4. Form validation problem: URGENT

5. Field Validation in a Form

6. Validation of FORM fields

7. HTML Form data validation with Object REXX (Windows)

8. Date validation of input from HTML form

9. newbie with a php validation form mail script problem

10. clientside validation of checkboxes from PHP form

11. J Form Editor resizing a form?

12. J Form Editor resizing a form

 

 
Powered by phpBB® Forum Software