Submit 'links' with CakePHP formHelper - html

Is it possible to create a submit 'link' with CakePHP 2.4's FormHelper? I'm trying to put some less-used submit buttons from my POST form into a Bootstrap dropdown and am running into trouble since they only seem to be able to create a button, which won't work in a dropdown.
Since this is inside a form already, clearly this isn't what I want a postLink for- but is there any good Cake way around this? postLink just makes a plain link, but it won't play well inside another form.
echo $this->Form->button('Download Excel CSV', array(
'type' => 'submit',
'class' => '',
'formaction' => '/posts/csv',
));

Just use the HtmlHelper's url() method:
<button type="button" formaction="<?php echo $this->Html->url('/posts/csv'); ?>">
Click Here
</button>
(I realize you don't want it in a button element, but - showing the concept).
Side note: you should really be using an array instead of a hard-coded formaction:
$this->Html->url(array('controller'=>'posts', 'action'=>'csv'));

Related

Yii2 submit form and return the result in Pjax container

How to submit the form, process the data, send it to action and in the end, place it in the pjax container? I know solution where the pjax container is wrapping the form but my case is something like this:
$form = ActiveForm::begin();
...
...
...
ActiveForm::end();
some html
Pjax::begin(['id' => 'container']);
The result from the controller action goes here
Pjax::end():
I've seen solution like this with javascript/jQuery function along ago but can't find it now. Can some give me example or at least some useful link. Thank you in advance! P.s. Red a lot of articles but couldn't fine something for my case.

Kartik Gridview conflict with my templates menu

I have a template that i was using for my project.
Look at the picture below:
This is when i am not using the kartikGrid. the dropdown menu running as well as the template want.
look at the image below:
this is when i use kartik, the dropdown menu not running anymore.
can some body tell me why it happen.
The template using different bootsrap version with kartik.
thaks.
Hope some body help me.
Imaginaroom, that did the trick for me thank you.
My top menu wasn't responding (direct link, or drop down menu) after kartik was used. I added an id to my menu widget and it did the trick.
echo Nav::widget([
'id' => 'topMenuID',
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
Manually assign different ids to all widgets, so there won't be any conflicts.
If you don't assign ids to widgets, yii gives them one automatically, but the problem occures when loading data with ajax or pjax, then Yii cannot know which ids are already used in the page.
Every widget in Yii2 has a property 'id' that you can assign in configuration array when calling a widget.
Add this code in layout or page that has problem:
$this->registerJs( "$(document).ready(function() { $('.dropdown-toggle').dropdown(); });", View::POS_END, 'ecommerceProductJs' );

How do I change the HTML that is created with links in Wordpress?

I am trying to create a Wordpress template from static HTML that I made a while back. In the HTML there is a <span> tag within each link in the main navigation menu. It looks like this:
https://www.dropbox.com/s/52zgm8kpj8cfb51/Screenshot%202014-08-25%2018.35.47.png?dl=0
The span accounts for the small tab-like extension to the left of the links. This is to give the page a three-dimensional effect. Unfortunately, when I converted the HTML to a Wordpress theme, I was not able to find how to do this whilst making use of Wordpress' dynamic menu function. This creates the links automatically and generates the HTML. I was wondering if anyone knew a way in which I could edit the generated hyperlinks to include the <span> tag.
Assuming you're using the wp_nav_menu() function to generate the menu links, I believe the code you're looking for is:
<?php
$defaults = array(
'link_before' => '<span>',
'link_after' => '</span>'
);
wp_nav_menu( $defaults );
?>
http://codex.wordpress.org/Function_Reference/wp_nav_menu

formHelper type time : avoiding the annoying dropdown select input?

When i use the cakePHP form helper for a type 'time' field, it automatically generates a dropdown select input and not an easy&easy html5 type time keyboard input like this
Anyone has a quick solution to this ? (preferably without any javascript)
thanks !
FYI, finally i used a jQuery timepicker, that's working fine ! find it here
And after importing the css and js through cakePHP, it's very easy to use.
For example:
With an form element like this (note the type => text)
echo $this->Form->input('time', array(
'type'=>'text',
'label'=>'RĂ©el',
'div'=> array(
'class'=>'two columns')
));
you just call it with
<script>
$('#TimeID').timepicker();
</script>
Just lock the type by manually adding it.
So if you want to use a text field for JS snippets:
echo $this->Form->input('time', array('type' => 'text'));
You can also make it anything else (manually).
For "time" you can try
echo $this->Form->input('time', array('type' => 'time'));
Don't forget to adjust your data form input if necessary.
But careful with HTML5 stuff. This is not suitable for all browsers and therefore can lead to problems in some.

CakePHP hidden _method POST

When using the FormHelper->create(...), the HTML that gets rendered looks like this:
<form action="/blogs/add" method="post" accept-charset="utf-8">
<div style="display:none;">
<input type="hidden" name="_method" value="POST">
</div>
<!-- omitted: form inputs -->
</form>
Why is that div with the display:none; style there? How do I make it not show up?
UPDATE: Just to be clear, I'm wondering why both the div AND the hidden input inside the div show up. They don't seem to be necessary, and therefore I don't want them to be there.
For anyone coming to this recently, there is a simple solution to this now that doesn't involve a custom helper. Using the FormHelper templates, the block of code in question is generated by the 'hiddenBlock' template. (See the full list of default templates here: https://api.cakephp.org/3.2/class-Cake.View.Helper.FormHelper.html#%24_defaultConfig).
So, to amend the example given in CakePHP's documentation to match this case and remove the wrapping <div> around the hidden <input> for _method (assuming HTML5):
// In your View class
$this->loadHelper( 'Form' , [ 'templates' => 'app_form' ] );
// in config/app_form.php
return [
'hiddenBlock' => '{{ content }}'
];
I was confronted with this problem because I recently implemented a Content Security Policy that doesn't allow inline styling, and I thought I should share my working solution.
The div is there to be valid HTML.
Non-block-level elements (such as <input>) are not valid directly inside <form> tags until HTML5. Source
Edit: To answer your question, you can't easily get rid of it. It's hard-coded into FormHelper::create(), you'd have to override that method in a custom helper. Why is it bothering you anyways?
This link might help you.
Whenever you use FormHelper->create() method ,A hidden input field is generated to override the default HTTP method. You can also change it by passing type option. Kindly ask if it not worked for you.
Try:
echo $this->Form->create('User', array(
'inputDefaults' => array(
'div' => false
)
));
The divs won't be created on any input of the form.
use hiddenField => false property