Custom metabox for file upload return empty filename - wordpress

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

Related

How to design a php page theme template in wordpress using either html or css?

<?php
/*
Template Name: isbn
*/
?>
<form action="" method="post" name="myForm">
Filter <input id="isbn" type="text" name="isbn" />
<input type="submit" name="submit" value="Submit" /></form>
<?php get_header(); ?>
<?php
if(isset($_POST['submit']))
{
global $wpdb;
$table_name = "isbn"; // change this to your table name
$field = $_POST['isbn']; // change this to your isbn field $_POST['ISBN'];
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name where isbn = '".$field."'");
foreach ($retrieve_data as $retrieved_data) {
echo $retrieved_data->title;
// echo $retrieved_data->image; // for image
}
}
?>
This is a search form which i want to design. I have created this form in a page template named isbn. But when i am opening that page for editing i am unable to do this. I am using divi theme in wordpress.
So divi theme is not allowing me to edit this page. Due to which this page is looking very bad in look wise.
Can anyone help me for designing this page by giving their codes or simply by giving their suggestions?
I am facing one more problem whenever i am writing css code in above code i am not getting anything. So i am totally blank that how to deal with this
Just create a WordPress page and add shortcode which you added in functions.php before. Don't create template for this page just use your shortcode only.
First, you have to create a page using divi theme, then create shortcode for this form in functions.php and then use this shortcode in your page.
you are inserting the form above the get_header(); function, so it will be outside of the html tag and outside of the body tag. Move it into the body, then it should at least appear on the page, and you'll see what you need to do next.

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

How to submit form in custom wp plugin

I am trying to make a wp plugin to show a list from table,which can be edited and
deleted .
I am succeed in showing a list in plugin.but not getting how to update .
can any one tell me what will be the path in form action,
,and after form get submited where does it goes ie on which page.
on which page should i write update query
You can place all your form handlers on the same page, but be sure to place them before any output. Like this:
<?
if (isset($_POST['my-form-submit'])) : // check if form is submitted
/*
Here goes update process etc
*/
endif;
get_header();
?>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
/* Here come form fields */
<input type="submit" name="my-form-submit" value="Update" />
</form>
<?php
get_footer();
?>

WordPress Search Queries

I have added within my WordPress 3.1 site, the following code at the bottom of my sidebar.php file:
<div id="search_box">
<form id="searchform" action="http://www.service.com/" method="get" role="search">
<input id="s" type="text" name="s" class="search" value="Search site" size="19" maxlength="80" id="white_box" onfocus="if (this.value=='Search site') this.value = ''"/>
<input id="searchsubmit" type="image" class="submit" value="submit" src="<?php bloginfo( 'template_url' ); ?>/images/search_btn.jpg" />
</form>
</div>
As I have coded this search process myself, when I place a some text within my search text box and press the "Search" button, it looks as if, is is calling the page search.php within my theme and displaying the results.
Questions:
1) where/how does it know when I press the "Search" button to go off and call search.php?
2) if possible only, how can I change it to call a different php file instead of the search.php
Thanks.
Use template filter
add_filter( 'template_include', 'template_include', 10 );
and change the template as
function template_include($template)
{
if(your condition here){
$template = get_template_directory().'/your-template.php';
}
return $template;
}
-1. All requests for a WP site go to a single page that routes them based upon specific criteria. Thus when a search is performed it knows that it is a search and directs to the search.php page.
Specifically it goes to index.php that loads wp-blog-header.php.
-2: Everything you need to know should be right here: http://codex.wordpress.org/Creating_a_Search_Page#Using_the_page.php
Wordpress assumes the request is a search if it sees an 's' GET variable.
You can hook into the template_redirect action (in your theme's functions.php file) and load a different template like so:
add_action('template_redirect', 'my_template_select');
function my_template_select() {
if (is_search()) {
load_template(TEMPLATEPATH . '/foobar.php');
exit;
}
}

Resources