Menu

Beat and Broken! Anyone want a project?

Help
RedMoon
2007-03-02
2013-06-03
  • RedMoon

    RedMoon - 2007-03-02

    Do you ever try so hard at something and then you can't do it and you want to cry?  That's where I am.  This program is SO user friendly and yet I can't figure out a little programming to get it to do what I want. =0(

    OK. I am willing to PAY for someone's services at this point.  I've created some forms that need validation.  I'm trying to beef up the validation on the process.php page by adding different expression syntax (or is it syntai? Or syntaxs?  I'm burnt. I don't know).  Please be patient with me.  I just started learning php and some other webworld stuff in the last few weeks.  I'm trying to kick my Microsoft habit.

    My normal working form (this is only part of it) looks like the following:
    ---------------------------------
    $Notes=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Notes);if($ChooseItem=="" || $FirstName=="" || $LastName=="" || $Identification=="" || $Identification_=="" || $Address=="" || $City=="" || $Province=="" || $Country=="" || $Telephone=="" || $EMail=="" || $Donations=="" || $PayUsing=="" ){
    $errors=1;
    $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
    }
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EMail)){
    $error.="<li>Invalid email address entered";
    $errors=1;
    }
    if($errors==1) echo $error;
    ----------------------------------------

    That's what the PHPFormGenerator kicked out.  It works perfectly but since what I want to do is make it so that "FirstName", "LastName", etc. has to go through a verification like only allowing letters or for the drop down boxes not allowing "*" is the selection, I rigged up a little "!eregi" party.  I figured if one eregi worked so well with "email", then it should be GREAT for my other validations.  The following is the "eregi" party I threw in my process.php file.

    -------------------------------------------
    $Notes);if($ChooseItem=="" || $FirstName=="" || $LastName=="" || $Identification=="" || $Identification_=="" || $Address=="" || $City=="" || $Province=="" || $Country=="" || $Telephone=="" || $EMail=="" || $Donations=="" || $PayUsing=="" ){
    $errors=1;
    $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
    }
    if(!eregi("^[a-z]+([\s-.]{2,}$",$ChooseItem)){
    $error.="<li>Please choose an item to purchase.";
    $errors=1;
    }
    if(!eregi("^[a-z]+([\s-]{2,}$",$FirstName)){
    $error.="<li>Please enter your full first name.";
    $errors=1;
    }
    if(!eregi("^[a-z]+([\s-]{2,}$",$LastName)){
    $error.="<li>Please enter your last name(s).";
    $errors=1;
    }
    if(!eregi("^[a-z]+([_\\.-][^\*]{2,}$",$Identification)){
    $error.="<li>Please choose your form of identification.";
    $errors=1;
    }
    if(!eregi("^[a-z0-9]+{4,}$",$Identification_)){
    $error.="<li>Please enter your cedula or passport number.";
    $errors=1;
    }
    if(!eregi("^[a-z0-9]*([\s-]{2,}$",$Title)){
    $error.="<li>Please enter your title.";
    $errors=1;
    }
    if(!eregi("^[a-z]*([\s-]{2,}$",$Company)){
    $error.="<li>Please enter your company name.";
    $errors=1;
    }
    if(!eregi("^[a-z0-9]+([_\\.-]{2,}$",$Address)){
    $error.="<li>Please enter your address.";
    $errors=1;
    }
    if(!eregi("^[a-z0-9]+([_\\.-]{2,}$",$City.)){
    $error.="<li>Please enter your city.";
    $errors=1;
    }
    if(!eregi("^[a-z]+([_\\.-][^\*]{2,}$",$Province)){
    $error.="<li>Please choose your province or district.";
    $errors=1;
    }
    if(!eregi("^[a-z]+([_\\.-]{2,}$",$Country)){
    $error.="<li>Please enter your country.";
    $errors=1;
    }
    if(!eregi("^[0-9]+([_\\.-]{7,10}$",$Telephone)){
    $error.="<li>Please enter your telephone number.";
    $errors=1;
    }
    if(!eregi("^[0-9]*([_\\.-]{7,10}$",$Fax)){
    $error.="<li>Please enter your fax number.";
    $errors=1;
    }
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EMail)){
    $error.="<li>Please enter a valid email address entered";
    $errors=1;
    }
    if(!eregi("^[a-z]+([_\\.-][^\*]$",$Donations)){
    $error.="<li>Please choose the organization you would like us to donate to.";
    $errors=1;
    }
    if(!eregi("^[a-z0-9]+([_\\.-%][^\*]{2,}$",$PayUsing)){
    $error.="<li>Please choose your payment method.";
    $errors=1;
    }
    if($errors==1) echo $error;
    else{
    -------------------------------------------------------

    Any ideas?  Anybody want to bid on the job?  I really want to understand and learn for myself so it would only be the one above.  Hopefully I'll be able to see and understand what was done and I can do the others myself.

    Pura Vida from Costa Rica!
    Athena

     
    • TNTEverett

      TNTEverett - 2007-03-02

      I can help you but your going to have to explain what your intention was for the syntax checking of each variable. 
      Send me a link to your form so I don't have to recreate anything. 

       
    • RedMoon

      RedMoon - 2007-03-03

      Hi Everet,

      Thanks for responding.  The form is located at: http://mediosecologicos.com/ajra/use/orders/form1.html .  The other links on the page don’t work yet because the pages haven’t been loaded.  I wanted to get the forms working first.

      “ChooseItem”, “Identification”, “Province”, “Donations”, and “PayUsing” are all drop down boxes.  It’s tricky to do any validation on a drop down because technically it’s already validated by leaving it at the default, which is usually an option.  I thought that maybe I could get around this by having my heading entries (choose one, Costa Rica, Panama, etc) begin and end with an asterisk and then denying those entries in the syntax check for drop downs.  Hopefully that way it will force a pick.

      I’m curious to know if I’m not using the eregi command correctly for multiple validations rather than just for e-mail or are my strings just ca-ca? =0)

      Syntax Explanations---
      Choose Item: Allow letters A-Z (mandatory) white space, dashes and periods allowed.  At least two letters must be entered.  This is a drop down box but I was considering making the first choice in the selection “not allowed”.
      if(!eregi("^[a-z]+([\s-.]{2,}$",$ChooseItem)){
      $error.="<li>Please choose an item to purchase.";
      $errors=1;

      FirstName: Allow letters A-Z (mandatory) white space and dashes allowed.  At least two letters must be entered.
      if(!eregi("^[a-z]+([\s-]{2,}$",$FirstName)){
      $error.="<li>Please enter your full first name.";
      $errors=1;

      LastName: Allow letters A-Z (mandatory) white space and dashes allowed.  At least two letters must be entered.
      if(!eregi("^[a-z]+([\s-]{2,}$",$LastName)){
      $error.="<li>Please enter your last name(s).";
      $errors=1;

      Identification:  Allow letters A-Z (mandatory) underscores, backslashes, periods, and dashes.  Do not allow the symbol *.  At least two letters must be entered.  -Drop down box-
      if(!eregi("^[a-z]+([_\\.-][^\*]{2,}$",$Identification)){
      $error.="<li>Please choose your form of identification.";
      $errors=1;

      Identification_: Allow letters A-Z and numbers 0-9 (mandatory) white space allowed.  At least 4 characters must be entered.
      if(!eregi("^[a-z0-9]+[\s]{4,}$",$Identification_)){
      $error.="<li>Please enter your cedula or passport number.";
      $errors=1;

      Title: Not mandatory entry but if something is entered it should be letters A-Z and numbers 0-9.  White space and dashes allowed and be at least two characters.
      if(!eregi("^[a-z0-9]*([\s-]{2,}$",$Title)){
      $error.="<li>Please enter your title.";
      $errors=1;

      Company: Not mandatory entry but if something is entered it should be letters A-Z and numbers 0-9.  White space and dashes allowed and be at least two characters.
      if(!eregi("^[a-z]*([\s-]{2,}$",$Company)){
      $error.="<li>Please enter your company name.";
      $errors=1;

      Address: Allow letters A-Z and numbers 0-9 (mandatory).  Underscores, backslashes, periods, dashes, and white space allowed.  Two or more characters.
      if(!eregi("^[a-z0-9]+([_\\.-\s]{2,}$",$Address)){
      $error.="<li>Please enter your address.";
      $errors=1;

      City: Allow letters A-Z and numbers 0-9 (mandatory).  Underscores, backslashes, periods, dashes, and white space allowed.  Two or more characters.
      if(!eregi("^[a-z0-9]+([_\\.-\s]{2,}$",$City.)){
      $error.="<li>Please enter your city.";
      $errors=1;

      Province: Allow letters A-Z (mandatory) underscores, backslashes, periods, dashes, and white space.  Do not allow the symbol *.  At least two letters must be entered.  -Drop down box-
      if(!eregi("^[a-z]+([_\\.-\s][^\*]{2,}$",$Province)){
      $error.="<li>Please choose your province or district.";
      $errors=1;

      Country: Allow letters A-Z (mandatory). Underscores, backslashes, periods, and dashes allowed.  Two or more characters required.
      if(!eregi("^[a-z]+([_\\.-]{2,}$",$Country)){
      $error.="<li>Please enter your country.";
      $errors=1;

      Telephone:  Allow numbers 0-9 (mandatory).  Dashes and periods allowed.  Seven to ten numbers required.
      if(!eregi("^[0-9]+([\.-]{7,10}$",$Telephone)){
      $error.="<li>Please enter your telephone number.";
      $errors=1;

      Fax: Not mandatory entry but if something is entered it should be numbers 0-9.  Dashes and periods allowed and seven to ten numbers required.
      if(!eregi("^[0-9]*([\.-]{7,10}$",$Fax)){
      $error.="<li>Please enter your fax number.";
      $errors=1;

      Email:  This string expression was generated by PHPFG and works perfectly. No help needed here.

      Donations: Allow letters A-Z (mandatory) underscores, backslashes, periods, and dashes.  Do not allow the symbol *.  At least two letters must be entered.  -Drop down box-
      if(!eregi("^[a-z]+([_\\.-][^\*]$",$Donations)){
      $error.="<li>Please choose the organization you would like us to donate to.";
      $errors=1;

      Pay Using: Allow letters A-Z and numbers 0-9 (mandatory) underscores, backslashes, periods, dashes and percent signs.  Do not allow the symbol *.  At least two letters must be entered.  -Drop down box-
      if(!eregi("^[a-z0-9]+([_\\.-%][^\*]{2,}$",$PayUsing)){
      $error.="<li>Please choose your payment method.";
      $errors=1;

       
      • TNTEverett

        TNTEverett - 2007-03-03

        Since it is difficult for me to interpret exactly what you want, and because I don't agree with some of your constraints I giving you this test code (process.php) to help you along.  You can test all you want until you get it right and then cut and paste into your own process.php code. 

        I have fixed a few errors and gave comments on teh syntax used.  Most of the rest are commented out.  You can uncomment them one at a time until you are satisfied that they work and then move on to the next one. 
        Common errors:

        You don't need $ end of line for everything.

        ^[a-z0-9]+{4,}",$Identification
        The {4,} indicates a repeat of preceeding syntax, but you can not repeat teh start of line.
        Correction would be
        ^([a-z0-9]+){4,}",$Identification
        repeat what is in parenthesis.

        (!eregi("^[a-z]*([\s-]{2,}$",$Company))
        The dash is interpretted as indicating a range from (s to ]), impossible of course but this is how it is interpretted.  This special charcater is best delimited by the \ character. 

        I can stil help you along but I think it's best if you get yourself started then ask me for more specific advise. 

        Some good advice, don't try to control everything otherwise no one will be able to fill in your form.  Some people never capitalize or punctuate anything.  If you have a nown simple list, limit to items in the list.  You can not fake out a pull down list.  The only options for the form are in the list.  You can default a list in a much simpler way.  If you have known unwanted characters, limit only unwanted characters.  Keep it simple, keep it simple, keep it simple where ever possible. 

        <?php
        include("global.inc.php");
        $errors=0;
        $error="The following errors occured while processing your form input.<ul>";
        pt_register('POST','Notes');
        pt_register('POST','ChooseItem');
        pt_register('POST','FirstName');
        pt_register('POST','LastName');
        pt_register('POST','Identification');
        pt_register('POST','Identification_');
        pt_register('POST','Address');
        pt_register('POST','City');
        pt_register('POST','Province');
        pt_register('POST','Country');
        pt_register('POST','Telephone');
        pt_register('POST','EMail');
        pt_register('POST','Donations');
        pt_register('POST','PayUsing');

        $Notes=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Notes);
        if($ChooseItem=="" || $FirstName=="" || $LastName=="" || $Identification==""
           || $Identification_=="" || $Address=="" || $City=="" || $Province=="" || $Country==""
           || $Telephone=="" || $EMail=="" || $Donations=="" || $PayUsing=="" ) {
           $errors=1;
           $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
           }
        if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EMail)) {
        $error.="<li>Invalid email address entered";
        $errors=1;
        }
        //A single capitol Letter followed by any number of lower case letters,
        //followed by zero or more (zero or more (space one capitol letter any number of lower case letters)
        //zero or more (space one capitol letter any number of numbers))
        if(!eregi("^[A-Z]?[a-z]+(\s[A-Z]+[a-z]*)*(\s[A-Z]+[0-9]+)*",$ChooseItem)) {
           $error.="<li>Please choose an item to purchase.";
           $errors=1;
           }
        //A single capitol Letter followed by any number of lower case letters
        if(!eregi("^[A-Z]?[a-z]*",$FirstName)) {
           $error.="<li>Please enter your full first name.";
           $errors=1;
           }
        //A single capitol Letter followed by any number of lower case letters a dot or dash
        if(!eregi("^[A-Z]+[a-z.\-]*",$LastName)) {
           $error.="<li>Please enter your last name(s).";
           $errors=1;
           }
        //Not sure what you need here
        if(!eregi("^[a-z]+([_\\.-][^\*]{2,})",$Identification)) {
           $error.="<li>Please choose your form of identification.";
           $errors=1;
           }

        if(!eregi("^([a-z0-9]+){4,}",$Identification_)) {
           $error.="<li>Please enter your cedula or passport number.";
           $errors=1;
           }
        /*if(!eregi("^[a-z0-9]*([\s-]{2,}$",$Title)) {
           $error.="<li>Please enter your title.";
           $errors=1;
           }
        if(!eregi("^[a-z]*([\s-]{2,}$",$Company)) {
           $error.="<li>Please enter your company name.";
           $errors=1;
           }
        if(!eregi("^[a-z0-9]+([_\\.-]{2,}$",$Address)) {
           $error.="<li>Please enter your address.";
           $errors=1;
           }
        //if(!eregi("^[a-z0-9]+([_\\.-]{2,}$",$City.)) {
        //   $error.="<li>Please enter your city.";
        //   $errors=1;
        //   }
        if(!eregi("^[a-z]+([_\\.-][^\*]{2,}$",$Province)) {
           $error.="<li>Please choose your province or district.";
           $errors=1;
           }
        if(!eregi("^[a-z]+([_\\.-]{2,}$",$Country)) {
           $error.="<li>Please enter your country.";
           $errors=1;
           }
        if(!eregi("^[0-9]+([_\\.-]{7,10}$",$Telephone)) {
           $error.="<li>Please enter your telephone number.";
           $errors=1;
           }
        if(!eregi("^[0-9]*([_\\.-]{7,10}$",$Fax)) {
           $error.="<li>Please enter your fax number.";
           $errors=1;
           }
        if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EMail)) {
           $error.="<li>Please enter a valid email address entered";
           $errors=1;
           }
        if(!eregi("^[a-z]+([_\\.-][^\*]$",$Donations)) {
           $error.="<li>Please choose the organization you would like us to donate to.";
           $errors=1;
           }
        if(!eregi("^[a-z0-9]+([_\\.-%][^\*]{2,}$",$PayUsing)) {
           $error.="<li>Please choose your payment method.";
           $errors=1;
           }
        if($errors==1) {
           echo $error;
           }
          */

        if(1) { echo $error;

        ?>

        <!-- This is the content of the Thank you page, be careful while changing it -->

        <h2>Thank you!</h2>
        <table width=50%>
        <tr><td>FirstName: </td><td> <?php echo $FirstName; ?> </td></tr>
        <tr><td>LastName: </td><td> <?php echo $LastName; ?> </td></tr>
        <tr><td>Identification: </td><td> <?php echo $Identification; ?> </td></tr>
        <tr><td>Identification_: </td><td> <?php echo $Identification_; ?> </td></tr>
        <tr><td>Address: </td><td> <?php echo $Address; ?> </td></tr>
        <tr><td>City: </td><td> <?php echo $City; ?> </td></tr>
        <tr><td>Country: </td><td> <?php echo $Country; ?> </td></tr>
        <tr><td>Telephone: </td><td> <?php echo $Telephone; ?> </td></tr>
        <tr><td>EMail: </td><td> <?php echo $EMail; ?> </td></tr>
        <tr><td>Donations: </td><td> <?php echo $Donations; ?> </td></tr>
        <tr><td>PayUsing: </td><td> <?php echo $PayUsing; ?> </td></tr>
        <tr><td>Notes: </td><td> <?php echo $Notes; ?> </td></tr>
        <tr><td>ChooseItem: </td><td> <?php echo $ChooseItem; ?> </td></tr>
        <tr><td>Error: </td><td> <?php echo $error; ?> </td></tr>

        </table>
        <!-- Do not change anything below this line -->

        <?php
        }
        ?>

         
    • RedMoon

      RedMoon - 2007-03-04

      EVERET!
      THANKYOUTHANKYOUTHANKYOU!!!  You’re an ANGEL.  I know this is a forum for PHPFG on not for lessons on PHP but you helped me anyway.  Your response was also kind instead of beating me up.  I appreciate it.  I was really frazzled.  I followed your instructions and I’m taking it line by line and it’s actually working.  FYI: even adding the [^\*] for the drop down boxes is working.  I couldn’t have done it without you.  There’s a girl in Costa Rica who LOVES you!

      Athena
      Happily on my way to finally completing my website.

       
      • TNTEverett

        TNTEverett - 2007-03-04

        Glad I could help.  I know regular expression syntax can be tricky.  You are welcome to come back and ask questions any time.  
        phpFormGenerator is a great tool.  It's also our opportunity to learn a little more about using php.

        Enjoy!

        BTW, here is another place you can learn alot about PHP.  I use it all the time. 
        http://www.w3schools.com/php/default.asp

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.