php-general Digest 25 May 2013 02:02:56 -0000 Issue 8245

Topics (messages 321197 through 321200):

Re: Random
        321197 by: Jim Giner

Re: Simple objective which always seems to make me think I'm doing it wrong.
        321198 by: Richard Quadling

iterate javascript verification
        321199 by: Tim Dunphy
        321200 by: Ken Robinson

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 ---
On 5/24/2013 3:04 AM, Last Hacker Always onpoint wrote:
I needed something like this echo(rand(1,30))

On 5/24/13, Last Hacker Always onpoint <lasthack...@gmail.com> wrote:
okay thanks tamouse and others you think am not on point hmmm? I'll
show you i am.

On 5/24/13, tamouse mailing lists <tamouse.li...@gmail.com> wrote:
On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint
<lasthack...@gmail.com> wrote:
Hey I need code for random number 1-30 for my site.

function rand_from_1_to_30() {
     return 4;
}


Apparently, your laziness was overcome by all the abuse you took here.

--- End Message ---
--- Begin Message ---
On 23 May 2013 16:31, Stuart Dallas <stu...@3ft9.com> wrote:

> On 23 May 2013, at 15:54, Richard Quadling <rquadl...@gmail.com> wrote:
>
> > I'm building an XML file.
> >
> > It is within an OOP structure and is pretty simple.
> >
> > The method is ...
> >
> >    /**
> >     * Turn an error from the W2GlobalData service into normal document as
> > this will make it easier to integrate downstream.
> >     *
> >     * @param \SimpleXMLElement $o_XML
> >     * @return \SimpleXMLElement
> >     * @todo Build document to be a correct request header with the
> > embedded error message.
> >     */
> >    public function normaliseError($o_XML)
> >    {
> >        $s_XML = <<< END_XML
> > <?xml version="1.0" encoding="UTF-8"?>
> > <doc>
> >    <service>UK Verification (Edited)</service>
> >    <searchtext>
> >        <forename>{$this->a_RequestData['forename']}</forename>
> >        <middlename>{$this->a_RequestData['middlename']}</middlename>
> >        <surname>{$this->a_RequestData['surname']}</surname>
> >        <address1>{$this->a_RequestData['address1']}</address1>
> >        <address2>{$this->a_RequestData['address2']}</address2>
> >        <postcode>{$this->a_RequestData['postcode']}</postcode>
> >        <gender>{$this->a_RequestData['gender']}</gender>
> >        <dob>{$this->a_RequestData['dob']}</dob>
> >
> > <drivinglicence>{$this->a_RequestData['drivinglicence']}</drivinglicence>
> >        <passport>{$this->a_RequestData['passport']}</passport>
> >        <mpan>{$this->a_RequestData['mpan']}</mpan>
> >    </searchtext>
> >
> >
> <clientreference>{$this->a_RequestData['clientreference']}</clientreference>
> >    <resultcount/>
> >    <searchdate/>
> >    <expiry/>
> >    <timetaken/>
> >    <reportemailsent/>
> >    <error>
> >        {$o_XML->error}
> >    </error>
> > </doc>
> > END_XML;
> >        return new SimpleXMLElement($s_XML);
> >    }
> >
> > Nothing particularly difficult to understand, but I just don't like
> having
> > the XML embedded this way.
> >
> > Ideally, I want a scope aware include function, so I can say _something_
> > like ...
> >
> > $s_XML = require_once __CLASS__ . DIRECTORY_SEPARATOR .
> > 'normalisedError.xml';
> >
> > and have the include be aware of the local scope (so $o_XML and $this are
> > all happy).
> >
> > I know I can write a template parser, but I'm just missing an obvious
> > solution that isn't fat and doesn't require a massive learning for the
> > other devs.
> >
> > Ideas?
>
>
> normalisedError.xml:
>
> <?php
>   return <<< END_XML
> the xml here
> END_XML;
>
> Then in your class your require_once line will work. However, use require
> instead of require_once otherwise if the function gets called twice it
> won't work the second time.
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>

Perfect!!! Thanks


-- 
Richard Quadling
Twitter : @RQuadling
EE : http://e-e.com/M_248814.html
Zend : http://bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message --- You do realize that you shouldn't rely on Javascript to validate values returned in a form? Also, if you use HTML5, you can use the required attribute in the <input> tag and the browser won't let a user submit a form with a required field not filled. Of course, you should still validate within your PHP script, in case a user is using a browser that doesn't understand HTML5.

At 08:07 PM 5/24/2013, Tim Dunphy 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


--- End Message ---

Reply via email to