Form Block - add help text to form input - concrete5

I'm trying to add a 'help text' to the questions added by the Form block.
Something like this but on the front-end part of the form.
For some reason its not saving the value or getting the value into the edit form. Even when I add it manually to the row it is not in the frontend output.
I made a custom form block / template with the additional changes to:
An extra table column 'helptext' in the db.xml. And updated the block.
<table name="btFormQuestions">
...
<field name="helptext" type="text">
<default value=""/>
</field>
...
</table>
An extra field on the editing form (normal and edit):
<div class="form-group">
<?php echo $form->label('helptext', t('Help Text'))?>
<?php echo $form->text('helptext', array('maxlength' => '255'))?>
</div>
Output it In the view.php
use \Application\Block\Form\MiniSurvey;
...
<?php echo $question['helptext']; ?>
Added the extra code to auto.js,
addQuestion:
postStr += '&helptext=' + encodeURIComponent($('#helptext' + mode).val());
...
reloadQuestion:
$('#helptextEdit').val(jsonObj.helptext);
...
resetQuestion:
$('#helptext').val('');
mini-survey.php,
$dataValues = array(
intval($values['qsID']),
trim($values['question']),
trim($values['helptext']),
$values['inputType'],
$values['options'],
intval($values['position']),
$width,
$height,
intval($values['required']),
$values['defaultDate'],
intval($values['msqID']),
);
$sql = 'UPDATE btFormQuestions SET questionSetId=?, question=?, helptext=?, inputType=?, options=?, position=?, width=?, height=?, required=?, defaultDate=? WHERE msqID=? AND bID=0';
} else {
if (!isset($values['position'])) {
$values['position'] = 1000;
}
if (!intval($values['msqID'])) {
$values['msqID'] = intval($this->db->fetchColumn("SELECT MAX(msqID) FROM btFormQuestions") + 1);
}
$dataValues = array(
$values['msqID'],
intval($values['qsID']),
trim($values['question']),
trim($values['helptext']),
$values['inputType'],
$values['options'],
intval($values['position']),
intval($values['width']),
intval($values['height']),
intval($values['required']),
$values['defaultDate'],
);
$sql = 'INSERT INTO btFormQuestions (msqID,questionSetId,question,helptext,inputType,options,position,width,height,required,defaultDate) VALUES (?,?,?,?,?,?,?,?,?,?,?)';
}
$result = $this->db->executeQuery($sql, $dataValues);
Cleared cache and updated the block.
Forum Post on Concrete5 with the changes
Solved:
Got this working on a clean install of C5.
Small changes:
Added the original files form the concrete/blocks/form to the application folder (and changed the namespace)
db.xml (longtext was unnecessary)
<field name="helptext" type="text" size="65535"></field>
auto.js (Semicolon ; missing in the original concrete/block/form/auto.js (and thus the copy in application))
reloadQuestion:
$('#editQuestionForm').css('display', 'block');

Related

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);

Wordpress Contact form 7, fields in template.php - not validating correctly

I need to generate CF7 fields from php to make the form dynamic.
So instead of writing <div>[text* your-name]</div> and so on directly in wordpress, I have a template file that does that instead. The problem is that when doing so, the validation is not working. The fields are displayed correctly, but no fields are checked when submitting. If submitting, the data is however saved correctly.
WP ADMIN form tab:
[my_cf_template]
template.php
<?php echo do_shortcode(apply_filters("the_content", '[contact-form-7 id="115" title="Ruumide rent - booking"]')); ?>
functions.php
function cf_template_func(){
$email = wpcf7_do_shortcode('[email* your-email]');
$submit = wpcf7_do_shortcode( '[submit "Send"]' );
$str = <<<HTML
<div class="detailed-info">
<label> Your E-mail*
$email </label>
</div>
$submit
HTML;
return $str;
}
add_action( 'wpcf7_init', 'custom_add_shortcode');
function custom_add_shortcode() {
wpcf7_add_shortcode( 'my_cf_template', 'cf_template_func');
}

Wordpress outer shortcode parsing html tag of inner shortcode's content

I'm going to write some example code, so it's a shortened example of the issue I'm experiencing.
Let's say I have the following text stored in the database:
[form]
<ul>
[each name="upgrades"]
<li><input type="checkbox" [value name="upgrade_name" id="1"] />[value name="upgrade_name" id="2"]</li>
[/each]
</ul>
[/form]
If I run do_shortcode on this text, the shortcodes INSIDE html tags INSIDE the each content is parsed instead of being deferred to the each shortcode. However, shortcodes that are not in html tags in the each content are not parsed until the each shortcode runs do_shortcode on it's content, which should be the correct behavior.
In otherwords, the value shortcode with id 1 is parsed too soon (on the form shortcode pass), but the value shortcode with id 2 is not parsed until the each shortcode runs do_shortcode on it, so it produces the correct value.
I know I can set the ignore_html flag on the form shortcode to true, but that is incorrect as a user may want to have html tags parsed for shortcodes.
Is there a workaround for this behavior?
Wordpress version 4.6.1
EDIT: Adding reproducible code
Create a new plugin with this code:
<?php
/*
Plugin Name: Broken Shortcodes
Description: Shortcodes should not jump the gun in parsing html tag shortcodes of inner shortcode content.
*/
remove_filter('the_content', 'wpautop');
add_shortcode('form', function($atts, $content){
echo "<textarea>This is the form's content:\n".$content.'</textarea>';
return "<textarea>This is the rendered form shortcode:\n".do_shortcode($content).'</textarea>';
});
$bad_global_variable = 'first';
add_shortcode('value', function($atts, $content){
global $bad_global_variable;
return $bad_global_variable;
});
add_shortcode('each', function($atts, $content){
global $bad_global_variable;
$_content = '';
foreach(array('second', 'third', 'fourth') as $v){
$bad_global_variable = $v;
$_content .= do_shortcode($content);
}
return $_content;
});
?>
Create a page with this text:
[form]
[each]
<div [value]>[value]</div>
[/each]
[/form]
The output is incorrect:
<div first>second</div>
<div first>third</div>
<div first>second</div>
<div first>fourth</div>
<div first>second</div>
<div first>third</div>
<div first>second</div>
A quick workaround is to parse your own shortcodes out of html tags.
So you text would look like:
[form]
[each]
<!-- Notice curly brackets -->
<div {value}>[value]</div>
[/each]
[/form]
Then your each shortcode might look like this:
add_shortcode('each', function($atts, $content){
global $bad_global_variable;
$content = preg_replace('/\{([^}]+)\}/', '[$1]', $content, -1);
$_content = '';
add_filter( 'wp_kses_allowed_html', 'parse_tags', 10, 2 );
foreach(array('second', 'third', 'fourth') as $v){
$bad_global_variable = $v;
$_content .= do_shortcode($content);
}
remove_filter( 'wp_kses_allowed_html', 'parse_tags', 10, 2 );
return $_content;
});
// This might be necessary depending on your use-case
function parse_tags($tags, $context){
$tags['input']['value'] = true;
return $tags;
}
But, this should not be a solution to something seemingly so simple. I think the Shortcode API needs some TLC.
See ticket here: https://core.trac.wordpress.org/ticket/33134

Custom metabox for file upload return empty filename

I want to attach a file to a post and "do something with it later". The file isn't being pulled over when I publish/update my post, the error I get is an empty filename. If I change the input type to text and submit I can get the text to save/display but trying to upload the file acts as though I haven't supplied the file to the form:
form --
function display_file_upload_meta_box($post_id,$post){
wp_nonce_field( basename( __FILE__ ), 'file_upload_meta_box_nonce' );
?>
<p>
<?php
$fileUpload= get_post_meta($object->ID,'file-upload-meta',true);
if(!$fileUpload)
$fileUpload = '';
echo 'file: '.$fileUpload;
?>
<label for="file_upload_meta">Attach a file to this post</label>
<input type="file" id="file_upload_meta" name="file_upload_meta" class="widefat"/>
</p>
<?php
}
code to upload file --
$new_meta_value = wp_upload_bits($_FILES["file_upload_meta"]['name'], null, file_get_contents($_FILES["file_upload_meta"]['tmp_name']));
It's probably because the form does not have those attributes :
enctype="multipart/form-data" encoding="multipart/form-data"
You can use a hook to add them, check this : https://gist.github.com/rfmeier/3513349
I got a requirement for adding custom meta boxes for a custom post type in wordpress and I tried using the following plugin and got working for me. Try this

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>

Resources