I'm trying to update a database column using a checkbox. The idea is that I want to only display certain things on the homepage, so the checkbox should send either 0 or 1 to the DB. If the record has 0 in the first page column, it shouldn't appear on the homepage, if it has 1 it should appear.
I tried setting something up, but it doesn't work as intended (it just refreshes the page with no effect)
The checkbox:
<?php echo form_checkbox(array('name' => 'first_page', 'class'=>'checkbox-inline', 'value' => 1)); ?>
Controller:
if(null != ($this->input->post('first_page'))) {
$first_page = 1;
$book_id= $this->input->post('id'); (the id is sent to the controller via an extra hidden input field)
$this->book_model->first_page($first_page, $book_id);
}
Model:
$this->db->set ( "first_page", $first_page);
$this->db->where ( "book_id", $book_id);
$this->db->update ( "books" );
return;
Full form:
<?php echo form_open('admin/modifica_autor'); ?>
<?php echo form_hidden('id', $item->id_carte); ?>
<?php echo form_hidden('id_autor', $item->id_autor)?>
<label for="titlu_nou">Titlu:</label>
<?php echo form_input(array('name' => 'titlu_nou_carte', 'class'=>'form-control', 'value' => $item->titlu)); ?> <br>
<label for="autor_nou">Autor:</label>
<select name='autor_nous' class="form-control"><?php
foreach ( $autori2 as $row ) {
echo '<option value="' . $row->id_autor . '">' . $row->nume_autor . '</option>'; }
?></select><br>
<label for="domeniu_nou">Domeniu:</label>
<select name='domeniu_nou' class="form-control"><?php
foreach ( $domenii as $row ) {
echo '<option value="' . $row->id_domeniu . '">' . $row->nume_domeniu . '</option>';
}
?></select><br>
<label for="pret_nou">Pret:</label>
<?php echo form_input(array('name' => 'pret_nou', 'class'=>'form-control', 'value' => $item->pret.' LEI')); ?><br>
<label for="descriere_noua">Descriere:</label>
<?php echo form_textarea(array('name' => 'descriere_noua', 'class'=>'form-control textarea', 'value' => $item->descriere)); ?><br>
<label for="prima_pagina">Afisare pe prima pagina:</label>
<?php echo form_checkbox(array('name' => 'prima_pagina', 'class'=>'checkbox-inline', 'value' => 1)); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<?php echo form_submit(array('name'=>'submit_autor','value' => 'Modifica', 'class'=>'btn btn-default')); ?>
<?php echo form_close(); ?>
Related
I'm developing my own code to display the comment list and comment form.
What I need is to replace 'reply' button (only when is shown), with a comment form, next to the commentary to make the reply.
All the code I have so far is the following. Can someone help me fix it? Thanks.
<?php
$postid = XXX;
$comment_send = 'Send';
$comment_reply = 'Leave a Message';
$comment_reply_to = 'Reply';
$comment_author = 'Name';
$comment_email = 'E-Mail';
$comment_body = 'Comment';
$comment_url = 'Website';
$comment_cookies_1 = ' By commenting you accept the';
$comment_cookies_2 = ' Privacy Policy';
$comment_before = 'Registration isn\'t required.';
$comment_cancel = 'Cancel Reply';
$comments_args = array(
'fields' => array(
'author' => '<p class="comment-form-author"><br /><input id="author" name="author" aria-required="true" placeholder="' . $comment_author .'"></input></p>',
'email' => '<p class="comment-form-email"><br /><input id="email" name="email" placeholder="' . $comment_email .'"></input></p>',
'url' => '<p class="comment-form-url"><br /><input id="url" name="url" placeholder="' . $comment_url .'"></input></p>',
'cookies' => '<input type="checkbox" required>' . $comment_cookies_1 . '' . $comment_cookies_2 . '',
),
'label_submit' => __( $comment_send ),
'title_reply' => __( $comment_reply),
'cancel_reply_link' => __( $comment_cancel ),
'comment_field' => '<p class="comment-form-comment"><br /><textarea id="comment" name="comment" aria-required="true" placeholder="' . $comment_body .'"></textarea></p>',
'comment_notes_before' => __( $comment_before),
'comment_notes_after' => ''
);
comment_form( $comments_args, $postid );
?>
<ol class="commentlist">
<?php wp_list_comments(array('callback' => 'custom_comments_format'), get_comments(array('post_id' => $post_id))); ?>
<?php function custom_comments_format($comment, $args, $depth){ ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author">
<?php echo get_avatar( $comment, 56 ); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author()) ?>
</div>
<div class="comment-moderation">
<?php if ($comment->comment_approved == '0') : ?>
<p><?php _e('Your comment is awaiting moderation.') ?></p>
<?php endif; ?>
</div>
<div class="comment-meta commentmetadata">
<p ><?php printf(__('%1$s at %2$s'), get_comment_date('j F, Y'), get_comment_time()) ?><?php edit_comment_link(__('(Edit)'),' ','') ?></p>
</div>
<div class="user-comment">
<?php comment_text() ?>
</div>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php } ?>
</ol>
Ps: The relation between a form and a reply comment is the comment_parent input. I can stack a new form instead the reply button, but I dont know how to set the comment_parent id into the comment_form( $comments_args, $postid ); as I did before to customize the form itself.
<input type="hidden" name="comment_parent" id="comment_parent" value="XXX">
<div class="reply">
<?php //comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
<?php
if($depth < $args['max_depth']){
$comments_args = array(
'comment_field' => '<input type=\'hidden\' name=\'comment_parent\' id=\'comment_parent\' value=\''.get_comment_ID().'\' />'
);
comment_form( $comments_args, $postid );
}
?>
</div>
Following my own steps, ive sloved the problem now its DONE like this.
<div class="reply">
<?php //comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
<?php
if($depth < $args['max_depth']){
$postid = $comment->comment_post_ID;
$comments_args['submit_field'] = '<p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Send"> <input type="hidden" name="comment_post_ID" value="'.$postid.'" id="comment_post_ID"> <input type="hidden" name="comment_parent" id="comment_parent" value="'.get_comment_ID().'"> </p>';
comment_form( $comments_args, $postid );
}
?>
</div>
the inserted data always result to Upland even though I selected either the tab-pane Irrigated or Rainfed, result is still the same using echo. Sorry for posting a common problem. I am new in array insertion to database.
$types = array(
'irrigated' => 'Irrigated',
'rainfed' => 'Rainfed',
'upland' => 'Upland'
);
$seed_types = array(
'hybrid_' => 'Hybrid',
'taggedSeeds_' => 'Tagged Seeds from (RS/FS/CS)',
'goodSeedsTagged_' => 'Good Seeds from Tagged FS/RS',
'goodSeedsStarter_'=>'Good Seeds from Starter RS/CS',
'goodSeedsTraditional_'=>'Good Seeds of Traditional',
'farmSaved_'=>'Farm Saved Seeds'
);
foreach($types as $type){
echo '<div id="'.$type.'" class="tab-pane fade tab-title">';
echo "<br/>".$type."<hr/>";
echo "<input type='hidden' name='ecosystem' value='".$type."'>";
foreach($seed_types as $seed_name => $seed_type){
echo '<div class="row form-group">';
echo '<div class="col-md-4 table-body">'.$seed_type.'</div>';
for ($x = 0; $x <= 3; $x++) {
echo '<div class="col-md-2"><input type="number" class="form-control" name="'.$seed_name.''.$x.'" /></div>';
}
echo "</div>";
}
echo '</div>';
}echo '<div class="row" style="border-top:dashed 1px #eaeaea;padding-top:15px;">
<div class="col-md-11" style="text-transform:initial;">Note: Kindly check all the data before saving. Thank You.</div>
<div class="col-md-1">
<input type="submit" name="save-report" value="Save Data!" class="btn btn-success">
</div>
</div>';
echo '</div>';
<?php
if (isset($_POST['save-report'])) {
// Process
global $wpdb;
$ecosystem = $_POST['ecosystem'];
$result = $wpdb->insert('wp_sample', array (
'eco_system' => "$ecosystem",
'type' => "$seed_type",
));
}
Try like this.
$types = array(
'irrigated' => 'Irrigated',
'rainfed' => 'Rainfed',
'upland' => 'Upland'
);
$seed_types = array(
'hybrid_' => 'Hybrid',
'taggedSeeds_' => 'Tagged Seeds from (RS/FS/CS)',
'goodSeedsTagged_' => 'Good Seeds from Tagged FS/RS',
'goodSeedsStarter_'=>'Good Seeds from Starter RS/CS',
'goodSeedsTraditional_'=>'Good Seeds of Traditional',
'farmSaved_'=>'Farm Saved Seeds'
);
foreach($types as $type){
echo '<div id="'.$type.'" class="tab-pane fade tab-title">';
echo "<br/>".$type."<hr/>";
echo "<input type='hidden' name='ecosystem[]' value='".$type."'>";
foreach($seed_types as $seed_name => $seed_type){
echo '<div class="row form-group">';
echo '<div class="col-md-4 table-body">'.$seed_type.'</div>';
for ($x = 0; $x <= 3; $x++) {
echo '<div class="col-md-2"><input type="number" class="form-control" name=[number]["'.$seed_name.''.$x.']" /></div>';
}
echo "</div>";
}
echo '</div>';
}echo '<div class="row" style="border-top:dashed 1px #eaeaea;padding-top:15px;">
<div class="col-md-11" style="text-transform:initial;">Note: Kindly check all the data before saving. Thank You.</div>
<div class="col-md-1">
<input type="submit" name="save-report" value="Save Data!" class="btn btn-success">
</div>
</div>';
echo '</div>';
<?php
if (isset($_POST['save-report'])) {
// Process
global $wpdb;
foreach($_POST['ecosystem'] as $key => $value){
$ecosystem = $value;
$result = $wpdb->insert('wp_sample', array (
'eco_system' => $ecosystem,
'type' => $seed_type,
));
}
}
I'm building a theme for Wordpress on my own and I'm having som problems with my comment form. I want to change the text of the reply"button" (actually it's not a button, it's an a-class with onclick function). Now the default is "reply", but I want to change it to something else. How do a do that?
My php-file looks like this:
<?php
/**
* The template for displaying Comments.
*
* The area of the page that contains comments and the comment form.
*
*/
/*
* If the current post is protected by a password and the visitor has not yet
* entered the password we will return early without loading the comments.
*/
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die('Please do not load this page directly. Thanks!');
if (post_password_required()) {
?>
<p class="nocomments">Det här inlägget är lösenordsskyddat. Knappa in lösenordet för att se inlägget.</p>
<?php
return;
}
?>
<div id="commentsbox" class="post">
<?php if (have_comments()) : ?>
<h3 id="comments">
<?php comments_number('Inga kommentarer',
'En kommentar',
'% kommentarer'); ?>
än så länge.</h3>
<ol class="commentlist">
<?php wp_list_comments(array(
'avatar_size' => 70)); ?>
</ol>
<div class="comment-nav">
<div class="alignleft">
<?php previous_comments_link() ?>
</div>
<div class="alignright">
<?php next_comments_link() ?>
</div>
</div>
<?php else : ?>
<?php if (comments_open()) : ?>
<?php else : ?>
<p class="nocomments">Kommentarer är avstängda</p>
<?php endif; ?>
<?php endif; ?>
<?php if (comments_open()) : ?>
<div class="commentform_wrapper">
<div class="post-info">
</div>
<div id="comment-form">
<?php $comment_args = array( 'title_reply'=>'Vänligen lämna dina synpunkter och kommentarer:',
'title_reply_to' => __( 'Svara %s' ),
'cancel_reply_link' => __( 'Stäng svar' ),
'label_submit'=>'Skicka',
'reply_text' => 'Svara',
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Namn' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email">' .
'<label for="email">' . __( 'Mejl' ) . '</label> ' .
( $req ? '<span>*</span>' : '' ) .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />'.'</p>',
'url' => '' ) ),
'comment_field' => '<p>' .
'<label for="comment">' . __( 'Kommentarer' ) . '</label>' .
'<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
'</p>',
'comment_notes_after' => '',
);
comment_form($comment_args); ?>
</div>
</div>
<?php endif; ?>
</div>
The code that I want to reach looks like this, when inspecting with firebug:
<a class="comment-reply-link" onclick="return addComment.moveForm("div-comment-3", "3", "respond", "40")" href="/?p=40&replytocom=3#respond">Reply</a>
Add into functions.php :
function custom_comment_reply($content) {
$content = str_replace('Reply', 'Reply to this comment', $content);
return $content;
}
add_filter('comment_reply_link', 'custom_comment_reply');
Change " Reply" - "Reply to this comment" .
I got 3 array's where from i make 2 select box and a checkbox. What i want to do is that when i change CMS the checkbox value needs to change like in the array.
if i choose Joomla in the select box then i want the checkbox that is made with the $aOnderdelen, then in the array $aOnderdelen i have an array with Contact-form Foto-gallery and Carousel and this 3 have an array with the name of each CMS with different values and this are the values that the checkbox needs to get when you choose one of those and the CMS.
Example: i choose Joomla and i choose a Contact-formulier than contact-formulier checbox gets 3 as value.
$aCMS = array('SilverbeeCMS','Joomla','WP','Drupal','Scott');
$prijsPerUur=1;
$basisPrijs=
array(
array('titel' => 'Kopie', 'uur' => '8'),
array('titel' => 'Maatwerk', 'uur' => '10'),
array('titel' => 'Aangekocht', 'uur' => '12'),
array('titel' => 'Custom', 'uur' => '14')
);
$aOnderdelen = array
(
'Contact-formulier' => array
(
'SilverbeeCMS'=>3,
'WP'=>2,
'Joomla'=>3,
'Drupal'=>4,
'Scott'=> 5
),
'Foto-gallery' => array
(
'SilverbeeCMS'=>1,
'WP' => 3,
'Joomla'=> 4,
'Drupal'=> 5,
'Scott'=> 6
),
'Carousel' => array
(
'SilverbeeCMS'=>1,
'WP' => 4,
'Joomla'=> 5,
'Drupal'=> 6,
'Scott'=> 7
)
);
?>
This is the HTML form where the Select and checkbox are
<form action="" method="post">
<select id="cms" class="form-control" name="cms">
<?php foreach($aCMS as $key => $value): ?>
<option value="<?php echo strtolower($aCMS[$key]); ?>">
<?php echo $aCMS[$key]; ?>
</option>
<?php endforeach; ?>
</select>
<label><?php echo $template.$verplicht; ?></label>
<select id="templates" class="form-control" name="templates">
<?php foreach($basisPrijs as $key => $value): ?>
<option value="<?php echo $basisPrijs[$key]["uur"]; ?>">
<?php echo $basisPrijs[$key]["titel"]; ?>
</option>
<?php endforeach; ?>
</select>
<?php echo $oTitel; ?>
<div class="checkbox col-xs-12">
<div class="row">
<?php foreach($aCMS as $cmsKey => $cmsValue) ?>
<?php foreach($aOnderdelen as $key => $value):
foreach($value as $key1 => $value1)
{};
$i++;
echo "<div class='checkbox'>
<label><input class='check".$i."' type='checkbox' value='".strtolower($key)."' name='".$key."'>".$key."</label></div>"
;endforeach;?>
</div>
</div>
</form>
You have to use jquery along with AJAX for changing things dynamically
Simple example as
$(document).ready(function() {
$('#selector').change(function() {
//do here things required about changing
//You can also change DOM elements according to needs
//and have Ajax requests
})
});
I found how to do it
switch($("option:selected").val())
{
case "silverbeecms":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["SilverbeeCMS"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["SilverbeeCMS"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["SilverbeeCMS"] ?>)
break;
case "joomla":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["Joomla"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["Joomla"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["Joomla"] ?>)
break;
case "wp":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["WP"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["WP"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["WP"] ?>)
break;
case "drupal":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["Drupal"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["Drupal"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["Drupal"] ?>)
break;
case "scott":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["Scott"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["Scott"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["Scott"] ?>)
break;
}
New Answer more Flexibel
First Loop through the PHP array.
<?PHP
foreach($aCMS as $cmsKey => $cmsValue)
?>
<?php
foreach($aOnderdelen as $key => $value)
:
foreach($value as $key1 => $value1){};
?>
Than use data attr to get the prices.
<input class="<?php echo strtolower($key);?>" type="checkbox" value="<?php echo strtolower($key)?>" name="<?php echo $key;?>" data-silverbeecms="<?php echo $value['SilverbeeCMS']; ?>" data-wp="<?php echo $value['WP'];?>" data-joomla="<?php echo $value['Joomla'];?>" data-drupal="<?php echo $value['Drupal'];?>" data-scott="<?php echo $value['Scott'];?>">
After you get the Price in the data you can call this data from JQUERY and do the Match.
urenOnderdelen = 0;
$("#sCms, #templates, .contact-formulier, .foto-gallery, .carousel").change(function()
{
urenOnderdelen = 0;
urenTemplate = $("#templates").val();
$(".contact-formulier, .foto-gallery, .carousel").each(function()
{
if(this.checked)
{
urenOnderdelen+=parseInt($(this).data($("option:selected").val()));
}
});
$("#output, #output1, #gVoor").hide().fadeIn(300);
urenTemplate = $("#templates").val();
urenTemplate = parseInt(urenTemplate);
urenOnderdelen = parseInt(urenOnderdelen);
totaal = urenOnderdelen + urenTemplate;
$("#output").text(euroTeken + totaal*prijs);
});
Only first row is printing. Others are not printing.
Only getting a submit button in other rows
no errors or warnings found in code.
$v and $u array is same. When $v is used in both foreach nothing is printing.
<?php
foreach ($v->result() as $row)
{
?>
<tr>
<?php echo form_open('add_exam', array('role' => 'form', 'class' => 'form-horizontal')); ?>
<?php
foreach ($u->list_fields() as $field)
{
?>
<td class='hidden-1024'>
<div class="form-group">
<div class="col-sm-9">
<input class="form-control" type="text" placeholder="<?php echo $field; ?>" name="<?php echo $field; ?>" value="<?php echo $row->$field;?>">
</div>
</div>
</td>
<?php
}
?>
<td class='hidden-1024'>
<?php echo form_submit(array('name' => 'score_submit', 'id' => 'score_submit', 'value' => 'Save', 'class' => 'btn btn-embossed btn-primary m-r-20'));?>
</td>
<?php echo form_close(); ?>
</tr>
<?php
}
?>
It should be like this:
value="<?php echo $row->field;?>"