How to add class to Form in Yii framework? - css

I have a form in Yii, and I want to add a class to the form :
<form class="subscribe_form" action="#" method="post">
I tried this but it's not working :
<?php $form=$this->beginWidget('CActiveForm', array(
'class'=>'subscribe_form',
'id'=>'mail-list-addmail-form',
'enableAjaxValidation'=>false
)); ?>
Thanks for helping me!.

You need to pass an htmlOptions property, like this:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'mail-list-addmail-form',
'enableAjaxValidation'=>false,
'htmlOptions'=>array(
'class'=>'subscribe_form',
)
)); ?>
from http://www.yiiframework.com/doc/api/1.1/CActiveForm#htmlOptions-detail

htmlOptions: additional HTML attributes that should be rendered for the form tag.
htmlOptions: there is commonly through all HTML helpers CHtml, CActiveForm and you can set the custom HTML options in this property.

Related

How to design a php page theme template in wordpress using either html or css?

<?php
/*
Template Name: isbn
*/
?>
<form action="" method="post" name="myForm">
Filter <input id="isbn" type="text" name="isbn" />
<input type="submit" name="submit" value="Submit" /></form>
<?php get_header(); ?>
<?php
if(isset($_POST['submit']))
{
global $wpdb;
$table_name = "isbn"; // change this to your table name
$field = $_POST['isbn']; // change this to your isbn field $_POST['ISBN'];
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name where isbn = '".$field."'");
foreach ($retrieve_data as $retrieved_data) {
echo $retrieved_data->title;
// echo $retrieved_data->image; // for image
}
}
?>
This is a search form which i want to design. I have created this form in a page template named isbn. But when i am opening that page for editing i am unable to do this. I am using divi theme in wordpress.
So divi theme is not allowing me to edit this page. Due to which this page is looking very bad in look wise.
Can anyone help me for designing this page by giving their codes or simply by giving their suggestions?
I am facing one more problem whenever i am writing css code in above code i am not getting anything. So i am totally blank that how to deal with this
Just create a WordPress page and add shortcode which you added in functions.php before. Don't create template for this page just use your shortcode only.
First, you have to create a page using divi theme, then create shortcode for this form in functions.php and then use this shortcode in your page.
you are inserting the form above the get_header(); function, so it will be outside of the html tag and outside of the body tag. Move it into the body, then it should at least appear on the page, and you'll see what you need to do next.

In cakephp 3 I got error Unexpected field in POST data

In cakephp 3 I got error Unexpected field in POST data.
Actually that field is not in my table, but I want to use in controller.
The Security Component in CakePHP is not forgiving. If you want to allow a field thru that should not go thru the Security Component hashing process, you need to use the unlockedField method that comes with the FormHelper class as such:
$this->Form->unlockField('field');
If this does not work, you will need to provide us with the pertinent code
I was getting the similar error in cakephp 3.4 I was using the simple html form and input fields. I was passing the input fields data in array. like below:-
<form action="" method="post">
<input name="data[1][category_1]" id="category_1">
</form>
Then i do some R&D and found that we need to use the cakephp form helper to create the form and its fields like below :-
In case of pass form data in array
<?= $this->Form->create($user, ['url' => ['controller' => 'Users', 'action' => 'saveOrder']]); ?>
<?= $this->Form->input("Data.1.category_1"); ?>
<?= $this->Form->end() ?>
In case of simple input fields you can do the code like below
<?= $this->Form->create($user, ['url' => ['controller' => 'Users', 'action' => 'saveOrder']]); ?>
<?= $this->Form->input("category"); ?>
<?= $this->Form->end() ?>
This work form me and resolve the error Unexpected field in POST data in cakephp 3.4

can't view html content when submit form in wordpress

i'm was create a menu and Form in wordpress.
then, i was create form send email for my customer.
it's oke. But my problems is :
I'm writing some thing in editor, add color, font size... for text, add images....
But when echo the result after click submit button, it not show same as in the editor content,
all html code was removed, (the heading form h1 -> h6 is keep).
I want the result of Echo was same as in the forms. (All html was keep)
Help me to solve this problem, Please !
here is my code
<form method="post" id="kaka" name="form_send_mail">
<?php wp_editor('default text', 'idgiday', $settings = array(
'drag_drop_upload' => true,
'editor_height' => '300',
'textarea_name' => 'textarea_name_td'
) );
?>
<imput type="text"></imput>
<input type="submit" value="ok">
</form>
<?php
echo #$_POST['textarea_name_td'];
?>
Actually you need to get the output via editor ID which you have mentioned idgiday ,
echo $_REQUEST['idgiday'];
You can save the editor output via,
add_post_meta($post_id,'idgiday',$_REQUEST['idgiday']);
And then get the output,
get_post_meta($post_id,'idgiday',true);

Adding class to the comment form in Wordpress

I want to add a class to the form, not form items. I've looked on http://codex.wordpress.org/Function_Reference/comment_form but there is no mention of adding a class to the form.
UPDATE:
Wordpress finally supports the possibility to add classes to the comments form. See Nabil Kadimi's answer to get an example.
My outdated answer:
Because Wordpress still hasn't supported this option, I've worked out the following workaround:
<?php
ob_start();
comment_form();
echo str_replace('class="comment-form"','class="comment-form your-custom-class"',ob_get_clean());
?>
Now the standard class comment-form will be replaced by itself plus the custom class.
In the documentation for the comment_form() function:
WordPress 4.4.0 Introduced the 'class_form' [...] arguments.
So you would do:
// Output the comment form with a custom class:
comment_form ( array( 'class_form' => 'my_custom_class' ) );
One a second thought
I prefer using hooks:
/**
* Callback function for the `comment_form_defaults` filter hook
*
* #param Array $defaults Defaults.
* #return Array Defaults modified.
*/
function se_8476425_modify_comment_form_defaults( $defaults ) {
$defaults[ 'class_form' ] = 'class1 class2 class3';
return $defaults;
};
add_filter( 'comment_form_defaults', 'se_8476425_modify_comment_form_defaults' );
This solution is more generic as you can use it to modify the default function behavior and themes you don't "own".
Since wordpress versiĆ³n 4.1 (Dec, 2014) the comment_form function allows to specify a class attribute for the submit button.
Php Code:
$comments_args = array('class_submit' => 'btn btn-default');
comment_form($comments_args);
Resultant HTML Button code:
<input name="submit" type="submit" id="submit" class="btn btn-default" value="Submit" />
For reference see the related ticket: https://core.trac.wordpress.org/ticket/20446
You can easily modify the code of the submit button of the coment form with this filter :
function custom_submit_comment_form( $submit_button ) {
return '<input name="submit" type="submit" id="submit" class="btn btn_2" value="Laisser un commentaire" />';
}
add_filter( 'comment_form_submit_button', 'custom_submit_comment_form' );
You can just edit your single.php and wrap the :
<?php comments_template(); ?>
In a class. Something like:
<div class="myClass">
<?php comments_template(); ?>
</div>

Override form using PHPTemplate

I was wondering how I should override the way a form looks in Drupal 7 using PHPTemplate. I have some difficulties displaying all the information on my page.
I have a page with a form and some miscellaneous information.
I have tried:
foo.module
function foo_add_form($form, &$form_state, $foo) {
...
$form['#theme'] = 'foo_add';
return $form;
}
function foo_theme($existing, $type, $theme, $path) {
return array(
'foo_add' => array(
'template' => 'foo-add',
'render element' => 'form',
),
);
}
foo-add.tpl.php
<?php
// First form
print drupal_render_children($form);
?>
<!-- Miscellaneous information -->
<div id="links">
<ul>...</ul>
<form action="#" method="post" id="second-form">
<fieldset id="i-want">
...
</fieldset>
...
</form>
</div>
At the moment the form and miscellaneous information are being displayed. However, the 2nd form (id="second-form") is being removed somehow. I can see it in the source, but when I inspect the element with chrome/firefox, I can no longer see the form element. I can see the div, ul and fieldset tags though.
Has anybody done this before?
Typically, you wouldn't add to the form at the theme layer. Instead, you'd use a custom module, implementing hook_form_alter to modify the form.

Resources