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

2013-05-24 Thread php-general-digest-help

php-general Digest 25 May 2013 02:02:56 - 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


--
---BeginMessage---

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---
---BeginMessage---
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
 serviceUK 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---
---BeginMessage---
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
titleLDAP Form/title
body
  ?php

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

echo centerYou will be creating $num_forms accounts
today./centerbr /;
for($counter = 

Re: [PHP] Random

2013-05-24 Thread Last Hacker Always onpoint
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;
 }



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] json_decode mistery

2013-05-24 Thread Radek Krejča
Hello, I am usin json regulary, but in one script I have mistery:

echo($decrypted_data).\n\n;
var_dump(json_decode($decrypted_data, true));
echo \n;
var_dump(json_decode('{result_ok:true,result_message:null,client_name:Radek
 Krej\u010da}', true));

I got:

{result_ok:true,result_message:null,client_name:Radek Krej\u010da}

NULL

array(3) {
  [result_ok]=
  bool(true)
  [result_message]=
  NULL
  [client_name]=  a
} string(13) Radek KrejÄ


You can see, that in $decrypted_data, is stored valid (by my opinion) json 
data. If I use this variable in json_decode, I got null. And if I manualy use 
data displayed on screen, I got valid array.

Where I do mistake? If I remove client_name (so no utf8 is in json data), 
situation is the same.

Radek


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Random

2013-05-24 Thread Ashley Sheridan


Last Hacker Always onpoint lasthack...@gmail.com 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;
 }



Did you actually try that?

Thanks,
Ash

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] RE: json_decode mistery - solved

2013-05-24 Thread Radek Krejča
var_dump(json_decode(Trim($decrypted_data), true));
I dont know why, but there is any spaces, this is working.
Radek

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Random

2013-05-24 Thread Nick Pratley
Lola

On Friday, May 24, 2013, Ashley Sheridan wrote:



 Last Hacker Always onpoint lasthack...@gmail.com javascript:; wrote:

 I needed something like this echo(rand(1,30))
 
 On 5/24/13, Last Hacker Always onpoint lasthack...@gmail.comjavascript:;
 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.comjavascript:;
 wrote:
  On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint
  lasthack...@gmail.com javascript:; wrote:
  Hey I need code for random number 1-30 for my site.
 
  function rand_from_1_to_30() {
  return 4;
  }
 
 

 Did you actually try that?

 Thanks,
 Ash

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
- Nick


Re: [PHP] Random

2013-05-24 Thread Jim Giner

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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple objective which always seems to make me think I'm doing it wrong.

2013-05-24 Thread Richard Quadling
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
 serviceUK 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


[PHP] iterate javascript verification

2013-05-24 Thread Tim Dunphy
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
titleLDAP Form/title
body
  ?php

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

echo centerYou will be creating $num_forms accounts
today./centerbr /;
for($counter = 1;$counter=$num_forms;$counter++) {
echo 'centerform name=ldap_accounts method=post
action=sendemail.php onsubmit=return validateForm()';
echo 'br /br /';
echo Enter user: $counterbr /;
echo label for=\first_name_.$counter.\First Name:/labelbr
/;
echo input type=\text\ id=\first_name_.$counter.\
name=\first_name_.$counter.\ /br /br /;
echo label for=\last_name_.$counter.\Last Name:/labelbr /;
echo input type=\text\ id=\last_name_.$counter.\
name=\last_name_.$counter.\ /br /br /;
echo label for=\department_.$counter.\Department:/labelbr
/;
echo input type=\text\ id=\department_.$counter.\
name=\department_.$counter.\ /br /br /;
echo label for=\title_.$counter.\Title:/labelbr /;
echo input type=\text\ id=\title_.$counter.\
name=\title_.$counter.\ /br /br /;
echo label for=\email_.$counter.\Email:/labelbr /;
echo input type=\text\ id=\email_.$counter.\
name=\email_.$counter.\ /br /br /;
echo label for=\phone_$counter.\Phone:/labelbr /;
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


Re: [PHP] iterate javascript verification

2013-05-24 Thread Ken Robinson
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
titleLDAP Form/title
body
  ?php

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

echo centerYou will be creating $num_forms accounts
today./centerbr /;
for($counter = 1;$counter=$num_forms;$counter++) {
echo 'centerform name=ldap_accounts method=post
action=sendemail.php onsubmit=return validateForm()';
echo 'br /br /';
echo Enter user: $counterbr /;
echo label for=\first_name_.$counter.\First Name:/labelbr
/;
echo input type=\text\ id=\first_name_.$counter.\
name=\first_name_.$counter.\ /br /br /;
echo label for=\last_name_.$counter.\Last Name:/labelbr /;
echo input type=\text\ id=\last_name_.$counter.\
name=\last_name_.$counter.\ /br /br /;
echo label for=\department_.$counter.\Department:/labelbr
/;
echo input type=\text\ id=\department_.$counter.\
name=\department_.$counter.\ /br /br /;
echo label for=\title_.$counter.\Title:/labelbr /;
echo input type=\text\ id=\title_.$counter.\
name=\title_.$counter.\ /br /br /;
echo label for=\email_.$counter.\Email:/labelbr /;
echo input type=\text\ id=\email_.$counter.\
name=\email_.$counter.\ /br /br /;
echo label for=\phone_$counter.\Phone:/labelbr /;
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



Re: [PHP] iterate javascript verification

2013-05-24 Thread musicdev
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
 titleLDAP Form/title
 body
   ?php

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

 echo centerYou will be creating $num_forms accounts
 today./centerbr /;
 for($counter = 1;$counter=$num_forms;$counter++) {
 echo 'centerform name=ldap_accounts method=post
 action=sendemail.php onsubmit=return validateForm()';
 echo 'br /br /';
 echo Enter user: $counterbr /;
 echo label for=\first_name_.$counter.\First Name:/labelbr
 /;
 echo input type=\text\ id=\first_name_.$counter.\
 name=\first_name_.$counter.\ /br /br /;
 echo label for=\last_name_.$counter.\Last Name:/labelbr
 /;
 echo input type=\text\ id=\last_name_.$counter.\
 name=\last_name_.$counter.\ /br /br /;
 echo label for=\department_.$counter.\Department:/labelbr
 /;
 echo input type=\text\ id=\department_.$counter.\
 name=\department_.$counter.\ /br /br /;
 echo label for=\title_.$counter.\Title:/labelbr /;
 echo input type=\text\ id=\title_.$counter.\
 name=\title_.$counter.\ /br /br /;
 echo label for=\email_.$counter.\Email:/labelbr /;
 echo input type=\text\ id=\email_.$counter.\
 name=\email_.$counter.\ /br /br /;
 echo label for=\phone_$counter.\Phone:/labelbr /;
 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



Re: [PHP] iterate javascript verification

2013-05-24 Thread Ken Robinson
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.phphttp://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./divbr;
$tmp[] = 'div style=text-align:centerform 
name=ldap_accounts method=post action=';

$tmp[] = 'br /br /';
for($counter = 1;$counter=$num_forms;$counter++) {
$tmp[] = Enter user: $counterbr /;
$tmp[] = label for='first_name_$counter'First Name:/labelbr/;
$tmp[] = input type='text' required 
id='first_name_$counter' name='first_name[$counter]'br /br /;

$tmp[] = label for='last_name_$counter'Last Name:/labelbr /;
$tmp[] = input type='text' required 
id='last_name_$counter' name='last_name[$counter]' /br /br /;

$tmp[] = label for='department_$counter'Department:/labelbr/;
$tmp[] = input type='text' required 
id='department_$counter.' name='department[$counter]' /br /br /;

$tmp[] = label for='title_$counter'Title:/labelbr /;
$tmp[] = input type='text' required id'title_.$counter' 
name='title[$counter]' /br /br /;

$tmp[] = label for='email_.$counter'Email:/labelbr /;
$tmp[] = input type='email' required id='email_.$counter' 
name='email[$counter]' /br /br /;

$tmp[] = label for='phone_$counter'Phone:/labelbr /;
$tmp[] = input type='text' required id='phone_$counter' 
name='phone[$counter]' /br /br /;

  }
  $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
titleLDAP 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
 titleLDAP Form/title
 body
   ?php

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

 echo centerYou will be creating $num_forms accounts
 today./centerbr /;
 for($counter = 1;$counter=$num_forms;$counter++) {
 echo 'centerform name=ldap_accounts method=post
 action=sendemail.php onsubmit=return validateForm()';
 echo 'br /br /';
 echo Enter user: $counterbr /;
 echo label for=\first_name_.$counter.\First Name:/labelbr
 /;
 echo input type=\text\ id=\first_name_.$counter.\