I have created menu for my plugin page like follow..
function createMenu() {
add_menu_page('Configuration Contact Page', 'Conatct US Setting', 'manage_options', 'adminmenu', 'welcome');
add_submenu_page("adminmenu","Form Setting", "Form Setting", "manage_options", 'formbuilder', 'formbuilder');
}
now my question is how can render form.php when I click on Form Setting page. in form.php I have html code.
my function is
function formbuilder() {
//how to render form.php here
}
thanks in advance
You can include file into your function
function formbuilder() {
// to render form.php here
include('form.php');
}
Basically, you just echo your content
function formbuilder()
{
echo '<form>hello, I am a form</form>';
}
Use locate_template function to find out where the needed template is, then include it.
function formbuilder()
{
include locate_template('form.php');
}
Related
For a better organization of my theme's functions.php, i would like to know if it's possible to add multiples functions with add_action on customize_register ? Like this for exemple :
function banana_customize($wp_customize) {
///// Content of function }
add_action('customize_register','banana_customize')
function coconut_customize($wp_customize) {
///// Content of function }
add_action('customize_register','coconut_customize')
If i do this, i have an error and page won't load.
If this is not possible, could you tell me how to combine functions like so :
function banana_customize($wp_customize) {
///// Content of function }
function coconut_customize($wp_customize) {
///// Content of function }
" function combined_functions = banana_customize + coconut_customize "
add_action('customize_register','combined_functions')
Thanks in advance :)
You can hook functions into the site footer using the following:
function to_footer() {
$content = 'I am in the footer';
echo $content;
}
add_action('wp_footer', 'to_footer');
But is there a similar approach to add a function inside the post's footer (not site footer) in single page views?
The closest you can get (without changing template files) is this
function to_footer($content)
{
return $content . 'I am in the footer';
}
add_action('the_content', 'to_footer');
This will add your thing after post content
If you do not mind editing your templates, try the following
function alt_footer()
{
do_action('alt_footer');
}
in functions.php of your theme. Then call alt_footer() in your template where you need it, then
function to_footer()
{
echo 'I am in the footer';
}
add_action('alt_footer', 'to_footer');
I'm seeing a lot of guides on how to add more classes to a Wordpress body tag, but is there a way to remove all classes from a specific page template, more specifically the search page?
Here's where I'm at so far.. not much sorry.
add_filter('body_class', 'remove_search_class');
function remove_search_class($classes){
global $post;
if(is_search()) {
// find ".search & .search-results"
}
return // no classes within <body>
}
add_filter('body_class','alter_search_classes');
function alter_search_classes($classes) {
if(is_search()){
return array();
} else {
return $classes;
}
}
try adding this in your functions.php
I am a newbie to Codeigniter. As part of studying it, I created a form which inserts data to the database. After insertion it is not redirecting properly to the form view page (formvalidation.php).
Form Action
public function submitform()
{
$formdata['username']=$this->input->post('username');
$formdata['address']=$this->input->post('address');
$formdata['state']=$this->input->post('state');
$formdata['country']=$this->input->post('country');
$data['state']=$this->getstatearray();
$data['country']=$this->getcountries();
if($this->userprofile_model->setdata($formdata)=='success')
{
$this->load->view('formvalidation/formvalidation',$data);
}
else
{
$this->load->view('formvalidation/formvalidation',$data);
}
}
Form view page (formvalidation.php)
echo form_open('formvalidation/submitform');
echo form_input('username');
echo "<br>".form_textarea("address");
echo "<br>".form_dropdown('state',$state);
echo "<br>";
echo form_dropdown('country',$country);
echo "<br><br>".form_submit('submit','Submit');
echo form_close();
Model (userprofile_model.php)
class userprofile_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function setdata($data)
{
$this->db->insert('userprofile',$data);
if($this->db->affected_rows()>0)
{
echo "success";
}
else
{
echo "fail";
}
}
}
Now the value is getting inserted into the database. But after insertion I want to redirect it to the url http://www.example.com/codeigniter/index.php/formvalidation/. But instead, it is now redirecting to http://www.example.com/codeigniter/index.php/formvalidation/submitform where submitform is the form action method.
How can I solve this problem? I tried with putting exit; after the page redirect function. But it won't work. Please help me to fix this.
Thanks in advance.
yes it will, because there is no redirect code. When the form is submitted your submitform function is executed and in that function you are loading the view. So if you want to redirect
to something else you must use the redirect() function.
public function submitform()
{
$formdata['username']=$this->input->post('username');
$formdata['address']=$this->input->post('address');
$formdata['state']=$this->input->post('state');
$formdata['country']=$this->input->post('country');
$data['state']=$this->getstatearray();
$data['country']=$this->getcountries();
if($this->userprofile_model->setdata($formdata)=='success'){
redirect("Your URL");
}
else{
redirect("Your URL");
}
}
Also you must properly sanitize the user input. You must validate your form inputs before passing it to model. You can find more info here
First Load the view page in controller index function.
function index()
{
$this->load->view('v_bank_master');
}
Then in model page, after insertion done. give the below code.
redirect('give your controller page name here','refresh');
Your page will now redirect to the view page after insertion.
Hope it will help you...
I use redirect('yourControllerName', 'refresh').
Read more here: Redirect()
After insertion give the below code
redirect('controller_name/function_name');
I have a PHP stuff that uses call_user_func to create element/objects to a certain function where it was place.
Example functions.php File:
function head($args=null){
echo $args;
}
function footer($args=null){
echo $args;
}
function createHeadTexts(){
echo 'This is header area';
}
function createFooterTexts(){
echo 'This is footer area';
}
//function to call this elements
function addParam($arg, $val){
call_user_func($arg, call_user_func($val));
}
Example index.php file:
head()
This is contents area...
footer()
Back to my functions.php file, I have added a call to function which is
addParam('head','createHeadTexts')//which is I thought has to be added on a header area.
addParam('footer','createHeadTexts')//which is I thought has to be added on a footer area too.
But I came to an issue when I tried to view my PHP page.
it looks like this :
This is header area This is footer area
This is contents area...
I thought the texts should be display like this:
This is header area
This is contents area...
This is footer area
The only functions should be place to my index.php file is head() and footer().
The head() should be appear before the web contents, and footer() should be appear after the contents.
If I would like to create an element/objects/scripts to head() it should be addParam('head','function to create element/object/scripts');
Please help me how to fix this or is there any other way to use aside call_user_func?
Thanks,
I just tested this and it came out allright:
<?php
function head($args=null){
echo $args;
}
function footer($args=null){
echo $args;
}
function createHeadTexts(){
echo 'This is header area';
}
function createFooterTexts(){
echo 'This is footer area';
}
// function to call this elements
function addParam($arg, $val){
call_user_func($arg, call_user_func($val));
}
addParam('head','createHeadTexts');
echo '<br />This is contents area...<br />';
addParam('footer','createFooterTexts');
?>
And the output:
This is header area
This is contents area...
This is footer area
Maybe you forgot to change some arguments? The only thing I changed was
addParam('footer','createHeadTexts') to addParam('footer','create FOOTER Texts')