This is part of code I have problem with
if(user_is_logged_in())
{
$cover='<form method="post">
<input type="text" name="tekst" /><input type="submit" id="add" value="Dodaj adres okładki" />
</form></td></tr>';
}
else
{
$cover=" ";
}
$description .= '<tr><td width="60px">Title</td><td>'.$this->getTytul().'</td><td rowspan="20" width="150px">'.$cover.'</td></tr>';
and I have to run that query when user click submit button
db_query("INSERT INTO okladki_publikacji(id_publikacji,adres_okladki) VALUES(".$this->getId().",".$value_from_form.")");
but I have no idea how to do it in drupal
What I want is run function with that query on action in form but how? action =add_cover() doesnt work
Drupal has an amazing forms API that can help you doing this kind of stuff in a breeze.
Basically you define a form using this API and then define the function to be invoked once the user submits it and that's it. Here's an example on how to define the form:
function myformname_form($form, &$form_state){
// define the input field
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Dodaj adres okładki'),
);
// define the submit button
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Apply'),
);
return $form;
}
Then you define the function that will be executed once the form is executed. Function basically has to be named the same + "_submit" - Drupal will do the magic behind the scenes to tie it together.
function myformname_form_submit($form, &$form_state){
// and this will be where you execute the query you wanted.
}
Would recommend installing Devel module so you can inspect the form_state variable - that's where the input field value will be.
Now, you can just render the form on your code below using drupal_get_form like this:
$cover = " ";
if(user_is_logged_in()) {
$form = drupal_get_form('myformname_form');
$cover = render($form);
}
$description .= '<tr><td width="60px">Title</td><td>'.$this->getTytul().'</td><td rowspan="20" width="150px">'.$cover.'</td></tr>';
Hope this helps!
Related
I tried to edit the data form but the submit button doesn't work like it doesn't have a function. In that form I also added 1 more form which was wrapped in a modal
code of view:
code of controller:
public function update(Request $request)
{
$items = Arsip::where('field_id', Auth::user()->employee->field_id)->get();
$request->validate([
'indikator'=>'required',
]);
$i = $request->indikator;
foreach($i as $row) {
$i = indicator::find($row['id']);
$i->arsip_id = $row['arsip_id'];
$i->nama_indikator = $row['nama_indikator'];
$i->nilai_indikator = $row['nilai_indikator'];
$i->save();
}
return view('admin.approve.index', compact('items'))->with('success', 'update data successfully.');
}
Don't use images in questions
You're not very clear on what is or isn't working. It feels like your form action isn't correct. $items, seeing your code snippet` is a collection and not a single model, which would mean the route wouldn't be correct.
I would suggest using named arguments when building a route: route('arsip.update', ['id' => $item->id])
Also, you're nesting a form inside a form. This is not allowed within HTML, and there is no good reason for wanting to do this. I see that this is a delete button. You can hide a form somewhere else and use javascript or a button (outside a form) with a form attribute to submit the form. See this thread's answers for this approach.
What I'm looking for exactly is a button that says something like, "Report a typo," and notifies me when somebody clicks that button on that page.
To clarify, I've got a big writing project with many short pages -- a couple paragraphs in an html template each, which I know could be done much more concisely, but that's another matter. It would help me if, when reading through, I could just click a button every time I (or whoever is reading) see something screwy, then get a message saying on which page the button was clicked without having to send an email. I'm fine with an automatic message to my email (even just as simple as the page name, like 'example.html' in the body), but I don't want to have to open my email client, etc. Honestly, any way I can get notification is fine (can html5 send carrier pigeons?), as long as the user interaction remains minimal. Is there a relatively simple way to do this? I'm happy to learn, but not exactly an expert as it stands.
I apologize in advance if I was unclear, if this has been asked before (I couldn't really think of how to search for what I'm asking), or if the answer is ridiculously simple and I'm just completely missing it. I'm kind of a noob at all this, so I appreciate any patience if this isn't an ideal question, but I'll try to update with suggested fixes. Thanks!
if ($this->form_validation->run() == FALSE) {
$this->load->view('welcome_message');
} else {
$this->load->view('formsuccess');
$name = $this->input->post('name');
$email = $this->input->post('email');
$cell = $this->input->post('cell');
$msg = $this->input->post('msg');
// $captcha=$this->input->post('captcha');
// echo $this->session->flashdata('email_sent');
$data = array('name' => $name, 'email' => $email, 'cell' => $cell, 'msg' => $msg);
$this->load->model('mymodel');
if ($this->mymodel->add($data)) {
$this->load->library('email');
//SMTP & mail configuration
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'consecutive.development#gmail.com',
'smtp_pass' => 'devAccountCB!',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
//Email content
$subject = 'Call Back Request';
$message = $this->input->post('msg');
$name = $this->input->post('name');
$from = $this->input->post('email');
$to = 'consecutive.development#gmail.com';
$this->email->from($from, $name);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message("From : " . $from . " <br> Message: " . $message . "<br>Phone Number:" . $cell);
if ($this->email->send()) {
$this->mymodel->add($data);
$this->session->set_flashdata('success_msg', 'Message sent successfully');
//$success= $this->session->set_flashdata('success_msg');
} else {
$this->session->set_flashdata('error_msg', 'Error sending message!');
//redirect('Welcome/index');
// show_error($this->email->print_debugger());
}
echo '<script>alert("Your Message has been sent. Thankyou!");</script>';
redirect('');
It is impossible to do that in Html5 , however it can be done using Jquery or php, as you may need some backend site scripting language.
I've created a page where I have two input textareas and I add CKeditor (ver. 4) to both of them.
The first editor works fine, I've set config.allowedContent = true; in the config.js to stop stripping tags like <script> and everything works as expected.
I have another editor right below it, same settings, same setup, I just changed the ID of the textarea field. It works when I submit normal text, but as soon as I add a <script> tag, for example, and press the submit button of the form in which the editors are in it seems to reload the page, doesn't submit any data and firebug tells me that the server returns 403.
I tried isolating the editor, adding personal configuration. Nothing. The first textarea works like a charm, second one returns 403 if the text has unsafe tags in it.
My setup is as follows, I'm using this ckeditor helper to insert the editors where I need. Page is created with CodeIgniter as you guessed.
I got a config.js file in ckeditor folder.
I'm using a regular form, nothing fancy about it. It looks like this
<form action="http://domain.com/admin/articles/edit/47" method="post">
<div id="cke_ckeditor_en_container">
<textarea cols="75" rows="7" id="ckeditor_en" name="text_en" class="input-text is-col-text"><?php echo set_value('text_en', isset($text_en) ? htmlspecialchars_decode($text_en) : ''); ?></textarea>
<?php echo display_ckeditor($ckeditor_en); ?>
</div>
<input type="submit" value="submit" />
</form>
The form has another part of html for the other editor which is the same, with changed id and other attributes, and a checkbox, nothing relevant.
And got this in my controller
public function edit(){
$this->load->helper('ckeditor');
$id = (int)$this->uri->segment(4);
if (empty($id)){
$this->session->set_flashdata('error', 'Empty ID!');
redirect('admin/articles');
}
$data = $this->articles_model->fetch_article($id);
$data['page_title'] = "Edit `" . $data['title'] . "`";
$data['form_url'] = "admin/articles/edit/" . $id;
$data['ckeditor'] = array(
'id' => 'ckeditor',
'path' => 'js/ckeditor');
$data['ckeditor_en'] = array(
'id' => 'ckeditor_en',
'path' => 'js/ckeditor');
$data['edit'] = true;
if($this->input->post('submit')){
$this->save_article("update",$id);
}
$this->load->view("admin/articles",$data);
}
private function save_article($type='insert', $id=0){
$this->load->library('form_validation');
$this->form_validation->set_rules('title','Title','trim|xss_clean|max_length[150]|min_length[1]');
$this->form_validation->set_rules('text','Text','trim');
$this->form_validation->set_rules('title_en','Title EN','trim|xss_clean|max_length[150]|min_length[1]');
$this->form_validation->set_rules('text_en','Text EN','trim');
$this->form_validation->set_rules('top_menu','Show in top menu','trim|xss_clean|max_length[1]');
if ($this->form_validation->run() === FALSE)
{
return FALSE;
}
// make sure we only pass in the fields we want
$data = array();
$data['title'] = $this->input->post('title');
$data['text'] = htmlspecialchars($this->input->post('text'));
$data['title_en'] = $this->input->post('title_en');
$data['text_en'] = htmlspecialchars($this->input->post('text_en'));
$data['url'] = $this->toAscii($this->input->post('title'));
$data['url_en'] = $this->toAscii($this->input->post('title_en'));
$data['top_menu'] = $this->input->post('top_menu');
if($type == "insert"){
$data['time'] = date("YmdHis");
}
if ($type == 'insert'){
if($this->articles_model->insert($data)){
$this->session->set_flashdata('success', 'Article added successfully!');
}else{
$this->session->set_flashdata('error', 'An error occured!');
}
}else if ($type == 'update'){
if($this->articles_model->update($id, $data)){
$this->session->set_flashdata('success', 'Article `' . $data['title'] . '` edited successfully!');
}else{
$this->session->set_flashdata('error', 'An error ecc!');
}
}
redirect("admin/articles");
}
Safety, or unsafeness, to be exact, of my code is not relevant
edit
Adding config.js for ckeditor.
CKEDITOR.editorConfig = function( config ) {
config.filebrowserBrowseUrl = '/js/kcfinder/browse.php?type=files';
config.filebrowserImageBrowseUrl = '/js/kcfinder/browse.php?type=images';
config.filebrowserFlashBrowseUrl = '/js/kcfinder/browse.php?type=flash';
config.filebrowserUploadUrl = '/js/kcfinder/upload.php?type=files';
config.filebrowserImageUploadUrl = '/js/kcfinder/upload.php?type=images';
config.filebrowserFlashUploadUrl = '/js/kcfinder/upload.php?type=flash';
config.removeButtons = 'Underline,Subscript,Superscript';
config.allowedContent = true;
// Se the most common block elements.
config.format_tags = 'p;h1;h2;h3;pre';
// Make dialogs simpler.
config.removeDialogTabs = 'image:advanced;link:advanced';
};
I'm stumped and stupified, I've got no ideas on what to do. It seems that the one input has been cursed.
Any help appreciated, thank you.
This would be the result of your mod_security rules. Depending on how strict they are they help better protect scripts from being hacked through vulnerabilities, generally those exploited via POST's.
As I understand you are trying to add something to your second textarea. And CKEditor removing some "unsafe" tags. I won't be very secure, but this can help you:
config.extraAllowedContent = '*{*}';
You will add this to your config.js. This code provides you to add anything you want. And CKEditor won't delete "unsafe" tags.
Documenation for this method
https://www.bilisimkitabi.com/403-error-on-submit-of-ckeditor
You can add to following code in your .htaccess file
#ckeditor Post 403 problem
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
#ckeditor Post 403 problem
I have created a custom widget in my themes plugin directory and it seems to be working as expected but when I register a second custom widget the 1st one seems to get overridden and I no longer have access to it. Below is my code for the widgets:
add_action( 'widgets_init', create_function( '', 'register_widget( "staffWidget" );' ) );
class staffWidget extends WP_Widget{
function staffWidget() {
parent::WP_Widget(true, 'Staff');
}
function widget($args, $instance){
echo "test widget";
}
function update($new_instance, $old_instance){
return $new_instance;
}
function form($instance){
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
if($instance['title']){
$title = $instance['title'];
}
else{
$title = "Add title here";
}
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
<?php
}
}
Both widgets have this kind of code structure but with different class names and both widgets have been activated in the plugins section of the WP dashboard. Any help or suggestions would be very much appreciated. Thanks in advance :)
You are calling the class WP_Widget with the wrong parameters.
/**
* PHP5 constructor
*
* #param string $id_base Optional Base ID for the widget, lower case,
* if left empty a portion of the widget's class name will be used. Has to be unique.
* #param string $name Name for the widget displayed on the configuration page.
* #param array $widget_options Optional Passed to wp_register_sidebar_widget()
* - description: shown on the configuration page
* - classname
* #param array $control_options Optional Passed to wp_register_widget_control()
* - width: required if more than 250px
* - height: currently not used but may be needed in the future
*/
function __construct( $id_base = false, $name, $widget_options = array(), $control_options = array() ) {
If you put false (default value) or a string, it'll work. So, supposing we have a widget Staff and another Stuff, this would do:
parent::WP_Widget('staff', 'Staff', array(), array() );
parent::WP_Widget('stuff', 'Stuff', array(), array() );
Your code is using attribute_escape, which is deprecated. If you enable WP_DEBUG, you'll see the warning. Anyway, it's a good practice to develop always with it turned on.
All this indicates that you are using a bad source as example. This one is the article about custom widgets.
I'm trying to send a thank you email to the user submitting the form in HTML.
I found out by using a hook in my template.php file like this works to set the header correctly:
function mythemename_webform_mail_headers($form_values, $node, $sid) {
$headers = array(
'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
'X-Mailer' => 'Drupal Webform (PHP/'. phpversion() .')',
);
return $headers;
}
This works freat for the "Thank You" email.
The email that the site admin gets with the form results is also html, but it's not converting newlines to breaks in this email. I can't figure out how to use a hook for this, so I had to edit the webform.module file and do this:
function webform_mail($key, &$message, $params) {
$message['headers'] = array_merge($message['headers'], $params['headers']);
$message['subject'] = $params['subject'];
//$message['body'][] = drupal_wrap_mail($params['message']); // replaced this with line below
$message['body'][] = nl2br(drupal_wrap_mail($params['message']));
}
Can this be done with a hook in template.php?
You can use hook_mail_alter to edit mails created with hook_mail, which is what webform uses.
You can't use hook_mail_alter() in a theme, only in a custom module.
Old topic but still usefull I guess. On the webform module's edit page there is a option/fieldset with additional processing:
<?php
$to = $form_values['submitted_tree']['uw_gegevens']['e_mail'];
$from = "no-reply#example.com";
$achternaam = $form_values['submitted_tree']['uw_gegevens']['uw_naam'];
$message = drupal_mail('webform_extra', 'reply', $to, language_default(), array('body' => $body), $from, TRUE);
function webform_extra_mail($key, &$message, $params) {
$message['subject'] = "TEXT.";
$message['body'] = "
TEXT, " . $params['achternaam'] . "
TEXT.
KIND REGARDS,
TEXT
";
} ?>
Hope this helps
Guus van de Wal