Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I identificate Zend Forms?, I can't find it in official documentation!!!
For example in controller we have 2 forms, how we can find out with is submited?
Posted
Comments
Sergey Alexandrovich Kryukov 7-Aug-13 20:29pm    
Not clear. Why on Earth would you need to know which form is submitted? What, do you want to have different forms with the same value (URL) of the "action" attribute? But why?
—SA
Mohibur Rashid 7-Aug-13 20:47pm    
bad design
Sergey Alexandrovich Kryukov 7-Aug-13 20:52pm    
I would rather agree. I discussed it in my answer, take a look.
—SA

Well, the submit button hold a value, when you press a submit button all the input filed value will be send except other submit button.

example
<form >
	<INPUT name='me'>
	<INPUT type='submit' value='data1' name='ae'>
	<INPUT type='submit' value='data2' name='fe'>
</form>


if you press data1 the received query would be
?me=&ae=data1
if you press data2 then the received query would be
?me=&fe=data2

with isset function you can verify which submit has been requested.

And if they are two complete different form just add two different hidden field.
 
Share this answer
 
v2
Please see my comment to the question. It does not seem to make a whole lot of sense. However, if you understand how things work, you will be able to decide what you want to do.

You could not find it in "official documentation", because no one is going to write a documentation section on such a weird topic. Such topic does not actually exist, just because there is no such problem per se, there is general understanding of how things work (well documented, of course), plus some simple logic. Let's follow such logic.

Here is why: Normally, if you have different forms, they usually have different values of the attribute action which represent some URL; through this URL you send an HTTP request to some form processing agent:
Please see:
http://www.w3.org/TR/html4/interact/forms.html[^],
http://www.w3.org/TR/html4/interact/forms.html#adef-action[^].

Moreover, very typically, this URL is the same as the URL of the form. The agent code detects if something was posted and generate somewhat different page in its HTTP response, to show input data, validation results, or just to say "thank you for your information" to the user.

Imagine however, that you still need to have two form with identical values of the action attribute, by one or another reason. But how it possibly create a problem of "identification" of it? Remember that the forms are, apparently, different. You cannot know in advance what would be the data filled in the form, to take it into account in your PHP agent code. However, you know exactly what will be metadata, which is represented by form controls and their name attributes. If you use forms, you should know that it's the name attribute which is written in the body of HTTP request as a result of form submission:
http://www.w3.org/TR/html4/interact/forms.html#control-name[^].

And if the forms are really different, at least some of the names of their controls should be different. Do I even have to explain why? Well, because if they are identical, the forms, from the standpoint of the processing agent, are identical, not different, even if they are actually different elements. You PHP (or any other) processing agent code only receives HTTP request text, nothing else.

And if some names are different, you can see which form it that. As you should know, PHP gets access to HTTP request parameters via the PHP array (associative container, essentially) $_POST. The array is indexed by the strings keys which are the same very names. If some name is not present in the form, the key of the same value does not present in the array, which you can check up using the function isset. This is demonstrated, for example, here:
http://www.html-form-guide.com/php-form/php-form-post.html[^].

—SA
 
Share this answer
 
Comments
Lubomur 8-Aug-13 6:55am    
thanks for good answer, bad logic come with next task: in controller 'settings' I have action 'image' with give some logic (upload and crop image), at page load I have image with I can crop, than save, or uplaod new image and than crop, but we can upload another image and ... crop thay, that's why I need to use two forms.
Sergey Alexandrovich Kryukov 8-Aug-13 11:38am    
You are welcome.

As to the the image problem, it sounds like a separate question. Ask it and create a separate thread page if you wish.

—SA
PHP
public function imageAction()
    {
        $accountInfo = Zend_Auth::getInstance()->getStorage()->read();

        $uploadForm = new Application_Form_Settings_Image_Upload();
        $cropForm = new Application_Form_Settings_Image_Crop();

        $imgModel = new Application_Model_Img();

        if ($this->getRequest()->isPost()) {
            $requestParams = $this->getRequest()->getParams();
            if (isset($requestParams['x'])) {
                if ($cropForm->isValid($this->getRequest()->getPost())) {
                    echo 'CROP FORM IS VALID!';

                    $targ_w = $targ_h = 250;
////                    $jpeg_quality = 90;
////
////                    $src = 'demo_files/pool.jpg';
////                    $img_r = imagecreatefromjpeg($src);
////                    $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
////
////                    imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
////                        $targ_w,$targ_h,$_POST['w'],$_POST['h']);
////
////                    imagejpeg($dst_r, time().'.jpg',$jpeg_quality);
//
//                //$publicImg->create($id);
                }
            }

            if (isset($requestParams['MAX_FILE_SIZE'])) {
                if ($uploadForm->isValid($this->getRequest()->getPost())) {
                    $upload = new Zend_File_Transfer();
                    $fileName = date('YmdHis') . '.jpg';
                    $upload->addFilter(
                        'Rename',
                        PUBLIC_PATH . DIRECTORY_SEPARATOR . 'accounts' .
                        DIRECTORY_SEPARATOR . $accountInfo->email . DIRECTORY_SEPARATOR .
                        $fileName);

                    $publicImg = new Application_Model_PublicImg();

                    try {
                        $upload->receive();
                        $id = $imgModel->create($fileName);

                        //$publicImg->create($id);




                        //Zend_Debug::dump($upload->getFileInfo());


                        chmod(PUBLIC_PATH . '/accounts/' . $accountInfo->email . '/' . $fileName, 0777);
                    } catch (Zend_File_Transfer_Exception $e) {
                        echo $e->message();
                    }
                }
            }
        }

        $this->view->uploadForm = $uploadForm;
        $this->view->cropForm = $cropForm;

        $result = $imgModel->getLast();

        $this->view->currentImage = DIRECTORY_SEPARATOR . 'accounts' . DIRECTORY_SEPARATOR .
            $accountInfo->email . DIRECTORY_SEPARATOR . $result['src'];
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900