PHP Classes

Get start to use

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  Get start to use  >  (Un) Subscribe thread alerts  
Subject:Get start to use
Summary:Please help with sample codes
Messages:13
Author:Wah Y Lam
Date:2007-09-30 03:52:23
Update:2007-10-02 14:32:55
 
  1 - 10   11 - 13  

  1. Get start to use   Reply   Report abuse  
Picture of Wah Y Lam Wah Y Lam - 2007-09-30 03:52:23
I want to learn how to get start on using this validation package.
Can someone just give me a simple but completed code for four checkboxes and validate that at least one checkbox is checked?

Thanks

Ben

  2. Re: Get start to use   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-09-30 04:42:26 - In reply to message 1 from Wah Y Lam
The main test_form.php script shows how to do something like that with two checkboxes with a label above titled "When approved, receive notification by:".

  3. Re: Get start to use   Reply   Report abuse  
Picture of Wah Y Lam Wah Y Lam - 2007-09-30 12:05:05 - In reply to message 2 from Manuel Lemos
Thanks for the reply.
I did try the example, however, I got some errors, such as credit cards, personal names and others from those in the example. I may need to change the following templates as well (do I need to?:
form_body.html.php
form_frame.html.php

I was not sure what to include, and what not to include in my application. Please help.

the following is what I wrote in whole:

<?php

require("forms.php");
$form=new form_class;
$form->NAME="subscription_form";
$form->METHOD="POST";
$form->ACTION="";
$form->debug="trigger_error";
$form->ResubmitConfirmMessage=
"Are you sure you want to submit this form again?";
$form->OptionsSeparator="<br />\n";
$form->ShowAllErrors=1;
$form->InvalidCLASS='invalid';

$form->ErrorMessagePrefix="- ";
$form->ErrorMessageSuffix="";

$form->AddInput(array(
"TYPE"=>"checkbox",
"NAME"=>"operationType",
"ID"=>"OperationL",
"VALUE"=>"Operation",
"CHECKED"=>0,
"MULTIPLE"=>1,
"LABEL"=>"L<u>a</u>boratory",
"ACCESSKEY"=>"a",
"ReadOnlyMark"=>"[X]"
));

$form->AddInput(array(
"TYPE"=>"checkbox",
"NAME"=>"operationType",
"ID"=>"OperationE",
"VALUE"=>"Operation",
"CHECKED"=>0,
"MULTIPLE"=>1,
"LABEL"=>"E<u>x</u>hibition",
"ACCESSKEY"=>"x",
"ReadOnlyMark"=>"[X]"
));


$form->AddInput(array(
"TYPE"=>"hidden",
"NAME"=>"doit",
"VALUE"=>1
));

$form->AddInput(array(
"TYPE"=>"hidden",
"NAME"=>"user_track",
"VALUE"=>"0",
"ValidateAsInteger"=>1,
"DiscardInvalidValues"=>1
));


$form->LoadInputValues($form->WasSubmitted("doit"));
$verify=array();

if($form->WasSubmitted("doit"))
{
if(($error_message=$form->Validate($verify))=="")
{
$doit=1;
}
else
{
$doit=0;
$error_message=nl2br(HtmlSpecialChars($error_message));
}
}
else
{
$error_message="";
$doit=0;
}
if($doit)
{
$form->ReadOnly=1;
}
if(!$doit)
{
if(strlen($error_message))
{
Reset($verify);
$focus=Key($verify);
}
else
{
$focus='email';
}
$form->ConnectFormToInput($focus, 'ONLOAD', 'Focus', array());
}
$onload = HtmlSpecialChars($form->PageLoad());
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Operation Type</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css"><!--
.invalid { border-color: #ff0000; background-color: #ffcccc; }
// --></style>
</head>
<body onload="<?php echo $onload; ?>" bgcolor="#cccccc">
<center><h1>Operation Type Selected</h1></center>
<hr />

<?php

$form->StartLayoutCapture();
$title="Operation test";
$body_template="form_body.html.php";
require("templates/form_frame.html.php");
$form->EndLayoutCapture();
$form->DisplayOutput();
?>
</body>
</html>

  4. Re: Get start to use   Reply   Report abuse  
Picture of Wah Y Lam Wah Y Lam - 2007-09-30 14:18:15 - In reply to message 2 from Manuel Lemos
Please dis-regard my other message, as I found your example in forms.html.
It is wonderful to use once knowing the basic and understand!

One more question, I could not post to a second page "posted.php" by the following codes. I need your help!

Thanks!
Ben


File name: Checkbox.php
------------------------------------------------
<?php
$form->METHOD="POST";
$form->ACTION="posted.php";

require("forms.php");
$form=new form_class;

$form->AddInput(array(
"TYPE"=>"checkbox",
"NAME"=>"Operational_Type",
"ID"=>"OperationL",
"CHECKED"=>0,
"MULTIPLE"=>1,
"ValidateAsSet"=>1,
"ValidationErrorMessage"=>"You have to Choose One Type",
));
$form->AddInput(array(
"TYPE"=>"checkbox",
"NAME"=>"Operational_Type",
"ID"=>"OperationE",
"CHECKED"=>0,
"MULTIPLE"=>1,
"ValidationErrorMessage"=>"You have to Choose One Type",
));

$form->AddInput(array(
"ID"=>"submit",
"TYPE"=>"submit"
));

$form->StartLayoutCapture();
include("checkboxtemp.php");
$form->EndLayoutCapture();
$form->DisplayOutput();
?>
---------------------------------------------

The template file: checkboxtemp.php

<table>

<tr>
<th><?php
$form->AddLabelPart(array(
"FOR"=>"OperationE",
"LABEL"=>"<u>E</u>xibition",
"ACCESSKEY"=>"E"
));
?>:</th>
<td><?php $form->AddInputPart("OperationE"); ?></td>
</tr>

<tr>
<th><?php
$form->AddLabelPart(array(
"FOR"=>"OperationL",
"LABEL"=>"<u>L</u>aborary",
"ACCESSKEY"=>"L"
));
?>:</th>
<td><?php $form->AddInputPart("OperationL"); ?></td>
</tr>

<tr>
<td colspan="2"><?php $form->AddInputPart("submit"); ?></td>
</tr>

</table>

  5. Re: Get start to use   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-09-30 17:25:49 - In reply to message 4 from Wah Y Lam
It is recommended to post forms to the same pages that defines them, so you do not have to repeat the form definition to validate it on the server side.

If you want to make the user go to a different page after the form is successfully processed, use the page redirection headers like this:

Header('Location: http://www.mysite.com/posted.php');

  6. Re: Get start to use   Reply   Report abuse  
Picture of Wah Y Lam Wah Y Lam - 2007-09-30 22:50:38 - In reply to message 5 from Manuel Lemos
Thanks!

Within my code, where do I put the header redirection when every thing is verified?
It seemed when I put it in, it redirected immediately when the form was loaded. I must have put it in a wrong location.

Ben

  7. Re: Get start to use   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-10-01 00:49:08 - In reply to message 6 from Wah Y Lam
Yes, the Location: header redirects immediately. Response headers must be inserted before any HTML is outputted.

If you want to redirect only after a few seconds, you can insert a meta tag in your page head section like this:

<meta http-equiv="refresh" content="2; url=http://www.mysite.com/posted.php">

  8. Re: Get start to use   Reply   Report abuse  
Picture of Wah Y Lam Wah Y Lam - 2007-10-01 04:03:47 - In reply to message 7 from Manuel Lemos
I am very grateful for your response.
Sorry I may not have made my question clear enough!

I had tried putting that redirection on either the begining of the form itself, or the begining of the template. On either situation, when I loaded the form, it redirected me to the next page right away, and I did not have any chance to input any thing into the form.

Ben

  9. Re: Get start to use   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-10-01 04:42:07 - In reply to message 8 from Wah Y Lam
You should only apply redirection when you have successfully validated and processed the form.

In the test_form.php example you can see a section that has something like this:

if($doit)
{

/*
* The form is ready to be processed, just output it again as read only to
* display the submitted values. A real form processing script usually may
* do something else like storing the form values in a database.
*/
$form->ReadOnly=1;
}

So, all you need to do is replace the code inside the if section and do something useful that you application needs to do process the form and the use the redirection header.

  10. Re: Get start to use   Reply   Report abuse  
Picture of Wah Y Lam Wah Y Lam - 2007-10-01 17:17:50 - In reply to message 9 from Manuel Lemos
I had tried and failed. I took out the $form->ReadOnly=1; statement and entered the redirection into the if section, trying to carry the value of the selection to a next page, or into a database further down the road.

If possible, could you please tell me how I can, from the codes I mentioned above at message #4, that after making a selection on one of the two checkboxes, I can carry the value of the selection going to a new page!


 
  1 - 10   11 - 13