php-general Digest 28 May 2013 21:17:21 -0000 Issue 8249

Topics (messages 321217 through 321221):

Re: iterate javascript verification
        321217 by: Ken Robinson
        321218 by: Tim Dunphy

Header Keep-Alive
        321219 by: Al
        321220 by: Sebastian Krebs

need some regex help to strip out // comments but not http:// urls
        321221 by: Daevid Vincent

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message --- When you do validation of the form in the same script that shows the form, the normal way to do this is

<?php
   if (isset($_POST['submit'])) {
//
//  validation here
//
    }
?>

This won't work if you're getting to the page via another form, since the $_POST['submit'] is set. There two ways of avoiding this:

1) use hidden fields in each form to indicate which form was submitted
2) use a different name for each form's submit button and use that in the above code

Ken


At 12:52 PM 5/27/2013, Tim Dunphy wrote:
Hey guys,

Thanks for the input! This is pretty nice, and DOES work. I like the fact
that the fields have been into an iterative array. It's a very elegant
solution. However the problem with this approach is that if you load the
page directly it works. But if you call the page from the index.php page
you get an initial error on all fields as they are all quite naturally
empty when you first load the page.

Here's the index.php page. All it is is HTML, no php:

<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>LDAP Request Form</title>

<body>
  <center><h3>LDAP Request Form</h3>
   <form name="form_request" method="post" action="ldap.php"
onsubmit="return validateForm()">
    <label for="requestor_email">Your Email Address:</label><br />
    <input type="text" required id="requestor_email" name="requestor_email"
/><br /><br />
    <label for="num_forms">How Many Forms Do You Need:</label><br />
    <input type="text" required maxlength="2" size="5" id="num_forms"
name="num_forms" /><br /><br />
    <input type="submit" name="submit" value="Submit" />
  </form></center>
</body>
</html>

And here is ldap.php as was suggested:

<body>

  <?php

   if (isset($_POST['submit'])) {
    $requestor_email = $_POST['requestor_email'];
    $num_forms  = $_POST['num_forms'];
    }


    echo "<center>You will be creating $num_forms accounts
today.</center><br />";
    for($counter = 1;$counter<=$num_forms;$counter++) {
        echo '<center><form name="ldap_accounts" method="post"
action="sendemail.php" onsubmit="return validateForm()">';
        echo '<br /><br />';
        echo "Enter user: $counter<br /><br />";
        echo "<label for=\"first_name_.$counter.\">First Name:</label><br
/>";
        echo "<input type=\"text\" id=\"first_name_.$counter.\"
name=\"first_name_.$counter.\" /><br /><br />";
        echo "<label for=\"last_name_.$counter.\">Last Name:</label><br />";
        echo "<input type=\"text\" id=\"last_name_.$counter.\"
name=\"last_name_.$counter.\" /><br /><br />";
        echo "<label for=\"department_.$counter.\">Department:</label><br
/>";
        echo "<input type=\"text\" id=\"department_.$counter.\"
name=\"department_.$counter.\" /><br /><br />";
        echo "<label for=\"title_.$counter.\">Title:</label><br />";
        echo "<input type=\"text\" id=\"title_.$counter.\"
name=\"title_.$counter.\" /><br /><br />";
        echo "<label for=\"email_.$counter.\">Email:</label><br />";
        echo "<input type=\"text\" id=\"email_.$counter.\"
name=\"email_.$counter.\" /><br /><br />";
        echo "<label for=\"phone_$counter.\">Phone:</label><br />";
        echo "<input type=\"text\" id=\"phone_.$counter.\"
name=\"phone_.$counter.\" /><br /><br />";
  }

  echo "<input type=\"hidden\" id=\"num_forms\" name=\"num_forms\"
value=\"$num_forms\" /><br /><br />";
  echo "<input type=\"hidden\" id=\"requestor_email\"
name=\"requestor_email\" value=\"$requestor_email\" />";
  echo "<input type=\"submit\" name=\"submit\" value=\"Create Ticket\" />";
  echo "</form></center>";




   ?>


Why this happens when you call the ldap.php page from index.php but not
when you load the page directly beats me. But maybe someone can shed some
light on that?

Thanks!



On Sat, May 25, 2013 at 3:45 AM, tamouse mailing lists <
tamouse.li...@gmail.com> wrote:

> On Fri, May 24, 2013 at 9:51 PM, Ken Robinson <kenrb...@rbnsn.com> wrote:
> > I took your code and modified it to use HTML5 validation (and few other
> > changes). You can see the results at
> > <http://my-testbed.com/test1/form_validation.php>
> http://my-testbed.com/test1/form_validation.php
> >
> > My code follows:
> >
> >   <?php
> >   $fields =
> > array('first_name','last_name','department','title','email','phone');
> >   $num_forms = 1;
> >   $tmp = array();
> >   $errors = array();
> >
> >
> >    if (isset($_POST['submit'])) {
> >     $requestor_email = $_POST['requestor_email'];
> >     $num_forms  = $_POST['num_forms'];
> >     for ($i = 1;$i <= $num_forms; ++$i) {
> >         foreach ($fields as $fld) {
> >                 if ($_POST[$fld][$i] == '') {
> >                         $errors[] = ucwords(str_replace('_',' ',$fld)) .
> "
> > for account $i can not be blank";
> >                 }
> >         }
> >     }
> >   }
> >                 if (!empty($errors)) {
> >                         $tmp[] = "The following fields are in
> error:<br>";
> >                         $tmp[] = implode("<br>\n",$errors);
> >                         $tmp[] = "<br>";
> >                 }
> >     $tmp[] = "<div style='text-align:center'>You will be creating
> $num_forms
> > accounts today.</div><br>";
> >     $tmp[] = '<div style="text-align:center"><form name="ldap_accounts"
> > method="post" action="">';
> >     $tmp[] = '<br /><br />';
> >
> >     for($counter = 1;$counter<=$num_forms;$counter++) {
> >         $tmp[] = "Enter user: $counter<br />";
> >         $tmp[] = "<label for='first_name_$counter'>First
> > Name:</label><br/>";
> >         $tmp[] = "<input type='text' required id='first_name_$counter'
> > name='first_name[$counter]'><br /><br />";
> >         $tmp[] = "<label for='last_name_$counter'>Last Name:</label><br
> />";
> >         $tmp[] = "<input type='text' required id='last_name_$counter'
> > name='last_name[$counter]' /><br /><br />";
> >         $tmp[] = "<label
> > for='department_$counter'>Department:</label><br/>";
> >         $tmp[] = "<input type='text' required id='department_$counter.'
> > name='department[$counter]' /><br /><br />";
> >         $tmp[] = "<label for='title_$counter'>Title:</label><br />";
> >         $tmp[] = "<input type='text' required id'title_.$counter'
> > name='title[$counter]' /><br /><br />";
> >         $tmp[] = "<label for='email_.$counter'>Email:</label><br />";
> >         $tmp[] = "<input type='email' required id='email_.$counter'
> > name='email[$counter]' /><br /><br />";
> >         $tmp[] = "<label for='phone_$counter'>Phone:</label><br />";
> >         $tmp[] = "<input type='text' required id='phone_$counter'
> > name='phone[$counter]' /><br /><br />";
> >   }
>
>
> You can DRY this up (the HTML input fields) similarly to the way you
> did the validation above...
>
> for ($i = 1;$i <= $num_forms; ++$i) {
>    foreach ($fields as $fld) {
>      $tmp[]="<label for='$fld_$counter'>" . ucwords(str_replace('_','
> ',$fld) . ":</label><br />";
>      $tmp[]="<input type='text' required id='$fld_$counter'
> name='$fld[$counter]' /><br /><br />";
>    }
> }
>
> Further, you could also check the validity of field right at the point
> of generation and issue the error right next to the field in error,
> which is usually a better UX.
>
> >   $tmp[] = "<input type='hidden' id='num_forms' name='num_forms'
> > value='$num_forms' /><br /><br />";
> >   $tmp[] = "<input type='hidden' id='requestor_email'
> name='requestor_email'
> > value='$requestor_email' />";
> >   $tmp[] = "<input type='submit' name='submit' value='Create Ticket' />";
> >   $tmp[] = "</form></div>";
> >
> > ?>
> > <!DOCTYPE html>
> >
> > <html>
> > <head>
> > <title>LDAP Form</title>
> > <body>
> >         <?php echo implode("\n",$tmp) . "\n"; ?>
> > </body>
> > </html>
> >
> > You will notice that I moved the code for the form to above the HTML
> > section. I believe that very little PHP should be interspersed with the
> HTML
> > -- it makes for cleaner code. You can use single quotes around form
> > attributes so you don't have to escape the double quotes. The names in
> the
> > form are now arrays. This makes your life much easier when extracting the
> > values later in PHP.
> >
> > When you check the page in a HTML5 aware brower, you will see how the
> > validation is done.
> >
> > Ken
> >
> >
> > At 10:17 PM 5/24/2013, musicdev wrote:
> >>
> >> You can validate via JS if required, for example: (JS CODE):
> >>
> >> if(element.value.length == 0){
> >>    // handle 0 length value
> >> }
> >>
> >> I do agree with Ken that you SHOULD NOT perform JS validation.  It is
> >> preferable to use php or the new HTML5 features.  JS can be turned-off
> by
> >> the user which will make JS validation impossible.
> >>
> >>
> >> On Fri, May 24, 2013 at 8:07 PM, Tim Dunphy <bluethu...@gmail.com>
> wrote:
> >>
> >> > Hello list,
> >> >
> >> >  I have a php script that creates a variable number of forms based on
> a
> >> > $_POST variable from a preceding page. It then takes the data input
> into
> >> > the form and neatly packages the result into an email sent to an email
> >> > address (eventually to be a ticketing system).
> >> >
> >> >
> >> > Almost everything on the page works great. The only thing I can't seem
> >> > to
> >> > get working is how to verify that the fields in the form are not left
> >> > empty
> >> > using javascript. The syntax I'm using seems like it should work,
> >> > however
> >> > when I leave one or more of the fields empty, the email gets sent
> anyway
> >> > with the missing data.
> >> >
> >> > Here's the app I was hoping someone might be able to suggest a
> >> > successful
> >> > approach:
> >> >
> >> > <html>
> >> > <head>
> >> > <title>LDAP Form</title>
> >> > <body>
> >> >   <?php
> >> >
> >> >    if (isset($_POST['submit'])) {
> >> >     $requestor_email = $_POST['requestor_email'];
> >> >     $num_forms  = $_POST['num_forms'];
> >> >     }
> >> >
> >> >     echo "<center>You will be creating $num_forms accounts
> >> > today.</center><br />";
> >> >     for($counter = 1;$counter<=$num_forms;$counter++) {
> >> >         echo '<center><form name="ldap_accounts" method="post"
> >> > action="sendemail.php" onsubmit="return validateForm()">';
> >> >         echo '<br /><br />';
> >> >         echo "Enter user: $counter<br />";
> >> >         echo "<label for=\"first_name_.$counter.\">First
> >> > Name:</label><br
> >> > />";
> >> >         echo "<input type=\"text\" id=\"first_name_.$counter.\"
> >> > name=\"first_name_.$counter.\" /><br /><br />";
> >> >         echo "<label for=\"last_name_.$counter.\">Last
> Name:</label><br
> >> > />";
> >> >         echo "<input type=\"text\" id=\"last_name_.$counter.\"
> >> > name=\"last_name_.$counter.\" /><br /><br />";
> >> >         echo "<label
> >> > for=\"department_.$counter.\">Department:</label><br
> >> > />";
> >> >         echo "<input type=\"text\" id=\"department_.$counter.\"
> >> > name=\"department_.$counter.\" /><br /><br />";
> >> >         echo "<label for=\"title_.$counter.\">Title:</label><br />";
> >> >         echo "<input type=\"text\" id=\"title_.$counter.\"
> >> > name=\"title_.$counter.\" /><br /><br />";
> >> >         echo "<label for=\"email_.$counter.\">Email:</label><br />";
> >> >         echo "<input type=\"text\" id=\"email_.$counter.\"
> >> > name=\"email_.$counter.\" /><br /><br />";
> >> >         echo "<label for=\"phone_$counter.\">Phone:</label><br />";
> >> >         echo "<input type=\"text\" id=\"phone_.$counter.\"
> >> > name=\"phone_.$counter.\" /><br /><br />";
> >> >   ?>
> >> >    <script>
> >> >     function validateForm()
> >> >      {
> >> >        var a=document.forms["ldap_accounts"]["first_name_"].value;
> >> >        if (a==null || a=="")
> >> >        {
> >> >         alert("User $counter first name must be filled out.");
> >> >         return false;
> >> >        }
> >> >         var b=document.forms["ldap_accounts"]["last_name_"].value;
> >> >         if (b==null || b=="")
> >> >         {
> >> >         alert("User $counter last name must be filled out.");
> >> >         return false;
> >> >         }
> >> >         var c=document.forms["ldap_accounts"]["department_"].value;
> >> >         if (c==null || c=="")
> >> >         {
> >> >         alert("User $counter department must be filled out.");
> >> >         return false;
> >> >         }
> >> >         var d=document.forms["ldap_accounts"]["title_"].value;
> >> >         if (d==null || d=="")
> >> >         {
> >> >         alert("User $counter title must be filled out.");
> >> >         return false;
> >> >         }
> >> >         var d=document.forms["ldap_accounts"]["email_"].value;
> >> >         if (d==null || d=="")
> >> >         {
> >> >         alert("User $counter address must be filled out.");
> >> >         return false;
> >> >         }
> >> >         var d=document.forms["ldap_accounts"]["phone_"].value;
> >> >         if (d==null || d=="")
> >> >         {
> >> >         alert("User $counter phone name must be filled out.");
> >> >         return false;
> >> >         }
> >> >       }
> >> >      </script>
> >> >  <?php
> >> >   }
> >> >
> >> >   echo "<input type=\"hidden\" id=\"num_forms\" name=\"num_forms\"
> >> > value=\"$num_forms\" /><br /><br />";
> >> >   echo "<input type=\"hidden\" id=\"requestor_email\"
> >> > name=\"requestor_email\" value=\"$requestor_email\" />";
> >> >   echo "<input type=\"submit\" name=\"submit\" value=\"Create Ticket\"
> >> > />";
> >> >   echo "</form></center>";
> >> >
> >> >    ?>
> >> > </body>
> >> > </html>
> >> >
> >> > Thanks,
> >> > Tim
> >> >
> >> > --
> >> > GPG me!!
> >> >
> >> > gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
> >> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B


--- End Message ---
--- Begin Message ---
Sounds good! Thanks Ken. Very clear now.

Tim

Sent from my iPhone

On May 27, 2013, at 1:57 PM, Ken Robinson <kenrb...@rbnsn.com> wrote:

> When you do validation of the form in the same script that shows the form, 
> the normal way to do this is
> 
> <?php
>   if (isset($_POST['submit'])) {
> //
> //  validation here
> //
>    }
> ?>
> 
> This won't work if you're getting to the page via another form, since the 
> $_POST['submit'] is set. There two ways of avoiding this:
> 
> 1) use hidden fields in each form to indicate which form was submitted
> 2) use a different name for each form's submit button and use that in the 
> above code
> 
> Ken
> 
> 
> At 12:52 PM 5/27/2013, Tim Dunphy wrote:
>> Hey guys,
>> 
>> Thanks for the input! This is pretty nice, and DOES work. I like the fact
>> that the fields have been into an iterative array. It's a very elegant
>> solution. However the problem with this approach is that if you load the
>> page directly it works. But if you call the page from the index.php page
>> you get an initial error on all fields as they are all quite naturally
>> empty when you first load the page.
>> 
>> Here's the index.php page. All it is is HTML, no php:
>> 
>> <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
>> <head>
>>  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
>>  <title>LDAP Request Form</title>
>> 
>> <body>
>>  <center><h3>LDAP Request Form</h3>
>>   <form name="form_request" method="post" action="ldap.php"
>> onsubmit="return validateForm()">
>>    <label for="requestor_email">Your Email Address:</label><br />
>>    <input type="text" required id="requestor_email" name="requestor_email"
>> /><br /><br />
>>    <label for="num_forms">How Many Forms Do You Need:</label><br />
>>    <input type="text" required maxlength="2" size="5" id="num_forms"
>> name="num_forms" /><br /><br />
>>    <input type="submit" name="submit" value="Submit" />
>>  </form></center>
>> </body>
>> </html>
>> 
>> And here is ldap.php as was suggested:
>> 
>> <body>
>> 
>>  <?php
>> 
>>   if (isset($_POST['submit'])) {
>>    $requestor_email = $_POST['requestor_email'];
>>    $num_forms  = $_POST['num_forms'];
>>    }
>> 
>> 
>>    echo "<center>You will be creating $num_forms accounts
>> today.</center><br />";
>>    for($counter = 1;$counter<=$num_forms;$counter++) {
>>        echo '<center><form name="ldap_accounts" method="post"
>> action="sendemail.php" onsubmit="return validateForm()">';
>>        echo '<br /><br />';
>>        echo "Enter user: $counter<br /><br />";
>>        echo "<label for=\"first_name_.$counter.\">First Name:</label><br
>> />";
>>        echo "<input type=\"text\" id=\"first_name_.$counter.\"
>> name=\"first_name_.$counter.\" /><br /><br />";
>>        echo "<label for=\"last_name_.$counter.\">Last Name:</label><br />";
>>        echo "<input type=\"text\" id=\"last_name_.$counter.\"
>> name=\"last_name_.$counter.\" /><br /><br />";
>>        echo "<label for=\"department_.$counter.\">Department:</label><br
>> />";
>>        echo "<input type=\"text\" id=\"department_.$counter.\"
>> name=\"department_.$counter.\" /><br /><br />";
>>        echo "<label for=\"title_.$counter.\">Title:</label><br />";
>>        echo "<input type=\"text\" id=\"title_.$counter.\"
>> name=\"title_.$counter.\" /><br /><br />";
>>        echo "<label for=\"email_.$counter.\">Email:</label><br />";
>>        echo "<input type=\"text\" id=\"email_.$counter.\"
>> name=\"email_.$counter.\" /><br /><br />";
>>        echo "<label for=\"phone_$counter.\">Phone:</label><br />";
>>        echo "<input type=\"text\" id=\"phone_.$counter.\"
>> name=\"phone_.$counter.\" /><br /><br />";
>>  }
>> 
>>  echo "<input type=\"hidden\" id=\"num_forms\" name=\"num_forms\"
>> value=\"$num_forms\" /><br /><br />";
>>  echo "<input type=\"hidden\" id=\"requestor_email\"
>> name=\"requestor_email\" value=\"$requestor_email\" />";
>>  echo "<input type=\"submit\" name=\"submit\" value=\"Create Ticket\" />";
>>  echo "</form></center>";
>> 
>> 
>> 
>> 
>>   ?>
>> 
>> 
>> Why this happens when you call the ldap.php page from index.php but not
>> when you load the page directly beats me. But maybe someone can shed some
>> light on that?
>> 
>> Thanks!
>> 
>> 
>> 
>> On Sat, May 25, 2013 at 3:45 AM, tamouse mailing lists <
>> tamouse.li...@gmail.com> wrote:
>> 
>> > On Fri, May 24, 2013 at 9:51 PM, Ken Robinson <kenrb...@rbnsn.com> wrote:
>> > > I took your code and modified it to use HTML5 validation (and few other
>> > > changes). You can see the results at
>> > > <http://my-testbed.com/test1/form_validation.php>
>> > http://my-testbed.com/test1/form_validation.php
>> > >
>> > > My code follows:
>> > >
>> > >   <?php
>> > >   $fields =
>> > > array('first_name','last_name','department','title','email','phone');
>> > >   $num_forms = 1;
>> > >   $tmp = array();
>> > >   $errors = array();
>> > >
>> > >
>> > >    if (isset($_POST['submit'])) {
>> > >     $requestor_email = $_POST['requestor_email'];
>> > >     $num_forms  = $_POST['num_forms'];
>> > >     for ($i = 1;$i <= $num_forms; ++$i) {
>> > >         foreach ($fields as $fld) {
>> > >                 if ($_POST[$fld][$i] == '') {
>> > >                         $errors[] = ucwords(str_replace('_',' ',$fld)) .
>> > "
>> > > for account $i can not be blank";
>> > >                 }
>> > >         }
>> > >     }
>> > >   }
>> > >                 if (!empty($errors)) {
>> > >                         $tmp[] = "The following fields are in
>> > error:<br>";
>> > >                         $tmp[] = implode("<br>\n",$errors);
>> > >                         $tmp[] = "<br>";
>> > >                 }
>> > >     $tmp[] = "<div style='text-align:center'>You will be creating
>> > $num_forms
>> > > accounts today.</div><br>";
>> > >     $tmp[] = '<div style="text-align:center"><form name="ldap_accounts"
>> > > method="post" action="">';
>> > >     $tmp[] = '<br /><br />';
>> > >
>> > >     for($counter = 1;$counter<=$num_forms;$counter++) {
>> > >         $tmp[] = "Enter user: $counter<br />";
>> > >         $tmp[] = "<label for='first_name_$counter'>First
>> > > Name:</label><br/>";
>> > >         $tmp[] = "<input type='text' required id='first_name_$counter'
>> > > name='first_name[$counter]'><br /><br />";
>> > >         $tmp[] = "<label for='last_name_$counter'>Last Name:</label><br
>> > />";
>> > >         $tmp[] = "<input type='text' required id='last_name_$counter'
>> > > name='last_name[$counter]' /><br /><br />";
>> > >         $tmp[] = "<label
>> > > for='department_$counter'>Department:</label><br/>";
>> > >         $tmp[] = "<input type='text' required id='department_$counter.'
>> > > name='department[$counter]' /><br /><br />";
>> > >         $tmp[] = "<label for='title_$counter'>Title:</label><br />";
>> > >         $tmp[] = "<input type='text' required id'title_.$counter'
>> > > name='title[$counter]' /><br /><br />";
>> > >         $tmp[] = "<label for='email_.$counter'>Email:</label><br />";
>> > >         $tmp[] = "<input type='email' required id='email_.$counter'
>> > > name='email[$counter]' /><br /><br />";
>> > >         $tmp[] = "<label for='phone_$counter'>Phone:</label><br />";
>> > >         $tmp[] = "<input type='text' required id='phone_$counter'
>> > > name='phone[$counter]' /><br /><br />";
>> > >   }
>> >
>> >
>> > You can DRY this up (the HTML input fields) similarly to the way you
>> > did the validation above...
>> >
>> > for ($i = 1;$i <= $num_forms; ++$i) {
>> >    foreach ($fields as $fld) {
>> >      $tmp[]="<label for='$fld_$counter'>" . ucwords(str_replace('_','
>> > ',$fld) . ":</label><br />";
>> >      $tmp[]="<input type='text' required id='$fld_$counter'
>> > name='$fld[$counter]' /><br /><br />";
>> >    }
>> > }
>> >
>> > Further, you could also check the validity of field right at the point
>> > of generation and issue the error right next to the field in error,
>> > which is usually a better UX.
>> >
>> > >   $tmp[] = "<input type='hidden' id='num_forms' name='num_forms'
>> > > value='$num_forms' /><br /><br />";
>> > >   $tmp[] = "<input type='hidden' id='requestor_email'
>> > name='requestor_email'
>> > > value='$requestor_email' />";
>> > >   $tmp[] = "<input type='submit' name='submit' value='Create Ticket' />";
>> > >   $tmp[] = "</form></div>";
>> > >
>> > > ?>
>> > > <!DOCTYPE html>
>> > >
>> > > <html>
>> > > <head>
>> > > <title>LDAP Form</title>
>> > > <body>
>> > >         <?php echo implode("\n",$tmp) . "\n"; ?>
>> > > </body>
>> > > </html>
>> > >
>> > > You will notice that I moved the code for the form to above the HTML
>> > > section. I believe that very little PHP should be interspersed with the
>> > HTML
>> > > -- it makes for cleaner code. You can use single quotes around form
>> > > attributes so you don't have to escape the double quotes. The names in
>> > the
>> > > form are now arrays. This makes your life much easier when extracting the
>> > > values later in PHP.
>> > >
>> > > When you check the page in a HTML5 aware brower, you will see how the
>> > > validation is done.
>> > >
>> > > Ken
>> > >
>> > >
>> > > At 10:17 PM 5/24/2013, musicdev wrote:
>> > >>
>> > >> You can validate via JS if required, for example: (JS CODE):
>> > >>
>> > >> if(element.value.length == 0){
>> > >>    // handle 0 length value
>> > >> }
>> > >>
>> > >> I do agree with Ken that you SHOULD NOT perform JS validation.  It is
>> > >> preferable to use php or the new HTML5 features.  JS can be turned-off
>> > by
>> > >> the user which will make JS validation impossible.
>> > >>
>> > >>
>> > >> On Fri, May 24, 2013 at 8:07 PM, Tim Dunphy <bluethu...@gmail.com>
>> > wrote:
>> > >>
>> > >> > Hello list,
>> > >> >
>> > >> >  I have a php script that creates a variable number of forms based on
>> > a
>> > >> > $_POST variable from a preceding page. It then takes the data input
>> > into
>> > >> > the form and neatly packages the result into an email sent to an email
>> > >> > address (eventually to be a ticketing system).
>> > >> >
>> > >> >
>> > >> > Almost everything on the page works great. The only thing I can't seem
>> > >> > to
>> > >> > get working is how to verify that the fields in the form are not left
>> > >> > empty
>> > >> > using javascript. The syntax I'm using seems like it should work,
>> > >> > however
>> > >> > when I leave one or more of the fields empty, the email gets sent
>> > anyway
>> > >> > with the missing data.
>> > >> >
>> > >> > Here's the app I was hoping someone might be able to suggest a
>> > >> > successful
>> > >> > approach:
>> > >> >
>> > >> > <html>
>> > >> > <head>
>> > >> > <title>LDAP Form</title>
>> > >> > <body>
>> > >> >   <?php
>> > >> >
>> > >> >    if (isset($_POST['submit'])) {
>> > >> >     $requestor_email = $_POST['requestor_email'];
>> > >> >     $num_forms  = $_POST['num_forms'];
>> > >> >     }
>> > >> >
>> > >> >     echo "<center>You will be creating $num_forms accounts
>> > >> > today.</center><br />";
>> > >> >     for($counter = 1;$counter<=$num_forms;$counter++) {
>> > >> >         echo '<center><form name="ldap_accounts" method="post"
>> > >> > action="sendemail.php" onsubmit="return validateForm()">';
>> > >> >         echo '<br /><br />';
>> > >> >         echo "Enter user: $counter<br />";
>> > >> >         echo "<label for=\"first_name_.$counter.\">First
>> > >> > Name:</label><br
>> > >> > />";
>> > >> >         echo "<input type=\"text\" id=\"first_name_.$counter.\"
>> > >> > name=\"first_name_.$counter.\" /><br /><br />";
>> > >> >         echo "<label for=\"last_name_.$counter.\">Last
>> > Name:</label><br
>> > >> > />";
>> > >> >         echo "<input type=\"text\" id=\"last_name_.$counter.\"
>> > >> > name=\"last_name_.$counter.\" /><br /><br />";
>> > >> >         echo "<label
>> > >> > for=\"department_.$counter.\">Department:</label><br
>> > >> > />";
>> > >> >         echo "<input type=\"text\" id=\"department_.$counter.\"
>> > >> > name=\"department_.$counter.\" /><br /><br />";
>> > >> >         echo "<label for=\"title_.$counter.\">Title:</label><br />";
>> > >> >         echo "<input type=\"text\" id=\"title_.$counter.\"
>> > >> > name=\"title_.$counter.\" /><br /><br />";
>> > >> >         echo "<label for=\"email_.$counter.\">Email:</label><br />";
>> > >> >         echo "<input type=\"text\" id=\"email_.$counter.\"
>> > >> > name=\"email_.$counter.\" /><br /><br />";
>> > >> >         echo "<label for=\"phone_$counter.\">Phone:</label><br />";
>> > >> >         echo "<input type=\"text\" id=\"phone_.$counter.\"
>> > >> > name=\"phone_.$counter.\" /><br /><br />";
>> > >> >   ?>
>> > >> >    <script>
>> > >> >     function validateForm()
>> > >> >      {
>> > >> >        var a=document.forms["ldap_accounts"]["first_name_"].value;
>> > >> >        if (a==null || a=="")
>> > >> >        {
>> > >> >         alert("User $counter first name must be filled out.");
>> > >> >         return false;
>> > >> >        }
>> > >> >         var b=document.forms["ldap_accounts"]["last_name_"].value;
>> > >> >         if (b==null || b=="")
>> > >> >         {
>> > >> >         alert("User $counter last name must be filled out.");
>> > >> >         return false;
>> > >> >         }
>> > >> >         var c=document.forms["ldap_accounts"]["department_"].value;
>> > >> >         if (c==null || c=="")
>> > >> >         {
>> > >> >         alert("User $counter department must be filled out.");
>> > >> >         return false;
>> > >> >         }
>> > >> >         var d=document.forms["ldap_accounts"]["title_"].value;
>> > >> >         if (d==null || d=="")
>> > >> >         {
>> > >> >         alert("User $counter title must be filled out.");
>> > >> >         return false;
>> > >> >         }
>> > >> >         var d=document.forms["ldap_accounts"]["email_"].value;
>> > >> >         if (d==null || d=="")
>> > >> >         {
>> > >> >         alert("User $counter address must be filled out.");
>> > >> >         return false;
>> > >> >         }
>> > >> >         var d=document.forms["ldap_accounts"]["phone_"].value;
>> > >> >         if (d==null || d=="")
>> > >> >         {
>> > >> >         alert("User $counter phone name must be filled out.");
>> > >> >         return false;
>> > >> >         }
>> > >> >       }
>> > >> >      </script>
>> > >> >  <?php
>> > >> >   }
>> > >> >
>> > >> >   echo "<input type=\"hidden\" id=\"num_forms\" name=\"num_forms\"
>> > >> > value=\"$num_forms\" /><br /><br />";
>> > >> >   echo "<input type=\"hidden\" id=\"requestor_email\"
>> > >> > name=\"requestor_email\" value=\"$requestor_email\" />";
>> > >> >   echo "<input type=\"submit\" name=\"submit\" value=\"Create Ticket\"
>> > >> > />";
>> > >> >   echo "</form></center>";
>> > >> >
>> > >> >    ?>
>> > >> > </body>
>> > >> > </html>
>> > >> >
>> > >> > Thanks,
>> > >> > Tim
>> > >> >
>> > >> > --
>> > >> > GPG me!!
>> > >> >
>> > >> > gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
>> > >> >
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>> 
>> 
>> --
>> GPG me!!
>> 
>> gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---
I'm trying to increase the connection timeout; but can't get it to work. Note: 
Keep-Alive gets repeated.

I'm using:
header("Connection: Keep-Alive");
header("Keep-Alive: timeout=9, max=100");


I get:
(Status-Line)   HTTP/1.1 200 OK
Date    Mon, 27 May 2013 20:19:54 GMT
Server  Apache
Connection      Keep-Alive, Keep-Alive
Keep-Alive      timeout=5, max=100
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma  no-cache
Content-Encoding        gzip
Vary    Accept-Encoding,User-Agent
Set-Cookie Coach::VermontCamp2013_setupMode=58d7e534bec4ec57634c78caa59d8db2; expires=Sat, 23-Nov-2013 20:19:55 GMT; path=/Coach/; domain=.ridersite.org
Transfer-Encoding       chunked
Content-Type    text/html; charset=utf-8

--- End Message ---
--- Begin Message ---
2013/5/27 Al <n...@ridersite.org>

> I'm trying to increase the connection timeout; but can't get it to work.
> Note: Keep-Alive gets repeated.
>
> I'm using:
> header("Connection: Keep-Alive");
> header("Keep-Alive: timeout=9, max=100");
>

Set the second optional argument to "true"
See http://de.php.net/manual/en/function.header.php


>
>
> I get:
> (Status-Line)   HTTP/1.1 200 OK
> Date    Mon, 27 May 2013 20:19:54 GMT
> Server  Apache
> Connection      Keep-Alive, Keep-Alive
> Keep-Alive      timeout=5, max=100
> Expires Thu, 19 Nov 1981 08:52:00 GMT
> Cache-Control   no-store, no-cache, must-revalidate, post-check=0,
> pre-check=0
> Pragma  no-cache
> Content-Encoding        gzip
> Vary    Accept-Encoding,User-Agent
> Set-Cookie      Coach::VermontCamp2013_**setupMode=**
> 58d7e534bec4ec57634c78caa59d8d**b2; expires=Sat, 23-Nov-2013 20:19:55
> GMT; path=/Coach/; domain=.ridersite.org
> Transfer-Encoding       chunked
> Content-Type    text/html; charset=utf-8
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
github.com/KingCrunch

--- End Message ---
--- Begin Message ---
I'm adding some minification to our cache.class.php and am running into an
edge case that is causing me grief.

I want to remove all comments of the // variety, HOWEVER I don't want to
remove URLs...

Given some example text here with carefully crafted cases:

// another comment here
<iframe src="http://foo.com";>
function bookmarksite(title,url){
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    } 
    else if(document.all)// ie
        window.external.AddFavorite(url, title);
}

I've tried so many variations and hunted on StackOverflow, Google, etc. and
what would seem like a task already solved, doesn't seem to be.

This is "close", but still matches //foo.com (omitting the : of course)

\s*(?!:)//.*?$   (count it as '/m' multiline)


This ultimately ends up in a PHP line of code like so:

$sBlob = preg_replace("@\s*//.*?$@m",'',$sBlob);

Here are some other links of stuff I've found and tried to experiment with
varying degrees.

http://stackoverflow.com/questions/4568410/match-comments-with-regex-but-not
-inside-a-quote
http://stackoverflow.com/questions/611883/regex-how-to-match-everything-exce
pt-a-particular-pattern
http://stackoverflow.com/questions/11863847/regex-to-match-urls-but-not-urls
-in-hyperlinks
http://stackoverflow.com/questions/643113/regex-to-strip-comments-and-multi-
line-comments-and-empty-lines



--- End Message ---

Reply via email to