SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Quick validation question

    Hi all

    I have a FORM that requires the user to input stuff.. surprise! (not).. okay.. then I have some validation regular expressions for the fields of the form.

    Then I have the form displayed AGAIN if the user has entered something in wrongly in the first form. The way I do this is by using an $ErrorArray variable to keep an incremental store of errors.

    What I was now wondering is, on the re-displayed form, how to code it so that fields with an error are returned to being blank (for re-entry) and fields which are validated 'okay' contain the valid data that was entered previously.

    Thanks.

    Mak

  2. #2
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If an entry is invalid, just unset the value's variable and the according field will be empty.

  3. #3
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, sorry I have not helped you much lately...

    Been busy, although to your question; the part of your script which registers the actual error message, ie

    PHP Code:
    $errorArray[] = 'Please enter your email address';
    .

    Maybe instead of relying on incremental indexing, why not use assocc ?

    PHP Code:
    .
    .
    # checking email FROM INPUT from user at this point...
    $errorArray['Email'] = 'Please enter your email address';
    .
    .
    # rest of script 
    Now then, to check if you need to put the email address back to the FORM; ie the email address is valid, then you simply check for this array index being null or empty ?

    If so, then take the $_POST[...] sent by the user via form submission and place this back into the FORM ?

    PHP Code:
    # part of script to re-display FORM due to finding bad inputs from user
    .
    .
    $flag = false;
    #msg = '';
    if(empty($errorArray['Email'])) {
    # email address was okay so keep it
    $msg = $_POST['email'];
    }
    # now create the INPUT box again
    <input type='text' name='email' value='<?php echo($msg); ?>' size='16' maxlength='48'>
    .
    .
    # check for next INPUT box etc
    That'd work for you ?

  4. #4
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Great, that works

    However, what I was wondering is when I have a drop-down box, it does not appear to remember the last option selected:
    PHP Code:
    // Validate relation_select
      if (empty($_POST["relation_select"])) {
       $ErrorArray["relation_select"] = "Please select who is posting this profile.";
      }
     
    if(empty($ErrorArray["relation_select"])) {
      $okrel_select = $_POST["relation_select"];
     }
     
    <SELECT NAME="relation_select" class="formselect" value="<?php echo($okrel_select); ?>" />
    <OPTION SELECTED VALUE="">Select</OPTION>
    <?php
           
    while ($rel_q mysql_fetch_array($relation_query)) {
                
    $relation_id $rel_q["relationID"];
                
    $relation_type $rel_q["relationType"];
                echo(
    "<OPTION VALUE='$relation_id'>$relation_type<BR>\n");
       }
    ?>
    </SELECT>
    Any ideas?

    Thanks.

    Mak

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure myself, can anyone else help out here ?

  6. #6
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Do you think it is because a drop-down box doesn't use a 'value' property like a text box does?

    In that case, do you know how I would set the proper option to 'selected'?

    Thanks.

    Mak

  7. #7
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A dropdown menu uses values. You have to check whether the value is equal to a different value or not. If it is equal, output "selected".


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •