I'm fairly new to ZF.
I've been building a website on Zend Framework.
Everything looks good.
But I can't figure out how to resolve 1 problem, that actually is essential when developing article management module.
I've got form that has ZEND_TextArea that looks like this:
$full_text = new Zend_Form_Element_TextArea('full_text');
$full_text->setLabel('Description:')
->setOptions(array('rows' => '28','cols' => '40'))
->setRequired(true)
->addValidator('NotEmpty', true)
->addFilter('HTMLEntities')
->addFilter('StringTrim');
It work great, it has filter HTMLEntities that is really essential for filtering TextArea.
When displaying the saved data on the website I'm using html_entity_decode($item['full_text']) and it's fine.
But as soon as I try to edit it, it loads encoded text into my textarea, after editing it encodes my already encoded text - and on the front page I get terrible things like:
p;quot;color: #ff0000;">asdasda</
span>sdas <strong>sdfsdf&
lt;/strong>&
Maybe someone can help me figure out how to handle this problem, particularly load decoded data into Edit form of TextArea, so that my string doesn't get encoded twice, and when editing it was show in human manner and not into encoded one.
If you can provide code example - will be really AWESOME!!
thanks!!
Do not use HtmlEntities filter in edit form, if you use it in create form.
Create form :
$elements[] = $this->createElement('text','name',array(
'label' => 'test',
'filters' => array('HtmlEntities'),
));
Edit Form :
$elements[] = $this->createElement('text','name',array(
'label' => 'test',
'value' => html_entity_decode($value)
));
Your doing html_entity_decode() to set value, to show right 'name' to user..
When UPDATING data in model, you use htmlEntities filter again:
$data['name'] = $HtmlEntities->filter($data['name']);
Related
my system (built in Yii 1.1.19), I have several instances where I delete a record, and I have a confirm request to bring an alert before it continues to delete - all works fine, see below;
$this->menu = array(
array('label' => 'Delete User', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => "Are you sure you want to delete this user?",
'params' => array(Yii::app()->getRequest()->csrfTokenName => Yii::app()->getRequest()->csrfToken))),
);
Pretty standard Yii - however, I want the user to confirm their password before they delete specific records, as an extra security measure. Not necessarily within its own user model either, i.e. I might want to check the user's password before I delete a specific setting from a different model.
I understand what I need to do once I have an input - how to check the existing password, but I can't figure out how to actually alter the confirm to get the input form instead of standard confirm.
Can anyone help? Sounds like a straightforward request, but I can't seem to much online
Have you tried using "prompt" instead of confirm? or using a JS function and then calling prompt? https://www.w3schools.com/jsref/met_win_prompt.asp
That should allow you to get an input for the password. However, i don't think that's the best way since passwords are expected to be masked (prompt doesn't mask the input) so, what i would propose instead is to use an ajax loaded html form (could be modal) so you could properly handle the the password
I have a form that generates a pdf document that will be served to the user when submitted. I would like to have the pdf document open in a new window. How would I do that using Symfony forms? I've been doing some Google searching but have not been able to find any ready answers to how to do this.
I found the answer to my question and added it as reference for other Symfony developers. See my response below to learn how to use it in your project.
To get your form to redirect to a new window is insanely simple, once you know how. When you create your form ( if you are using form classes, which you should ), your form creation will look something like this:
$form = $this->createForm(new MyFormName(), $myObject);
To add the ability for your form to redirect, you need to add the third argument to your constructor, like this:
$form = $this->createForm(
new MyFormName(),
$myObject,
array(
'attr' => array(
'target' => '_blank'
)
)
);
Now, when your form is submitted, it opens the results in a new window.
I hope this information helps other developers from hitting their heads on their keyboards like I was doing.
I'm using Apatana's formatting features in PHP documents, it works well except with arrays where it transform this:
$data = array(
'email' => $params['email'],
'username' => $params['username'],
);
into this:
$data = array('email' => $params['email'], 'username' => $params['username']);
is there a way to avoid this and set custom formatting rules?
Yes. There is a way.
Go to the Studio's preferences and locate the 'Formatter' item. If you are using the default formatter profile, create a new one by clicking the '+' icon.
Click to edit the PHP formatting setting (double-click the 'PHP' item, or click it and than click the 'Edit' button).
Under the 'New Lines' tab, check the option to 'Insert new line between array-creation elements'. OK the dialogs. Make sure that the profile you just created is the selected one in the formatter preferences page, and format your code.
Cheers
I'm wondering if there is any proper way to include HTML in the setFlash() function of the Session component.
Basically I have this admin interface on an e-commerce website which allows administrators to create and edit "shops" found on the website. Upon saving the "shop", I would like CakePHP to display something like "Your shop has been successfully saved. Return to Shop Index". "Return to Shop Index" would be a link. I'm currently using plain old HTML like:
$this->Session->setFlash("Shop has been successfully published. Return to Shop Index");
Works, but it's HTML in the Controller, which I think is a "bad thing".
Thanks!
EDIT:
Thanks #YonoRan for solution. Missed that out in the CakePHP documentation. Here's what I did:
1) Created new element session_flash_link.ctp in app/views/elements.
2) Added the following code in session_flash_link.ctp:
<div id="flashMessage" class="message">
<?php
echo $message;
echo $this->Html->link($link_text, $link_url, array("escape" => false));
?>
</div>
3) Code in controller:
$this->Session->setFlash("Shop has been successfully saved. ", "session_flash_link", array(
"link_text" => "Return to Shop Management ยป",
"link_url" => array(
"controller" => "shops",
"action" => "manage",
"admin" => true
)
));
This might be a solution for what you are trying to do, it loads a "Layout" with all the HTML in it as a setFlash message.
Custom CakePHP flash message
Update:
I just checked the Manual for setFlash
SetFlash Manual
And it shows that you can specify and element that holds the HTML for the setFlash message + a bunch of other properties.
setFlash($message, $element = 'default', $params = array(), $key = 'flash')
So it seems like a better way of doing whats suggested in the first link I posted, because it doesn't require a new layout but just uses Elements.
Good luck.
I've just found another way to do this that doesn't need new specific templates:
You can use the HtmlHelper - which you can access since it's probably loaded in the view, and we have access to that:
// access the html helper
$Html = (new View($this))->loadHelper('Html');
// use it to generate a link
$resend = $Html->link(__('resend'), array(
'controller' => 'users',
'action' => 'resend',
));
// sprintf to insert the link to your standard message text!
$this->Session->setFlash(sprintf(_("Do you want to %s the email?"), $resend));
Should work in any case where you need Helper functionality in a View. Works in 2.3.5.
I would like to programatically (using php) fill out an existing drupal form to create a content type that is included in a contributed module.
Details: The module is SimpleFeed and the content type is Feed. I would like to call the module's functions to accomplish this. The method I am interested in is hook_insert which appears to require vid and nid which I am unsure what these are.
Any help is appreciated.
can you provide a bit more information (which modules?). generally, i'd probably suggest calling the modules functions to create the content type, instead of trying to pass it through a form programatically. this way you don't have to worry about implementation, and can trust that if the module works, it'll work for your script too :)
of course this does tie your module to theirs, so any changes in their functions could affect yours. (but then again, you run that risk if they update their database structure too)
ex.
// your file.php
function mymodule_do_stuff() {
cck_create_field('something'); // as an example, i doubt this
// is a real CCK function :)
}
edit: vid and nid are node ID's, vid is the revision id, and nid is the primary key of a particular node. because this is an actual node, you may have to do two operations.
programatically create a node
you'll have to reference the database for all the exact fields (tables node and node_revisions), but this should get you a basic working node:
$node = (object) array(
'nid' => '', // empty nid will force a new node to be created
'vid' => '',
'type' => 'simplefeed'. // or whatever this node is actually called
'title' => 'title of node',
'uid' => 1, // your user id
'status' => 1, // make it active
'body' => 'actual content',
'format' => 1,
// these next 3 fields are the simplefeed ones
'url' => 'simplefeed url',
'expires' => 'whatever value',
'refresh' => 'ditto',
);
node_save($node);
now i think it should automatically call simplefeed's hook_insert() at this point. if not, then go on to 2. but i'd check to see if it worked out already.
call it yourself!
simplefeed_insert($node);
edit2: drupal_execute() isn't a bad idea either, as you can get back some validation, but this way you don't have to deal with the forms API if you're not comfortable with it. i'm pretty sure node_save() invokes all hooks anyhow, so you should really only have to do step 1 under this method.
The drupal api provides drupal_execute() to do exactly this. I would suggest you avoid calling the functions directly to create the node (unless there is a performance reason). By using drupal_execute() all the proper hooks in other modules will be called and your code is far more likely to continue to work through future versions of drupal.
Note that a classic bug in using this method is not first calling something like
module_load_include('inc', 'node', 'node.pages')
which will load the code for your node creation form.
Calling node_save directly is generally considered deprecated and could leave you with broken code in future versions of drupal.
There is a nice example at this lullabot post