hook for new page in wordpress? - php

I want to add a new page by my plugin.I tried a lot but failed.
What is the hook for creating a new page?Please help.
function add_new_page(){
.....
}
action('init','add_new_page');

If I understood properly, you want to create a new record in the database that is a page. If indeed this is the case, you need to programatically add a new POST of type PAGE (yeah, it is a bit confusing).
To this, you will setup an associative array with the details of your post and use the wp_save_post function, that is here: http://codex.wordpress.org/Function_Reference/wp_insert_post.
Just remember to check if your page already exists before inserting again, or it will create thousands of pages.

If you know all the tables then just write directly to the database for new page creation.
here is the help link http://codex.wordpress.org/Function_Reference/wp_insert_post

Related

Call a post inside an include ( i think )

I'm trying to learn PHP, and to do so im trying to create a code to register new products, i've made an loggin access where the person to do so needs to be connected, so inside of the cpanel I did differents sections, like add client, add product...
So i did an index in the _cpanel folde where i have my main html and to not repeat the same html i put an include inside this index so i can call others php files inside.
I dont know if its correctly to do like this BUT, as i said Im new at programming..
But everything works pretty good, until i need to call my post in my url..
like.. to add a new product i need to go to :
localhost -> connect... to go to localhost/_cpanel
if i click in add a new produt, i go to localhost/_cpanel/?page=folder/addnewproduct.php
and inside this php file i put a form with an action="?go=addnewproduct"
so, i did everything to put all the info in my db, but when i submit it goes to
localhost/_cpanel/?go=addnewproduct and nothing happens..
i tried to change the action like action="folder/?page=addnewproduct.php&?go=addnewproduct" but it doesnt work either.
BUT i made it works changing to action"folder/addnewproduct.php?go=newproduct
but to do so i need to go to "addnewproduct.php", and this page only is an included page inside my index..
i could call back to the index page after adding a new product, so that it doesnt show this page only, but when posting it loads fast to the page and after than it go back to my _cpanel.
i tried to find solutions but, didnt find... i think its just a problem with the way i put it in my action, maybe theres a way to do it and i dont know it yet.
I don't think I get what you're wanting exactly, but here you go:
If you're trying to redirect the request, you may just use the header function as follows:
header('Location: target/url.php');
If you want to make a external post request with php, you may use curl, as suggested here:
PHP + curl, HTTP POST sample code?

I have a form in drupal 7 how to submit the results to database to create new user

I had a question about a tutorial that I saw on sitepoint.com
http://www.sitepoint.com/building-multi-page-wizard-like-form-drupal/
I've got everything in the custom module and now I need to know how to go about actually creating the user using this form.
There's a multipageform_form1_submit code where it says //Store the values from $finalformvalues in database or file etc
What am I to do to actually create a new user? I'm sure there's a little snippet of code that needs to get added but I have looked and looked and cannot seem to find what I need. Any help would be greatly appreciated. Thanks in advance.
To add a new user, just use the user functions in your hook submit. See this article for code examples.

Dynamically Add Multiple Cgridview on a single Page

I'm trying to figure out how to let the user add any numbers of tables or CGridview on a single page. So right now the page has two gridviews in it which will stay fixed. Now i want to add an add button somwhere, clicking on which will give the user another gridview, and so on.
How should i proceed with this. I mean is there an easy way to do this, without resorting to writing everything from scratch.
What i was thinking was to create a new view file using file_put_contents() or fwrite() dynamically everytime the user wants another table on the page? Now following in my line of thinking from where would i create these dynamically view files.
Should i write the whole code of the view and put it in a string, in the controller, and call file_put_contents() from there.
This would cause another problem as the filter needs a specific ajaxUpdate url like this
'ajaxUrl' => Yii::app()->createUrl('project/AjaxUpdate'),
.
Which would entail i would have also have to dynamically create the actionCode in the project controller for the filter in that dynamic grid to work. eg. project/AjaxUpdateDynamic1, project/AjaxUpdateDynamic2, etc.
So i'm kinda stuck with this problem. I would really appreciate if someone points me in the right direction.
Thanks, in advance,
Maxx
if you had an action for ajax loading your gridviews, you can then set your ajax url to that url and you'd have filtering possible for your model, you can even put multiple gridviews for multiple data providers that can be loaded via a parameter that you have sent along with click of your button and an input.

Send form data to external database in wordpress

My client want to have form collecting the user data and save to external database
that is on different hosting of the wordpress site.
I need to have two forms, one is for contact us purpose and the second for newsletter registering.
Both forms need to collect the data and save it to the database on different tables.
I found plugin that let me make form on wordpress and plugin that let my save the data on the database wordpress use, but this in not what I need.
I found this solution Create a form and save data in a external DB with Wordpress but it do not help me.
I tried to run some PHP code (and learn it this way, because I do not know php) to get the data but I got nothing.
it is possible to do what I am asking?
Is there some plugin to do this?
I do not ask for code, but some help will great.
Thanks
The code in this page helps you create a second database connection, once you connect the second database, you can store data to it using routine WordPress database commands
http://bavotasan.com/2011/access-another-database-in-wordpress/
$newdb = new wpdb($DB_USER, $DB_PASSWORD, $DB_NAME, $DB_HOST);
$newdb->show_errors();
Hope this helps, let me know if there is still an issue.

how can i get data from other browser without refreshing browser in cakephp?

i am new to cakephp, and also new to ajax.
the function i trying to do is basically like this:
i am in a add page, which let me select few customer on that page.
but i wanted to set 1 more link for user, which let user click customer immediately on the add page, and the new data will show in my add page without refresh, so that the user can choose the new added customer for enter my form.
i know the idea is base on using ajax. but i am still new to it and hope any 1 can give some comment or suggestion how can i start??
the problem i face is, i am on a form, when i adding a new customer in the form, i wanted to get the new customer to show in my form without refresh. what can i do for getting this function?
thanks a lot and i will very appreciate your answer.
CakePHP has an ajax helper, which requires the prototype library. You can find the API for the AJAX helper here:
http://api.cakephp.org/class/ajax-helper
And a guide to using the helper here:
http://book.cakephp.org/view/208/AJAX
And a list of cakephp/ajax articles here:
http://bakery.cakephp.org/articles/search/tags/ajax
It's beyond the scope of a Stack Overflow answer to give you a tutorial but hopefully these links will help.
easiest way is to use a javascript library (like jquery for instance) to do an ajax request.
probably to a controller/action in your cake framework.
the easiest way would probably be returning the data in JSON and filling out your form fields.
PHP Json
jQuery AjAX/JSON

Categories