I'm new in Moodle development I'm stuck in Moodle form submission.
Mustache Template Code
<button type="button" onclick="request_access(this)" id="{{ data }}"
class="btn btn-primary col mr-1" data-action="save">
{{#str}} savechanges {{/str}}</button>
Form created in PHP
$editorhtml = '';
$editor = editors_get_preferred_editor();
$editor->use_editor("usernotes", array('autosave' => false));
$editorhtml .= html_writer::start_tag('div', array('class' => 'ltoolusernotes'));
$editorhtml .= html_writer::start_tag('form', array('method' => 'post', 'action' => $args['pageurl'], 'id' => 'notes-from', 'class' => 'mform'));
$editorhtml .= html_writer::tag(
'textarea',
'',
array('id' => "usernotes", 'name' => 'ltnoteeditor', 'class' => 'form-group', 'rows' => 20, 'cols' => 100)
);
$editorhtml .= html_writer::tag('input', '', array(
'type' => 'hidden',
'name' => 'course',
'value' => $args['course'],
));
$editorhtml .= html_writer::tag('input', '', array(
'type' => 'hidden',
'name' => 'contextid',
'value' => $args['contextid'],
));
$editorhtml .= html_writer::tag('input', '', array(
'type' => 'hidden',
'name' => 'contextlevel',
'value' => $args['contextlevel'],
));
$editorhtml .= html_writer::tag('input', '', array(
'type' => 'hidden',
'name' => 'pagetype',
'value' => $args['pagetype'],
));
$editorhtml .= html_writer::tag('input', '', array(
'type' => 'hidden',
'name' => 'pagetitle',
'value' => $args['pagetitle'],
));
$editorhtml .= html_writer::tag('input', '', array(
'type' => 'hidden',
'name' => 'pageurl',
'value' => $args['pageurl'],
));
$editorhtml .= html_writer::tag('input', '', array(
'type' => 'hidden',
'name' => 'user',
'value' => $args['user'],
));
$editorhtml .= html_writer::end_tag('form');
$editorhtml .= html_writer::end_tag('div');
$editorhtml .= ltool_note_load_context_notes($args);
Firstly, I'm confused, button and form both are located in different locations nevertheless they are connected how?
So I can't use the form id in the button's file.
I have tried a solution which is reload()(event) the page on reload data submit but sometimes reload event is fired before the form submission. so data can't submit.
what is the solution? I want to solve it using JS.
Related
$user
id
name
001
user 1
002
User 2
<ul>
<?php foreach($user as $user( { ?>
<input class="is-selected" type="checkbox" value="<?= $value->user->id ?>" />
<?php } ?>
</ul>
<button type="submit" class="btn is-primary">Send Reminder</button>
I'm using YII2, I'm displaying a list of inactive users. I'm using the checkbox to select the user. I'm going to send an email to the user I tagged.
how can i get id value from that checkbox and send data to controller?
I try to use javascript/jquery but i can't solved yet, i need some help from you guys
The above screenshot and your implementation is like you are talking 2 different things.
You would just be required a Grid View with CheckboxColumn
<?php
use yii\bootstrap\ActiveForm;
use yii\grid\GridView;
use yii\helpers\Html;
$form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
'id' => 'user_form',
'options' => ['class' => 'lfp-listing']
]);
echo Html::submitButton('Send Reminder', ['class' => 'btn is-primary', 'name' => 'action', 'value' => 'send_reminder']);
echo GridView::widget([
'dataProvider' => $dataprovider,
'columns' => [
'id',
'name',
'email',
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' =>
function ($model) {
return ['value' => $model->id, 'class' => '', 'id' => 'checkbox'];
}
],
]
]);
ActiveForm::end();
Considering your Action is actionIndex()
public function actionIndex()
{
if (isset($_REQUEST['action']) && isset($_REQUEST['selection']) && 'send_reminder' == $_REQUEST['action'] ) {
foreach ($_REQUEST['selection'] as $userIds) {
//write down the email code here....
}
}
friends of Stack overflow, what happens is that I have an email form in PHP Script and the idea is that once one sent the message successfully, I redirect you to a page, in my case I want to redirect users to a "Thank you" page.
I have managed that once the message is sent, a green box appears saying "Thank you for sending your message" and when it is not sent, an error box comes out, but I have not managed to redirect once it was successfully sent to a "Thank you" page.
This is the code
<?php
require_once('FormProcessor.php');
$form = array(
'subject' => 'New Form Submission',
'email_message' => 'You have a new form submission',
'success_redirect' => '',
'sendIpAddress' => true,
'email' => array(
'from' => '',
'to' => 'myemail#gmail.com'
),
'fields' => array(
'name' => array(
'order' => 1,
'type' => 'string',
'label' => 'Name',
'required' => true,
'errors' => array(
'required' => 'Field \'Name\' is required.'
)
),
'email' => array(
'order' => 2,
'type' => 'email',
'label' => 'Email',
'required' => true,
'errors' => array(
'required' => 'Field \'Email\' is required.'
)
),
'message' => array(
'order' => 3,
'type' => 'string',
'label' => 'Message',
'required' => true,
'errors' => array(
'required' => 'Field \'Message\' is required.'
)
),
)
);
$processor = new FormProcessor('');
$processor->process($form);
?>
this is the html
Name
Email
Message
Submit
Thank you! Your message has been sent.
Unable to send your message. Please fix errors then try again.
use this header("Location: https://somewahere.com/thankYouPage.php");die();
I have a input like this on my first page <input type="number" id="people" name="ppl" min="1" class="uniform-input number" value="7" required="">
I wanted to use the value to toggle some fields on the woocommerce checkout. I want to show 2 name fields when the input value="2" and so on. But the code deletes all the custom fields. I don't know if I classed and targeted the div correctly Does anyone know what the problem is?
header.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
toggleFields();
$("#people").on("keyup change", function () {
toggleFields();
});
});
function toggleFields() {
$("#personen1, #personen2, #personen3, #personen4, #personen5, #personen6, #personen7, #personen8").hide();
if ($("#people").val() < 9)
$("#personen" + $("#people").val()).show();
}
</script>
functions.php
function wordimpress_custom_checkout_field( $checkout ) {
//Check if Book in Cart (UPDATE WITH YOUR PRODUCT ID)
$book_in_cart = wordimpress_is_conditional_product_in_cart( 759 );
//Book is in cart so show additional fields
if ( $book_in_cart === true ) {
echo '<div class="container" id="personen1"><div class="jumbotron"><h2 style="color:red;">' . __( 'Buchungsinformationen' ) . '</h2>';
woocommerce_form_field( 'person1_name', array(
'type' => 'text',
'class' => array( 'person1 form-row-wide' ),
'placeholder' => 'Vorname und Nachname eingeben',
'label' => __( '1. Person' ),
), $checkout->get_value( 'person1_name' ) );
echo '</div>';
echo '<div class="container" id="personen2"><div class="jumbotron">';
woocommerce_form_field( 'person1_name', array(
'type' => 'text',
'class' => array( 'person1 form-row-wide' ),
'placeholder' => 'Vorname und Nachname eingeben',
'label' => __( '1. Person' ),
), $checkout->get_value( 'person1_name' ) );
woocommerce_form_field( 'person2_name', array(
'type' => 'text',
'class' => array( 'person2 form-row-wide' ),
'placeholder' => 'Vorname und Nachname eingeben',
'label' => __( '2. Person' ),
), $checkout->get_value( 'person2_name' ) );
echo '</div>';
}
}
I use the follow code to handle WordPress pagination. For instance, if the user goes to page 9, My code will echo this URL
'http://jjh.com/Cute/page/9/?post_per_page=60'.
My problem is this:
can I reset the page to 1 whenever I change the post_per_page number?
I allow the user to change this parameter, and I want to reset to the top when they use it.
<?php
//I cut some unnecessary code
// I have a select dropdown to select post_per_page
$arg = array(
'post_type' => 'post',
'posts_per_page' => $post_per_page,
'cat' => $page_cat,
'paged' => $paged,
'offset' => $offset,
'prev_text' => __('«'),
'next_text' => __('»'),
'mid_size' => 2
);
$wp_query = new WP_Query($arg);
echo paginate_links( $arg );
?>
Try this code:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_type = 'post';
$args=array(
'post_typr' => $post_type,
'cat' =>3,
'posts_per_page' => 6,
'paged' => $paged,
'orderby' => 'title',
'order' => 'asc'
);
$my_query = null;
$my_query = new WP_Query($args);
After adding this code use while query <?php if ($my_query->have_posts() ) :
while ($my_query->have_posts()) : $my_query->the_post(); ?>
After while query end tag use <?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $my_query->max_num_pages
) );
?>
And then close if statement. <?php endif; wp_reset_query();?>
The error messages on this form ('after') should be getting hidden by default and only showing when the user presses "Register" submit button. However all the error messages are being shown by default - could any help suggest why this isnt working? The javascript file is printing to the console so it can find the file. Ive put the PHP for the form and the javascript below - any help would be very much appreciated, thank you,
This is the PHP to display the form:
<div class="span5 pull-right reg-form hidden">
<?php
echo $this->Form->create('Users.Register', array(
'url' => '/register',
'class' => 'span12 pull-right'));
echo $this->Form->hidden('current_url', array('value' => $this->here));
echo $this->Form->input('username', array(
'class' => 'reg-input',
'label' => array('text' => 'Email:', 'class' => 'reg-label main-color'),
'div' => array('class' => 'span12 reg-div'),
'required' => FALSE,
'after' => '<span class="hidden show-email-err show-err">This email address is already taken</span>
<span class="hidden show-emailvalid-err show-err">This email is not valid</span>'
));
echo $this->Form->input('confirm_username', array(
'class' => 'reg-input',
'label' => array('text' => 'Confirm Email:', 'class' => 'reg-label main-color'),
'div' => array('class' => 'span12 reg-div'),
'required' => FALSE,
'after' => '<span class="hidden show-user-err show-err">Re-email is incorrect</span>'
));
echo $this->Form->input('password', array(
'class' => 'reg-input',
'label' => array('text' => 'Password:', 'class' => 'reg-label main-color'),
'div' => array('class' => 'span12 reg-div'),
'required' => FALSE,
'after' => '<span class="hidden show-pass-long show-err">Password must be at least 6 characters</span>'
));
echo $this->Form->input('confirm_password', array(
'class' => 'reg-input',
'type' => 'password',
'label' => array('text' => 'Confirm Password:', 'class' => 'reg-label main-color'),
'div' => array('class' => 'span12 reg-div'),
'required' => FALSE,
'after' => '<span class="hidden show-pass-err show-err">Re-password is incorrect</span>'
));
echo $this->Form->input('firstname', array(
'class' => 'reg-input',
'label' => array('text' => 'Name:', 'class' => 'reg-label main-color'),
'div' => array('class' => 'span12 reg-div'),
'required' => FALSE,
'after' => '<span class="hidden show-firstname-err show-err">This field must not empty</span>'
));
echo $this->Form->input('lastname', array(
'class' => 'reg-input',
'label' => array('text' => 'Last Name:', 'class' => 'reg-label main-color'),
'div' => array('class' => 'span12 reg-div'),
'required' => FALSE,
'after' => '<span class="hidden show-lastname-err show-err">This field must not empty</span>'
));
?>
<?php echo $this->Form->end(array('label' => 'Register', 'div' => false, 'id' => 'RegSubmit', 'class' => 'btn-sign pull-right')); ?>
</div>
This is the javascript:
(function($){
/** $(document).ready(function(){}) */
$(function(){
console.log('cover');
/*
$('#btn-reg').on('click', function(){
$('#RegisterUsername').val($('#LoginUsername').val());
$('.reg-form').removeClass('hidden');
});
*/
$('#RegSubmit').on('click', function(e) {
//console.log(e);
if($('.show-user-err').attr('class').indexOf('hidden') < 0)
$('.show-user-err').addClass('hidden');
var username = $('#RegisterUsername').val(),
re_username = $('#RegisterConfirmUsername').val(),
password = $('#RegisterPassword').val(),
re_password = $('#RegisterConfirmPassword').val(),
firstname = $('#RegisterFirstname').val(),
lastname = $('#RegisterLastname').val();
var check = 0;
var email_regex = /^([a-z0-9_\.-]+)#([\da-z\.-]+)\.([a-z\.]{2,6})$/;
$.each(user_emails, function(index, value){
if(value==username){
check = 1;
}
});
if(check == 1){
$('.show-err').addClass('hidden');
$('.show-email-err').removeClass('hidden');
return false;
}
if(!email_regex.test(username) || username == '') {
$('.show-err').addClass('hidden');
$('.show-emailvalid-err').removeClass('hidden');
return false;
}
if(username != re_username){
$('.show-err').addClass('hidden');
$('.show-user-err').removeClass('hidden');
return false;
}
if(password.length < 6){
$('.show-err').addClass('hidden');
$('.show-pass-long').removeClass('hidden');
return false;
}
if(password != re_password){
$('.show-err').addClass('hidden');
$('.show-pass-err').removeClass('hidden');
return false;
}
if(firstname == ''){
$('.show-err').addClass('hidden');
$('.show-firstname-err').removeClass('hidden');
return false;
}
if(lastname == ''){
$('.show-err').addClass('hidden');
$('.show-lastname-err').removeClass('hidden');
return false;
}
});
});
})(jQuery);
I'd guess that one of the other classes like show-err has display:block and that's overriding the hidden class. If you inspect the element in either Chrome or Firefox then it should show you the CSS rules that are being applied.