Zend controller/view newbie puzzle: $_GET & $_POST empty - on receipt from HTML form within view - zend-framework

Zend newbie here ... And just to make it better, my mission is to build on top of someone else's pre-existing Zend site.
(BTW: zf show version --> Zend Framework Version: 1.11.1 -- I seem to have Zend_Form).
Here's the curious bit. All the forms are built in HTML within views. They seem to work, although I can't figure out how -- especially given what I am seeing.
I followed the convention and created a view for a test form and wrote the form:
<form action="<?php echo $this->url(array('controller'=>'ControllerName','action'=>'submit'));?>" method="post" style="margin-left:20px">
<p class="bold setmgr">Your email here:</p>
<div class="field">
<input class="text" type="text name="custEmail"/>
</div>
<div class="field">
<input class="button" value="Submit and be free!" type="submit"/>
</div>
</form>
The submitAction member in the controller is firing correctly. No problem.
But ALL the places I could look for the POST data appear to be empty!
echo "obj custEmail = [" . $this->_request->getPost('custEmail') . "]\n";
echo "GET custEmail = [" . $_GET['custEmail'] . "]\n";
echo "POST custEmail = [" . $_POST['custEmail'] . "]\n";
if ($this->_request->isPost()) {
$data = $this->_request->getPost();
Zend_Debug::dump($data);
}
They all produce nothing.
I'd be much obliged for a solution or even a clue about what is going wrong.
Thanks for reading.

Your form is not in the correct format.As it's PHP you can use form like this or you can even generate a ZEND_FORM(which is profound way to do it).It's always a good practise to work around with ZEND_FORM.If you still want to use this and the go by your way,here is th snippet I modified for you.
I am modifying the Code for you.Your View should have this form in it;
<form action="" method="post" style="margin-left:20px">
<p class="bold setmgr">Your email here:</p>
<div class="field">
<input class="text" type="text" name="custEmail"/>
</div>
<div class="field">
<input class="button" value="Submit and be free!" type="submit" name="submit"/>
</div>
</form>
<?php
echo $this->custEmail;
?>
Now write the following one on your ACTIOn,i.e. submitAction;
public function submitAction()
{
if ($this->getRequest()->isPost())
{
$custEmail = $this->getRequest()->getPost('custEmail');
echo $custEmail;
$this->view->custEmail = $custEmail;
}
}
Now check if it works for you or not.

Create a form using Zend_Form. When ZF already has a way to create forms, you should use that. Your method is like a hack and is not a recommended way to do things.
Check here on how to create a Zend_Form
http://framework.zend.com/manual/en/zend.form.html

Related

GTM - Track all downloads except certain classes

I currently have a trigger in GTM that tracks when certain documents are downloaded, such as pdfs, xlsx, png, docx, jpg... etc..
This is setup to track on the entire site, however I have a specific section that I don't want tracked by this catch all.
I've been trying to add an exception that says if a download link contains the class "Library_Download" then don't track it under the catch all trigger.
I'm trying to bring more clarity to what types of files are being downloaded.
I have tried adding exceptions to the tag, or adding validation to the trigger that and I seem to be missing something.
Catch All Trigger
Trigger Type: Click - Just Links
Trigger Fires On: Element URL Path - matches RegEx
\.(pdf|xlsx|png|docx|jpg|jpeg|zip|pat|dwg)$
How do I not count any link that contains the class "Library_Download" Or is there another way I should have them omitted?
I've created the following trigger and added it as an exception to the tag but it didn't work.
Trigger Type: Custom Event
Event name: \* (Enabled regex matching)
Trigger Fires on: Click Class - contains - "Library_booking"
Nov 21 Edit
So to clarify a bit more with HTML. Below is what I'm currently using for my library_download link. I'm currently only concerned with the pdfdownload.pdf
<div class="resource_row">
<div class="resource_item large <?php echo $post->post_name; ?>" data-filter-item data-filter-name="<?php echo $post->post_name; ?>">
<a href="www.librarywebsite.com/librarypage/" ><?php the_post_thumbnail('medium'); ?></a>
<p><?php the_title(); ?></p>
<ul class="resource_icons">
<li><img src="<?php bloginfo('stylesheet_directory'); ?>/img/icon-download.png" alt="Download PDF" /></li>
<li><img src="<?php bloginfo('stylesheet_directory'); ?>/img/icon-library.png" alt="library" /></li>
</ul>
</div>
</div>
This is how a regular link would look like (the only thing that's changed is I have removed the class Library_Download
<div class="resource_row">
<div class="resource_item large <?php echo $post->post_name; ?>" data-filter-item data-filter-name="<?php echo $post->post_name; ?>">
<a href="www.librarywebsite.com/librarypage/" ><?php the_post_thumbnail('medium'); ?></a>
<p><?php the_title(); ?></p>
<ul class="resource_icons">
<li><img src="<?php bloginfo('stylesheet_directory'); ?>/img/icon-download.png" alt="Download PDF" /></li>
<li><img src="<?php bloginfo('stylesheet_directory'); ?>/img/icon-library.png" alt="library" /></li>
</ul>
</div>
</div>
Like I've mentioned my catch all trigger currently get's triggered on every single PDF download, I just want to omit the links that have class "Library_download".
In my opinion you made a mistake in your regex in "Custom Event" exclusion rule (that's why this rule doesn't work). You have "\*" (with regex matching checked). Try to change regex to:
.*
This will match every event (and then of course preserve this: Trigger Fires on: Click Class - contains - "Library_booking").
In your case regex like this: "\*" will match only to event strictly named as "*" (star)

Form action duplicates url

new to CI and for some reason the form submits to a wrong url.
the result is : http://localhost/ci/index.php/subjects/localhost/ci/index.php/do_upload
and can't understand why.
This is the html code :
echo form_open_multipart('do_upload');
?>
<input type="file" name="files[]" id="fileupload"
style="position:absolute; top:-200px" multiple />
<input type="submit" id="uploadFile" style="position:absolute; top:-200px" />
<?php echo form_close(); ?>
Any help?
I've also tried to write subjects/do_upload on form open, same thing.
Check your config for base_url and site_url
Leave them '' blank.

if isset doesn't work in php

I'm having a form with only one submit button. I don't know why, but when I use this code and I click on the submit button, nothing is happening. If I use a ! before the isset you'll see the echo in the page. I don't know what's wrong with it.
<form>
<input type="submit" value="Toevoegen" name="addImg" />
</form>
<?
if (isset($_POST['addImg'])) {echo "haaallloooo";}
?>
Maybe, form by default is sending variables by get, try using method="POST" attribute in form tag
You have to set the method to POST.
Otherwise you can use:
$_REQUEST['addImg']
The variable $_REQUEST can access both GET and POST parameters.
Form needs an action and a method.
<form action="" method="post">
<input type="submit" value="Toevoegen" name="addImg" />
</form>
<?
if (isset($_POST['addImg'])) {echo "haaallloooo";}
?>
Regarding "isset", if $_POST['addImg'] is not set, it doesn't echo "haaallloooo".
isset — Determine if a variable is set and is not NULL
Check http://hk.php.net/manual/en/function.isset.php

View Helper, Partial View or Something Else

I am new to Zend Framework and I have a question about something I am trying to do.
The main content of most pages of the application that I am working on will consist of 1 or more div elements that need to be styled the same.
Here is an example of the HTML that I want to generate:
<div id='admin-locations' class='panel'>
<header class="panel-header">
<h2>Locations</h2>
</header>
<div class='panel-content'>
<div id='locations-table' class='google-vis-table'></div>
<form id='locations'>
...
</form>
</div>
</div>
I know I can easily do this by pushing the form to my view script in my controller then adding this code to my controller.
<div id='admin-locations' class='panel'>
<header class="panel-header">
<h2>Locations</h2>
</header>
<div class='panel-content'>
<div id='locations-table' class="google_vis_table"></div>
<?php
echo $this->formLocations;
?>
</div>
</div>
But that is not DRY.
The example I used here has a Google Visualization Table and a Zend Form in it's content. Sometimes the panels will need to contain a form. Sometimes they won't, so I don't think form decorators are the way to go. So basically, the id of the panel, the panel header text and the content of div class='panel-content' need to be dynamic. Everything else will stay the same from panel to panel.
What is my best option here?
You might want to consider using partials:
http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.partial
For example, you could have an admin-locations.phtml partial that contains:
<div id='admin-locations' class='panel'>
<header class="panel-header">
<h2>Locations</h2>
</header>
<div class='panel-content'>
<div id='locations-table' class="google_vis_table"></div>
<?php echo $this->form; ?>
</div>
</div>
Now you can simply repeatedly call the partial within a view, with or without supplying a form:
...
echo $this->partial('admin-locations.phtml');
echo $this->partial('admin-locations.phtml', array('form' => $this->yourForm);
echo $this->partial('admin-locations.phtml');
...
Hope this helps.

Symfony: form field access with no sfForm object

i'm working on a symfony project and i developed a form to upload a file and save its info to a table in my model. And didn't use the sfForm class to implement my form.
Here you have my form
<form name="new_file" action="<?php echo url_for('home/uploadFile');?>" method="post">
<input type="file" id="file">
<input value="<?php echo $codigo_maestro?>" id="master_id">
<input value="<?php echo $codigo_entidad?>" id="entity_id">
<input type="submit" value="Upload">
</form>
So now i'm trying to access the fields of the sumbited form in my action function and don't know how :(
$request->getParameter('file');
$request->getParameter('master_id');
$request->getParameter('entity_id');
this code didn't work.
So please help me solve this! How can i access the fields of my form from the action??
You need to add a name to your form fields, that's the name you can access them via $request->getParameter().
finally i did this way, maybe not most elegant, but working
in action.class.php
$file= $_FILES['file'];
$filesize = $archivo['size'];
$filetype = $archivo['type'];
$filename = str_replace(' ','-',$file['name']);