How to submit form in custom wp plugin - wordpress

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

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.

I am developing plugin give following error while activation gives

The plugin generated 2 characters of unexpected output during activation. If you notice “headers already sent” messages, my code is below
<?php
/*
Plugin Name: configuration
Description: example plugin to demonstrate wordpress capatabilities
Author: kailash
License: Public Domain
*/
// run the install scripts upon plugin activation
function test_init() {
if(isset($_POST['save'])) {
$setting=$_POST['setting'];
global $wpdb;
$table_name ="setting";
$wpdb->query("UPDATE $table_name SET setting='$setting' WHERE id=1");
//echo"Setting Saved";
}
?>
<form name="form" id="myform" method="POST">
<input type="radio" name="setting" value="2" <?php if($setting==2){echo 'checked="checked"';}?> id="term"/>newconfiguration<br>
<input type="radio" name="setting" value="1" <?php if($setting==1){echo 'checked="checked"';}?> id="term"/>oldconfiguration<br>
<input type="submit" name="save" value="save">
<?php
}
add_action('admin_menu', 'config_plugin_setup_menu');
function config_plugin_setup_menu(){
add_menu_page( 'Test Plugin Page', 'configuration', 'manage_options', 'config-plugin', 'test_init' );
}
Headers already sent
It is usually because there are spaces, new lines, or other garbage before an opening <?php tag or after a closing ?>
check and remove all unnecessary space. example check before
<form> tag. means after ?> tag there is extra space in your code. so check other too and remove all space..!
Check that the very first characters are
<?php
Check that the very last characters are
?>
for details check this
https://codex.wordpress.org/Answers-Troubleshooting

How to create custom text forms in admin panel and show them on my page (Wordpress)

Introduction:
At this moment I'm creating my first custom Wordpress theme. Now I succesfully created a HTML/CSS template and converted this to fit wordpress (including header.php, index.php, footer.php, functions.php, sidebar.php and page.php).
Case/Problem definition:
At my homepage (index.php), I included several div's filled with text (pure HTML and CSS). Now I want to be able to manually change this text from an admin panel in my Wordpress Back-end. I already made an extra sub-menu page in the admin panel. This page is completely blank at this moment.
In Short:
How to fill in a text form in my Wordpress admin panel and echo this out on a certain page (front-end).
Extra
Since I'm new to Wordpress, PHP and creating your own themes I'm not sure how to do this or how to search for tutorials online (I don't know the correct terminology to search).
Thanks for all the tips and advice already!
In your functions.php add the following code that is highlighted. This will add a twitterid. So anywhere in your custom theme you can call the value of the custom admin page:
add menu item:
add_action('admin_menu', 'add_global_custom_options');
Assign the custom function which will create a form.
function add_global_custom_options()
{
add_options_page('Global Custom Options', 'Global Custom Options', 'manage_options', 'functions','global_custom_options');
}
Create a Function Which Generates the Form:
<?php
function global_custom_options()
{
?>
<div class="wrap">
<h2>Global Custom Options</h2>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options') ?>
<p><strong>Twitter ID:</strong><br />
<input type="text" name="twitterid" size="45" value="<?php echo get_option('twitterid'); ?>" />
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="twitterid" />
</form>
</div>
<?php
}
?>
View your admin page. You will find a new link in your Admin Menu called “Global Custom Options”. Just enter your values in that form and you are good to go for using those values in your theme files like “get_option(‘twitterid’)”. So, in your index.php or any other theme file, you can do something like
<?php echo get_option('twitterid') ?>
and it will print whatever value is in the textbox on admin page.
Here is a link to the tutorial for reference.

Advanced Custom Fields/PHP issue

I apologize if this is answered elsewhere, but I'm having an issue with this ACF code here: http://goo.gl/9onrFN I want the client to be able to add a portfolio site link (if applicable) to the artist page and the link would say "View Artist's Website" and the link would take the user to the artist's site in a new window. How would I go about not making this text not visible, unless there was a url entered into the custom field on the post? Here's the code:
<p><?php the_field('contact_phone_number'); ?><br />
or <?php the_field('contact_email'); ?><br />
View Artist's Website</p>
Thanks in advance!
You can check if a ACF field is set with:
if(get_field('artist_website')) {
the_field('artist_website');
}
Using the_field will simple echo the contents of your field, whereas get_field will return the value which is a lot more helpful. For example you could write the above code as:
Note: get_field simple returns the value of the field, if you want to check if a valid url has been entered you will have to use a regular expression.
Below is your code with an if statement performing an empty field check:
<p>
<?php the_field('contact_phone_number'); ?><br />
or <?php the_field('contact_email'); ?>
<?php if(get_field('artist_website')) { ?>
<br />View Artist's Website
You may find your code easier to read by pre-setting your variables and including HTML in the echo:
<p>
<?php
$contact_phone_number = get_field('contact_phone_number');
$contact_email = get_field('contact_email');
$artist_website = get_field('artist_website');
echo "{$contact_phone_number}<br />";
echo "or <a href='mailto:{$contact_email}'>{$contact_email}</a><br/ >;
if($artist_website) {
echo "View <a href='{$artist_website}' target='_blank'>Artist's website</a>";
}
?>
</p>

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