How can we add css class or id to the form element which has been created by Yii form bui
Imagine that I have created a form as follows:
Controller:
public function actionRegistration()
{
$form = new CForm('application.views.user.registerForm');
$form['user']->model = new Users;
$form['profile']->model = new Profile;
if(isset($_POST['Users']))
{
$form['profile']->model->attributes = $_POST['Profile'];
$_POST['Users']['mobile'] = $_POST['Profile']['mobile'];
$form['user']->model->attributes = $_POST['Users'];
if($form->validate()) {
$user = $form['user']->model;
$profile = $form['profile']->model;
if($profile->save(false))
{
$user->profile_id = $profile->id;
$user->save(false);
}
}
else {
$errors = array_merge($form['profile']->model->errors, $form['user']->model->errors);
}
}
$this->render('registration', array('form'=>$form));
}
View
<?php echo $form->renderBegin(); ?>
<div class="row">
<div class="nine columns">
<div class="field">
<?php echo $form['profile']['fname']; ?>
</div>
<div class="field">
<?php echo $form['profile']['lname']; ?>
</div>
<div class="row">
<div class="eight columns">
<div class="field phone">
<?php echo $form['profile']['phone']; ?>
</div>
</div>
<div class="eight columns">
<div class="field mobile">
<?php echo $form['profile']['mobile']; ?>
</div>
</div>
</div>
<div class="row">
<div class="eight columns">
<div class="field password">
<?php echo $form['user']['pass']; ?>
</div>
</div>
</div>
<div class="field address email">
<input type="text" name="Users[email]" value="" placeholder="Email" class="text input">
</div>
</div>
</div>
<div class="row text-center margins">
<span class="medium warning btn">
<button type="submit"Submit</button>
</span>
</div>
<?php echo $form->renderEnd(); ?>
I want to set an id or a class for my form element which is generated by $form->renderBegin() function. I don't know how to add any html options to the form. Please someone help me.
In your view file before renderBegin make assignment for attributes:
<?php
$form->attributes= array('id'=>'el123', 'class'=>'qwe');
echo $form->renderBegin(); ?>
Related
I bought a theme on ThemeForest to create listings. Users have access to a platform to create listings, edit them and also delete them. Each listing has its own page on the site.
I decided to add two new fields, one for the company's creation date and one for the number of employees in the company. My two fields have the following names nombre_d’employes= number of employees and annee_de_creation = company's creation date.
I can display the content of my ACF on the referencing pages via the following code
Création : <?php the_field( 'annee_de_creation' ); ?> and Employés : <?php the_field( 'nombre_d’employes' ); ?>. It's work fine.
But my problem is how can I allow users to change this from their configuration panel. The theme allows you to modify fields like opening hours, etc., and I tried to create my own code, but without success.
Here is all the code for the listing modification page (with the fields, etc.)
<div class="tr-single-box">
<div class="tr-single-header">
<h4><i class="ti-headphone"></i> <?php echo esc_html__('Business information', 'reveal-listing'); ?>
</h4>
</div>
<div class="tr-single-body">
<div class="row">
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label><?php echo esc_html__('Email', 'reveal-listing'); ?></label>
<input class="form-control" value="<?php echo reveal_get_listing_meta($editpostid, 'rlisting_email'); ?>"
name="rlemail" type="email" placeholder="business#gmail.com">
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label><?php echo esc_html__('Mobile', 'reveal-listing'); ?></label>
<input class="form-control" value="<?php echo reveal_get_listing_meta($editpostid, 'rlisting_mobile'); ?>"
name="rlmobile" type="text" placeholder="91 245 254 8745">
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label><?php echo esc_html__('Website', 'reveal-listing'); ?></label>
<input class="form-control" value="<?php echo reveal_get_listing_meta($editpostid, 'rlisting_website'); ?>"
name="rlwebsite" type="text" placeholder="https://yoursite.com/">
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label><?php echo esc_html__('Fax No', 'reveal-listing'); ?></label>
<input class="form-control" value="<?php echo reveal_get_listing_meta($editpostid, 'rlisting_fax_no'); ?>"
name="rlfax" type="text" placeholder="256 254 7854">
</div>
</div>
<div class="col-lg-12 col-md-12">
<div class="form-group">
<label><?php echo esc_html__('Address', 'reveal-listing'); ?></label>
<input class="form-control" value="<?php echo reveal_get_listing_meta($editpostid, 'rlisting_address'); ?>"
name="rladdress" type="text" placeholder="e.g 34 Wigmore Street, Canada">
</div>
</div>
<div class="col-lg-12 col-md-12">
<div class="form-group">
<label>Employés</label>
<input class="form-control" name="remploye" type="number" placeholder="12" value="<?php the_field( 'remploye' ); ?>">
</div>
</div>
<!-- test last -->
<?php acf_form_head(); ?>
<div id="primary">
<div id="content" role="main">
<p>My custom field: <?php the_field('remploye', get_the_ID();); ?></p>
<?php acf_form(); ?>
</div><!-- #content -->
</div><!-- #primary -->
<!-- end test -->
<div class="col-lg-12 col-md-12">
<div class="form-group">
<label>Année de création</label>
<input class="form-control" name="rfondation" type="number" placeholder="2004" value="<?php the_field( 'annee_de_creation' ); ?>">
</div>
</div>
An :<?php the_field( 'annee_de_creation' ); ?>
</div>
</div>
</div>
And I give you below my code that I added in the page to facilitate the reading. My first attempt was to call the field like this
<div class="col-lg-12 col-md-12">
<div class="form-group">
<label>Année de création</label>
<input class="form-control" name="rfondation" type="number" placeholder="2004" value="<?php the_field( 'annee_de_creation' ); ?>">
</div>
</div>
An :<?php the_field( 'annee_de_creation' ); ?>
</div>
It didn't work, so I tried this way, but still without success.
<?php acf_form_head(); ?>
<div id="primary">
<div id="content" role="main">
<p>My custom field: <?php the_field('remploye', get_the_ID();); ?></p>
<?php acf_form(); ?>
</div><!-- #content -->
</div><!-- #primary -->
Do you have any idea how I should go about making my code work? Thanks
Looking at the Create a front end form ACF docs, it appears you are calling acf_form_head() in the wrong place.
You should call acf_form_head() function before calling the wordpress get_header() function.
Example below taken from ACF docs...
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<p>My custom field: <?php the_field('my_custom_field'); ?></p>
<?php acf_form(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
I have 2 wordpress installations, 1 is for major content, the other is a help center.
the help center is installed in the major content directory. So you have the wordpress directory, and another in that directory, making it so we can use different themes and change the look between the two.
I'm just curious, on the search results page, I'm getting the correct url's, but they are going to 404 pages. I verified in the database that these records exist, so it's not a matter of the database not making these records and that these pages don't exist. Another note is that the search results page will return pages that have been created, but
<?php
get_header();
global $wp_query;
$total_result = $wp_query->found_posts;
?>
<div class="main">
<div class="main-hero">
<div class="container">
<h1>Boxstorm Help Center</h1>
<p>Search the Boxstorm Help Center documentation</p>
<div class="search-wrapper">
<form id="searchform" class="searchform" role="search" method="get" action="<?php echo site_url(); ?>">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input id="s" name="s" type="text" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder', 'boxstorm' ); ?>" value="<?php echo get_search_query(); ?>">
<span class="search-button-wrapper">
<input id="searchsubmit" type="submit" value="">
<i class="fa fa-search"></i>
</span>
</div>
</form>
</div><!-- / .search-wrapper -->
</div>
</div><!-- /.main-hero -->
<nav class="main-hero-subnav cd-secondary-nav">
<div class="container">
<div class="is-hidden-mobile">
<?php get_breadcrumb(); ?>
</div>
</div>
</nav>
<div class="panel sub-nav-hero">
<div class="container page">
<div class="columns is-multiline is-mobile search-results">
<div class="column is-3-desktop is-6-tablet is-full-mobile left">
<div class="columns top-cats is-multiline is-mobile is-centered">
<div class="column is-11-desktop is-10-tablet is-6-mobile">
<div>
<a href="<?php echo site_url(); ?>/getting-started/">
<i class="fas fa-list-ul"></i>
<h2>Getting Started</h2>
</a>
</div>
</div>
<div class="column is-11-desktop is-10-tablet is-6-mobile">
<div>
<a href="<?php echo site_url(); ?>/documentation/">
<i class="fas fa-book"></i>
<h2>Documentation</h2>
</a>
</div>
</div>
<div class="column is-11-desktop is-10-tablet is-6-mobile">
<div>
<a href="<?php echo site_url(); ?>/videos/">
<i class="far fa-play-circle"></i>
<h2>Browse Videos</h2>
</a>
</div>
</div>
<div class="column is-11-desktop is-10-tablet is-6-mobile">
<div>
<a href="<?php echo site_url(); ?>/contact/">
<i class="fas fa-at"></i>
<h2>Contact Support</h2>
</a>
</div>
</div>
</div>
</div>
<div class="column is-9-desktop is-6-tablet is-full-mobile right">
<h1 class="results"><?php printf( __( 'Search results for: <b>%s</b>', 'boxstormsupport'), get_search_query() ); ?></h1>
<div class="columns is-multiline">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part( 'content', 'search' ); ?>
<div class="column is-12 results">
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<?php the_permalink(); ?>
</div>
<?php endwhile; else : ?>
<div class="column is-12">
<p><?php _e( '<p>Sorry, but there were no results for the term <b style="font-weight:900;">'.get_search_query().'</b>. Please refine your search terms and try again.</p>' ); ?></p>
</div>
<?php endif; ?>
</div><!-- / columns -->
</div><!-- / columns is-9 right -->
</div><!-- / search-results -->
</div>
</div>
</div>
<?php get_footer(); ?>
The site is live at https://www.boxstorm.com/help-center. If you'd like to see the problem.
The pages follow this format in wordpress:
Pages parameters:
This is what I'm seeing:
Chrome
Firefox
Any help would be appreciated, thanks.
<div class="row">
<?php
global $wpdb;
$rows = $wpdb->get_results( "SELECT id, firstname, lastname, email, phone, voucher FROM wp_offer_user", ARRAY_A);
foreach ( $rows as $row ) {
$rowid=$row[id];
if($row[voucher] == null) { print_r ($row[id]); ?>
<div class="col-sm-12 tabel_voucher clearfix">
<div class="col-sm-2 voucher_box clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">First Name</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<?php echo $row[firstname] ?>
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Last Name</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<?php echo $row[lastname] ?>
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Mail ID</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<?php echo $row[email] ?>
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Mobile No</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<?php echo $row[phone] ?>
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Register Date</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
10/01/1991
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Voucher</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<form id="form-voucher">
<div class="field-wrap">
<input type="text" name="voucher" class="offer-voucher" />
</div>
<button name="submit" class="offer-submit">Submit</button>
<div class="ajax-loader"></div>
<div class="login-error"></div>
</form>
</div>
</div>
</div>
<?php
}
}
?>
</div>
This my function.php.
//User Profile Update
function user_voucher_form() {
// The $_REQUEST contains all the data sent via ajax
if ( isset($_REQUEST) ) {
$voucher = $_REQUEST['voucher'];
$id = $_REQUEST['id'];
global $wpdb;
$wpdb->update(
'wp_offer_user',
array(
'voucher' => $voucher // string
),
array( 'id' => $id ),
array(
'%s' // value1
),
array( '%d' )
);
if ( is_wp_error( $id ) ) {
echo "Error";
}
die();
}
}
add_action( 'wp_ajax_user_voucher_form', 'user_voucher_form' );
add_action( 'wp_ajax_nopriv_user_voucher_form', 'user_voucher_form' );
I have update user profile form create. but value not store in db...which problem.....i have using WordPress wpdb.
How to create get result and update table...please help me
Your get_results query doesn't look correct. What's in $rows when you do var_dump($rows);?
Try formatting this way (see more query structures here):
$variable = $wpdb->get_results(
$wpdb->prepare('
SELECT `column3`
FROM `wp_table`
WHERE `column1` = %s
AND `column2` = %d
',
$var1,
123
),
OBJECT
);
Also, your update structure looks correct - but please confirm that the $voucher is indeed the data to update and $id is the where statement:
$wpdb->update(
wp_table,
array(
'column3' => $variable, // the column to update
),
array(
'column1' => 123, // the first WHERE argument
'column2' => 'value2', // additional WHERE argument!
),
array('%s'), // the format of the update value
array(
'%d', // the format of the first WHERE argument
'%s' // the format of the second WHERE argument
)
);
I'm trying to show the featured image or the post thumbnail in every list items < li >. Here's the code:
<div class="row headline">
<ul class="col-md-12 col-sm-12">
<?php
$sql_submenu_produk_sql = $wpdb->get_results("
SELECT * from $wpdb->posts
WHERE post_parent=52 AND post_type='page' AND post_status='publish' group by ID;
");
?>
<?php foreach ($sql_submenu_produk_sql as $row_submenu_sql) { ?>
<li>
<div class="col-md-2 col-xs-12 bordered" style="min-height: 100px;">
<a href="" data-featherlight="image">
<?php echo get_the_post_thumbnail($post->ID); ?>
</a>
</div>
<div class="col-md-10 col-xs-12">
<h2 style="font-weight: normal;"><?php echo $row_submenu_sql->post_title ?></h2>
<p style="padding-bottom: 15px;"><?php echo $row_submenu_sql->post_content ?></p>
</div>
</li>
<?php } ;?>
</ul>
</div>
but, it's not showing after all while on the other page shows. Please help.
Should you have get_the_post_thumbnail($row_submenu_sql->ID); and not $row_submenu_sql->ID $post->ID is not defined in that loop.
<div class="row headline">
<ul class="col-md-12 col-sm-12">
<?php
$sql_submenu_produk_sql = $wpdb->get_results("
SELECT * from $wpdb->posts
WHERE post_parent=52 AND post_type='page' AND post_status='publish' group by ID;
");
?>
<?php foreach ($sql_submenu_produk_sql as $row_submenu_sql) { ?>
<li>
<div class="col-md-2 col-xs-12 bordered" style="min-height: 100px;">
<a href="" data-featherlight="image">
//UPDATE THIS LINE LIKE BELOW
<?php echo get_the_post_thumbnail($row_submenu_sql->ID); ?>
</a>
</div>
<div class="col-md-10 col-xs-12">
<h2 style="font-weight: normal;"><?php echo $row_submenu_sql->post_title ?></h2>
<p style="padding-bottom: 15px;"><?php echo $row_submenu_sql->post_content ?></p>
</div>
</li>
<?php } ;?>
</ul>
</div>
i got a template site when i bought a package and it has a built in chat function, however you need to press a "send" button each time to send chat messages, this is the script used, i guess it is kinda easy to do it but in not good at scripting :/
<div class="col-lg-4 border-left affix-items scrollbar" id="room-items">
<div id="dropboxy">
<?php
?>
</div>
</div>
<div class="col-lg-6 affix-players" style="padding:10px;">
<div id="playersdropboxy">
<?php include_once("players.php"); ?>
</div>
<div id="affix-players" class="scrollbar">
<div id="rooms"></div> </div> </div> <div class="col-lg-5 affix-right">
<div class="col-xs-24 chat"> <div class="row chat-container">
<div class="row chat-buttons"> <div class="col-xs-24"> <div class="media-body"> <div class="input-group">
<input type="text" class="form-control chat-message" id="text-massage" style="margin-left:6px;" maxlength="300"> <span class="input-group-btn">
<?php if(isset($_SESSION['steamid'])) { ?>
<button class="btn btn-primary" type="submit" data-loading-text="<i class='fa fa-spinner fa-spin'></i> WAIT..." id="send_massage" style="margin-right:6px;">SEND</button>
<div class="sml-bnt" id="smile"></div>
<? }
else { ?>
<form method="get" action="index.php"><input type="hidden" name="login" value=""/><input type="submit" class="btn btn-primary" value="Log in to chat" style="margin-right:6px;"/></form>
<?php }
?>
</span> </div> </div> </div> </div>
<div class="col-xs-24 messages messages-img" style="width:250px;">
<?php if(isadmin($_SESSION['steamid'])){
echo'Admin tools: [clear chat], [turn '. (chaton() ? 'off' : 'on').']';
} ?>
<? include ('mini-chat.php'); ?>
</div> </div>
</div>
<div id="raffle"><div class="col-xs-24 raffle"> <div class="cont"> <div class="circle"> <img id="raffle-img"> </div> <h4 class="name" id="raffle-name"></h4>
<h4 id="countdown-raffle-timer" data-countdown="2020-08-08"></h4>
<a class="btn btn-default" href="?login">LOG IN</a> </div> </div> </div> </div> </div>
Try change method="get" to method="post"