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.php 



My code follows:

$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:";
$tmp[] = implode("\n",$errors);
$tmp[] = "";
}
$tmp[] = "You will be creating 
$num_forms accounts today.";
$tmp[] = 'name="ldap_accounts" method="post" action="">';

$tmp[] = '';
for($counter = 1;$counter<=$num_forms;$counter++) {
$tmp[] = "Enter user: $counter";
$tmp[] = "First Name:";
$tmp[] = "id='first_name_$counter' name='first_name[$counter]'>";

$tmp[] = "Last Name:";
$tmp[] = "id='last_name_$counter' name='last_name[$counter]' />";

$tmp[] = "Department:";
$tmp[] = "id='department_$counter.' name='department[$counter]' />";

$tmp[] = "Title:";
$tmp[] = "name='title[$counter]' />";

$tmp[] = "Email:";
$tmp[] = "name='email[$counter]' />";

$tmp[] = "Phone:";
$tmp[] = "name='phone[$counter]' />";

  }
  $tmp[] = "value='$num_forms' />";
  $tmp[] = "name='requestor_email' value='$requestor_email' />";

  $tmp[] = "";
  $tmp[] = "";

?>



LDAP Form





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  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:
>
> 
> 
> LDAP Form
> 
>   
>if (isset($_POST['submit'])) {
> $requestor_email = $_POST['requestor_email'];
> $num_forms  = $_POST['num_forms'];
> }
>
> echo "You will be creating $num_forms accounts
> today.";
> for($counter = 1;$counter<=$num_forms;$counter++) {
> echo ' action="sendemail.php" onsubmit="return validateForm()">';
> echo '';
> echo "Enter user: $counter";
> echo "First Name: />";
> echo " name=\"first_name_.$counter.\" />";
> echo "Last Name: />";
> echo " name=\"last_name_.$counter.\" />";
> echo "Department: />";
> echo " name=\"department_.$counter.\" />";
> echo "Title:";
> echo " name=\"title_.$counter.\" />";
> echo "Email:";
> echo " name=\"email_.$counter.\" />";
> echo "Phone:";
> echo " name=\"phone_.$counter.\" />";
>   ?>
>
> 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_"].valu

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  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:
>
> 
> 
> LDAP Form
> 
>   
>if (isset($_POST['submit'])) {
> $requestor_email = $_POST['requestor_email'];
> $num_forms  = $_POST['num_forms'];
> }
>
> echo "You will be creating $num_forms accounts
> today.";
> for($counter = 1;$counter<=$num_forms;$counter++) {
> echo ' action="sendemail.php" onsubmit="return validateForm()">';
> echo '';
> echo "Enter user: $counter";
> echo "First Name: />";
> echo " name=\"first_name_.$counter.\" />";
> echo "Last Name: />";
> echo " name=\"last_name_.$counter.\" />";
> echo "Department: />";
> echo " name=\"department_.$counter.\" />";
> echo "Title:";
> echo " name=\"title_.$counter.\" />";
> echo "Email:";
> echo " name=\"email_.$counter.\" />";
> echo "Phone:";
> echo " name=\"phone_.$counter.\" />";
>   ?>
>
> 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;
> }
>   }
>  
> }
>
>   echo " value=\"$num_forms\" />";
>   echo " name=\"requestor_email\" value=\"$requestor_email\" />";
>   echo "";
>   echo "";
>
>?>
> 
> 
>
> 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  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:



LDAP Form

  You will be creating $num_forms accounts
today.";
for($counter = 1;$counter<=$num_forms;$counter++) {
echo '';
echo '';
echo "Enter user: $counter";
echo "First Name:";
echo "";
echo "Last Name:";
echo "";
echo "Department:";
echo "";
echo "Title:";
echo "";
echo "Email:";
echo "";
echo "Phone:";
echo "";
  ?>
   
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;
}
  }
 
 ";
  echo "";
  echo "";
  echo "";

   ?>



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



[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:



LDAP Form

  You will be creating $num_forms accounts
today.";
for($counter = 1;$counter<=$num_forms;$counter++) {
echo '';
echo '';
echo "Enter user: $counter";
echo "First Name:";
echo "";
echo "Last Name:";
echo "";
echo "Department:";
echo "";
echo "Title:";
echo "";
echo "Email:";
echo "";
echo "Phone:";
echo "";
  ?>
   
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;
}
  }
 
 ";
  echo "";
  echo "";
  echo "";

   ?>



Thanks,
Tim

-- 
GPG me!!

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


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  wrote:

> On 23 May 2013, at 15:54, Richard Quadling  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
> > 
> > 
> >UK Verification (Edited)
> >
> >{$this->a_RequestData['forename']}
> >{$this->a_RequestData['middlename']}
> >{$this->a_RequestData['surname']}
> >{$this->a_RequestData['address1']}
> >{$this->a_RequestData['address2']}
> >{$this->a_RequestData['postcode']}
> >{$this->a_RequestData['gender']}
> >{$this->a_RequestData['dob']}
> >
> > {$this->a_RequestData['drivinglicence']}
> >{$this->a_RequestData['passport']}
> >{$this->a_RequestData['mpan']}
> >
> >
> >
> {$this->a_RequestData['clientreference']}
> >
> >
> >
> >
> >
> >
> >{$o_XML->error}
> >
> > 
> > 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:
>
>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


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  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  wrote:

On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint
 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] Random

2013-05-24 Thread Nick Pratley
Lola

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

>
>
> Last Hacker Always onpoint > wrote:
>
> >I needed something like this echo(rand(1,30))
> >
> >On 5/24/13, Last Hacker Always onpoint >
> 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 >
> wrote:
> >>> On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint
> >>> > 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


[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 Ashley Sheridan


Last Hacker Always onpoint  wrote:

>I needed something like this echo(rand(1,30))
>
>On 5/24/13, Last Hacker Always onpoint  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  wrote:
>>> On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint
>>>  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] 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 Last Hacker Always onpoint
I needed something like this echo(rand(1,30))

On 5/24/13, Last Hacker Always onpoint  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  wrote:
>> On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint
>>  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