#1
  1. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Okay, I hope you all can forgive, I have been writing Perl for quite a long time, and am new to PHP, most of my questions are going to be about functionals while I transition between the languages.

    I am curious about building required field check routines, Naturally I can swing in the ereg_ functions of PHP.

    Anyone have pointers on how they approach making sure the user actually fills in the blanks for fields that are "NOT NULL" in the mysql database?

    And lastly, what's the best approach of returning the user back to their form with
    the "un-submitted" data still in the fields?

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    Anyone have pointers on how they approach making sure the user actually fills in the blanks for fields that are "NOT NULL" in the mysql database?


    You can check empty fields using empty() or isset() function.




    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    + if you set the form action to <?php echo $PHP_SELF;?>

    and in the form fields
    <input type="text" name="firstfield" value=<?php echo $firstfield;?>">

    when the form returns to itself the firstfield value will be returned as $firstfield - and if this field was not set then the field value will be blank.

    Simon.



    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  6. #4
  7. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    [QUOTE}
    You can check empty fields using empty() or isset() function.
    [/QUOTE]

    I will have to look up the empty() one, am familiar with the isset(), guess I wasn't really thinking in the right terms..

    Thanks for the info. Am new to the PHP and so far I love it



    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  8. #5
  9. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    That certainly gives a bit more meaning for me on using the php tags in the input values.

    But I am still left with a bit of question, maybe a recommendation from you..

    They user doesn't enter the data, so the field is rejected, and we are going to bring back the form, what's the best approach?

    exit? stop the script in it's tracks?



    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  10. #6
  11. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    I personally prefer client side validation with JavaScript - but there is the grand total of about 2.5% of surfers without(or have turned off?)Javascript - Client side methods wont send the form until it is complete, a faster cleaner method IMHO.

    As for php - on the receiving page just test for the variables ie: if you have 2 fields posted from the form ,say $f1 & $f2 - at the start of your code just add

    <?php if(!$f1 &#0124; &#0124; !$f2){?><script>window.location.href="back_to_form.path"</script><?php } else { ?> rest of code<?php } ?>

    you are basically testing for the existence of the fields before you even bother with the rest of your code. (you may have to use <script>document.write("window.location.href="path.path"")</script> - I can not remember right now!)

    The very-very best way is to submit a form to itself because it is easier to manage and much quicker to load - this can look complicated even if it is not! - a simplified example:

    <html>
    <head>
    <script>
    function cvalid(){
    if(document.fone.tester.value=="") {alert("Please enter your name");return false;}
    }
    </script>

    <body>
    <?php if(!$submit){?>
    <form name="fone" method="post" action="<?php echo $PHP_SELF;?>" onsubmit="return cvalid()">
    name:<input type="text" name="tester" value="">
    <input type="submit" name="submit">
    </form>
    <?php }else { ?><!-- //if submit is clicked// -->
    <form>
    your name is:<input type="text" name="tester" value="<?php echo $tester;?>">
    </form>
    <?php } ?>
    </body></html>

    This is with a simple Javascript validation which just tests if 'tester' is not empty - you could as easily do -<?php if(!$submit &#0124; &#0124; !$tester){etc - but the Javascript is quicker.

    Hope this helps.

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  12. #7
  13. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks a bunch.. will toy with the whole process.

    never been a bin fan of javascript validation, but I suppose, it offers a solution.

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  14. #8
  15. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    One last thing, in regards to validating with
    the PHP.

    In your example you are using a js statement to return to the form.

    which if we post the data via php_self, we are posting to the same document, we simply refresh the document if there are missing fields.

    Those fields which were previously filled in, will return to being filled in because of the <?php echo $the variablevalue; ?> in the value attribute of the forms input tag.

    This would apply, even if we post the form to a different php document to process the data?

    I'm guessing I'm just being a bit lazy

    I'm working with a form which inputs data to about 6 tables, a nice little normalized database for customer data.. my first real work with this language... anyway, I'm sure I'll figure it all out, and find a method that I'm happy with.

    I've found it a bit of fun in writing small php code to create db tables and populate those table with data..

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  16. #9
  17. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    no the javascript does not post the form back to itself - it stops the form from being submitted in the first place unless the validation is errr valid! so to speak.

    And yes submitting to a seperate form does the same job as submitting to itself - I just personally find this a cleaner/neater solution - and a couple of milliseconds faster!.

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  18. #10
  19. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by firepages:
    no the javascript does not post the form back to itself - it stops the form from being submitted in the first place unless the validation is errr valid! so to speak.

    And yes submitting to a seperate form does the same job as submitting to itself - I just personally find this a cleaner/neater solution - and a couple of milliseconds faster!.
    [/quote]

    Thanks for the clarification..

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.

Similar Threads

  1. Inserting from form to multiple tables
    By barth in forum MySQL Help
    Replies: 0
    Last Post: January 25th, 2004, 10:27 AM
  2. Replies: 1
    Last Post: January 20th, 2004, 10:14 PM
  3. cgi.pm module not compatible with multipart enctype syntax
    By Suzette in forum Perl Programming
    Replies: 2
    Last Post: December 22nd, 2003, 12:19 PM
  4. return value from 3 fields into 1 field
    By denali in forum MS SQL Development
    Replies: 1
    Last Post: December 19th, 2003, 08:44 AM
  5. Validating a field with multiple criteria...
    By brotherloco in forum Java Help
    Replies: 0
    Last Post: October 29th, 2003, 08:40 AM

IMN logo majestic logo threadwatch logo seochat tools logo