Submit/Validate triggering problem.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear anyone... :)

First, I hope I'm sending this message to correct address.
If this is not the case I'm apologizing for wasting your time, and I'm asking 
you to give me the right e-mail address.

=== GENERAL ====
LAMP Environment
PEAR - HTML_QuickForm 3.2.4pl1 stable
Platform: SuSE 9.3
=============

=== PROBLEM ====
I have a following "problem" (don't know is this a bug or not):
I have one HTML page, two FORMS, two TEXT fields and two SUBMIT buttons - A 
and B.
When I click either A or B button to submit a form program enters in both
validate() parts - In A and in B so the result on screen from code below is:

In A Validate In B Validate
==============

=== WHAT I WANT ===
I would like to enter in A part when I click on A submit button, and to enter 
in B part when I click on B submit button.
==============

=== QUESTION AND FEW MORE INFO ===
I can make "workaround" by checking the value of $Filter (is it "A" or "B") to 
determine which button sent a request (see "Workaround code" after "Original 
code"), but it looks "dirty" to me, and I'm wondering why to do that if I 
already have two different instances of HTML_QuickForm assigned to two 
different variables $AForm and $BForm.
Why element from $BForm triggers $AForm->validate() and vice versa?
==============

Thank you in advance.


Below is the code:
=============== Original code ==========
<?php
	require_once("HTML/QuickForm.php");

	// Create new instance - Form A
	$AForm = new HTML_QuickForm("Form1", "POST");
	$AForm->addElement("Text", "Name1", "Text1", array("size" => "30"));
	$AForm->addElement("Submit", "AButton", "A");
	if ($AForm->validate())
	{
		echo " In A Validate ";
	}

	// Create new instance - Form B
	$BForm = new HTML_QuickForm("Form2", "POST");
	$BForm->addElement("Text", "Name2", "Text2", array("size" => "30"));
	$BForm->addElement("Submit", "BButton", "B");
	if ($BForm->validate())
	{
		echo " In B Validate ";
	}

	// Display Forms
	$AForm->display();
	$BForm->display();
?>


=============== Workaround code ==========
<?php
	require_once("HTML/QuickForm.php");

	$Filter  = $_POST["SButton"];

	// Create new instance - Form A
	$AForm = new HTML_QuickForm("Form1", "POST");
	$AForm->addElement("Text", "Name1", "Text1", array("size" => "30"));
	$AForm->addElement("Submit", "SButton", "A");
	if ($AForm->validate() && Filter == "A")
	{
		echo " In A Validate ";
	}

	// Create new instance - Form B
	$BForm = new HTML_QuickForm("Form2", "POST");
	$BForm->addElement("Text", "Name2", "Text2", array("size" => "30"));
	$BForm->addElement("Submit", "SButton", "B");
	if ($BForm->validate() && Filter == "B")
	{
		echo " In B Validate ";
	}

	// Display Forms
	$AForm->display();
	$BForm->display();
?>

-- 
Uros Dukanac
---------------
LucidTech | Svetogorska 2 | 11000 Beograd
tel: +381 11 3033386 | fax: +381 11 3033391
http: www.lucidtech.org

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux