Php coding help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • econstas
    Second Lieutenant

    • Jul 2006
    • 105

    Php coding help

    All,
    I would like to know where I could find a good tutorial for php. I learning this language..and I run into problems.

    Probably easy:
    $choice1= $HTTP_POST_VARS['choice1'];
    $choice2= $HTTP_POST_VARS['choice2'];
    $choice3= $HTTP_POST_VARS['choice3'];

    $ch1=strlen($choice1);
    $ch2=strlen($choice2);
    $ch3=strlen($choice3);

    if ($ch1 == 0 || $ch2 == 0 || $ch3 == 0)
    {
    echo "One of your fields is missing. Please use the Back Button to return to the form. Thank you!\n";
    exit;
    }



    Basically I have created a form: http://www.holleyjohnson.net/Holidaymusic.html

    I am working on the choices / time options for this form.. I would like to make it easier for down the road incase I need to add more choice options. I don't want to continously add if statements, becausethis code can get very long.

    Ideas?

    Thanks
    Stratis
    Website: www.holleyjohnson.net
    Thanks,
    Stratis

    www.holleyjohnson.net
    mailto: stratis.constas@holleyjohnson.net
  • Andy128
    Major General

    • Dec 2005
    • 2317

    #2
    Re: Php coding help

    The problem I can see with this is that your customer will become frustrated with being given an error statement but no specific remedy. As you say- your list can be very long. If one statement is to cover 8 fields- then potentially- they could be given a generic error statement several times with out knowing exactly how to fix it.

    I prefer echo error statements because they are easier than creating an entire page dedicated to one error. Additionally- I make them specific to each field.

    Just a thought

    Andy
    PHP- is a blast!

    Comment

    • navaldesign
      General & Forum Moderator

      • Oct 2005
      • 12080

      #3
      Re: Php coding help

      The echo statement only provides a blank page with the error message. Not very nice. What i think is needed here is:
      1. A loop, that will look at array keys, to see which fields are related to the name "choice". This can easily be done by only considering the first 7 letters of the $key, and attributing an incrementing index to the variable. The second part inside the loop, will be the validation.
      2. A second loop, for the second group of choices, of similar type.

      Consequently, if a validation error is found, the error gets a number, equal to the index itself.
      If you put the validation script in the beggining of the same page as the form, and the form calls itself as action, with a double if() statement, the first to see if the fields had already been filled in or not, and the second to check if there are any errors or not, and if there are, print ALL the errors in a pre-deternined text box, your work could be done with a very elegant and short code but you need to know some php to accomplish this.
      Navaldesign
      Logger Lite: Low Cost, Customizable, multifeatured Login script
      Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
      DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
      Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

      Comment

      • Andy128
        Major General

        • Dec 2005
        • 2317

        #4
        Re: Php coding help

        Yeah- what he said.
        PHP- is a blast!

        Comment

        • econstas
          Second Lieutenant

          • Jul 2006
          • 105

          #5
          Re: Php coding help

          Yeah, I come from a PERL background. Do you know of any good places to learn some PHP? Tutorials / books ??

          I was thinking of doing something similar on the option with loops to figure out If they are filled and not. If not, a value is given. Then at the end any values created will be printed onto the screen so the customer would know the problems. If all filled then onto the next step ...
          Thanks,
          Stratis

          www.holleyjohnson.net
          mailto: stratis.constas@holleyjohnson.net

          Comment

          • navaldesign
            General & Forum Moderator

            • Oct 2005
            • 12080

            #6
            Re: Php coding help

            Originally posted by Andy128
            Yeah- what he said.
            Hi Andy, this is what i mean:


            Particular conditions require particular soloutions. The validating part of script could be based in loops so if in the future he adds more options, it will automatically take them into account.
            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment

            • econstas
              Second Lieutenant

              • Jul 2006
              • 105

              #7
              Re: Php coding help

              Wow, I haven't seen flow charts since my programming days in school.. :) Its been awhile.
              Thanks,
              Stratis

              www.holleyjohnson.net
              mailto: stratis.constas@holleyjohnson.net

              Comment

              • Andy128
                Major General

                • Dec 2005
                • 2317

                #8
                Re: Php coding help

                Navaldesign-
                I am but a pup in the php field- I have lots to learn. Thanks for showing me another thing to learn.

                Yeah- what he said
                I was just being funny in that -it was way over my head.

                I must disagree with the echo statement method though. Instead of a balnk page one could put the php script inside an html box and place it in the middle of a regular web page matching the theme of ones website. It doesn't have to be a blank page. I prefer this to having to make up several error pages. One draw back is that you cannot have a header re-direct as was recently discussed on this forum. Because the echo statement is output to the browser- if you then have a header redirect it gives an error. In that instance I have to use -
                echo'<meta http-equiv="refresh" content="0; URL =location:http://whateverpage.com"/>';
                which is not as clean as the header redirect.

                again Navaldesign- thaks a bunch for all you help with php that you have given.

                Andy
                PHP- is a blast!

                Comment

                • econstas
                  Second Lieutenant

                  • Jul 2006
                  • 105

                  #9
                  Re: Php coding help

                  I was able to incorporate some loops into the script. I like to look a script and break it down. Now, its basically piece by piece.. :(




                  $choice[1]= $HTTP_POST_VARS['choice1'];
                  $choice[2]= $HTTP_POST_VARS['choice2'];
                  $choice[3]= $HTTP_POST_VARS['choice3'];
                  $max=3;



                  for ( $counter = 1; $counter <= $max; $counter += 1){

                  if (strlen($ch[$counter]) == 0){
                  echo "test $ch[$counter] = false\n";
                  }else {
                  echo "test $ch[$counter] = true\n";
                  }
                  }


                  I got this part to work.. its very basic.. but it works for the time. I will have to look more into the code. I am thinking of adding something like:
                  every false statement create another array .e.

                  $false[$f]=" Field $choice[$choice] needs to be filled\n";
                  $f+=1;

                  Then set another for loop after all the work is done and run the loop that will print out all false statements. Thinking on the code itself.


                  Thanks again,
                  Stratis
                  Thanks,
                  Stratis

                  www.holleyjohnson.net
                  mailto: stratis.constas@holleyjohnson.net

                  Comment

                  • navaldesign
                    General & Forum Moderator

                    • Oct 2005
                    • 12080

                    #10
                    Re: Php coding help

                    As said above, create another loop that will grab not only ALL the choices but all required fields as well. Th e key to this is that :
                    1. You get a -R f.e. in your field names: choice1-R where -R stands for required.
                    2. The script will look for the last two characters in the $key variable, so if a field is required, it will perform the validation, if not, it won't.
                    3. The same loop will create an array with all the required fields for which it has not found a value, as well as relevant error messages, so, according to the flow chart posted above, it will submit to itself, so it can then, when reloaded, grab again the variables, as well as the error messages, and display them in an appropriate textbox, or empty the fields and print the field titles in another colour.
                    Navaldesign
                    Logger Lite: Low Cost, Customizable, multifeatured Login script
                    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                    Comment

                    • davidundalicia
                      General

                      • Mar 2006
                      • 6294

                      #11
                      Re: Php coding help

                      Navaldesign:
                      I would love to see your coding for that elegant solution above !!
                      Have fun
                      Regards..... David

                      Step by Step Visual Tutorials for the complete beginner
                      Newbies / Beginners Forum
                      FREE Membership Login Scripts: - Meta Tags Analyzer
                      My Social Networking Site - Free Contact Forms
                      Finished your New website!! Now get it noticed Here:

                      Comment

                      • navaldesign
                        General & Forum Moderator

                        • Oct 2005
                        • 12080

                        #12
                        Re: Php coding help

                        I will prepare an example form in the next days.
                        Navaldesign
                        Logger Lite: Low Cost, Customizable, multifeatured Login script
                        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                        Comment

                        • davidundalicia
                          General

                          • Mar 2006
                          • 6294

                          #13
                          Re: Php coding help

                          Looking forward to seeing it naval...................
                          Have fun
                          Regards..... David

                          Step by Step Visual Tutorials for the complete beginner
                          Newbies / Beginners Forum
                          FREE Membership Login Scripts: - Meta Tags Analyzer
                          My Social Networking Site - Free Contact Forms
                          Finished your New website!! Now get it noticed Here:

                          Comment

                          • econstas
                            Second Lieutenant

                            • Jul 2006
                            • 105

                            #14
                            Re: Php coding help

                            I ended up getting the situation fixed.

                            Basic good goes like:

                            $name = $HTTP_POST_VARS['name'];
                            $email = $HTTP_POST_VARS['email'];
                            $cellphone = $HTTP_POST_VARS['cellphone'];
                            $venue_yes = $HTTP_POST_VARS['venueyes'];

                            # Array to have all sites checked.

                            $myarray[1]= $groupname;
                            $myarray[2]= $name;
                            $myarray[3]= $participant;
                            $myarray[4]= $cellphone;
                            # This array is set up to have individual Error Messages. I can cator each error to a different kind of message.

                            $charray[1]= "No Group Name";
                            $charray[2]= "No Contact Name";
                            $charray[3]= "How many are performing?";
                            $charray[4]= "No Contact Phone Number";


                            $max=4;
                            for ( $counter = 1; $counter <= $max; $counter += 1){

                            if ($myarray[$counter] == ""){
                            $e_array[$a]=$charray[$counter];
                            $a +=1;
                            }}

                            if ($e_array){
                            $esize=count($e_array);

                            print "<FONT=14>One of your coices for performing fields is missing. Please use the Back Button to return to the form. Thank you!</FONT><br>";

                            PRINT "----------------------------------------------------------<BR>";
                            for($ecount=1; $ecount<=$esize; $ecount +=1){
                            if ($e_array[$ecount]){
                            print "FAILED: $e_array[$ecount]<br>\n";
                            }
                            # else{ "PASSED##: $e_array[$ecount]<br>\n";}

                            }
                            exit;}

                            Then I had the script email me the results..

                            I would still like to see the idea that was mentioned earlier.

                            Thanks,
                            Stratis
                            Thanks,
                            Stratis

                            www.holleyjohnson.net
                            mailto: stratis.constas@holleyjohnson.net

                            Comment

                            • navaldesign
                              General & Forum Moderator

                              • Oct 2005
                              • 12080

                              #15
                              Re: Php coding help

                              Hi Straris,

                              you might want to take a look at http://www.vodahost.com/vodatalk/for...form-help.html

                              regarding the use of loops for sending repeated fields as in your case.
                              Navaldesign
                              Logger Lite: Low Cost, Customizable, multifeatured Login script
                              Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                              DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                              Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                              Comment

                              Working...
                              X