Include PHP FORM in SQL Content - php

I Use SQL to store pages of my site & Admin can edit the content of pages
for some pages like enquiry,contact I need to use PHP Forms in Page Content
What I want is page.php?name=contact get data from sql of page name 'contact' which Admin can edit
e.g. Data is:
"Address of Company"
"Use the form below to contact us"
& Below that data I want to include content from contact.php file which include form & all the validation and mail sending function.
Can I use some shortcode or function like wordpress [contact-form] which can be included in sql data so while accessing page.php?name=contact include content from contact.php file below the data of sql.
"Address of Company"
"Use the form below to contact us"
[contact-form]<--- Form from contact.php or enquiry.php included below content
Whats the method to use this type of file include
Thanks

You must do the steps below:
use $name = $_GET['name']; to detect the current page.
Include your PHP file using include($name.'.php');.
Use MySQL functions like mysql_query() to load what is related to your current page and show it in your page. (This should be in contact.php source codes).
Wordpress short-codes are not accessible everywhere ... They work just for Wordpress itself.

Related

Keeping $_POST data after submit while getting rid of index.php in redirected URL

Within a Joomla template, I'm trying to use a form (within a Joomla article to keep the template's layout) and pass the data to a processing php-file (for example to enter this data in a mysql db). No Java.
When I hit submit, I'm losing all POST information before it reaches this processing PHP file. I believe this is because Joomla has index.php entered within any URLs.
I understood that any redirects (eg. htaccess changes), clears my needed POST variables.
How can I click on submit-button, keep the POST variables and send these to the processing PHP-file?
Thanks for any help..!
I tried changing the Joomla based URL Rewriting option, but this messes up all my other URLS.
I tried the webhost redirecting tool - this works but kills all data
I tried htaccess changes, but this doesn't seem to have any effect..plus this would also kill the POST variables
I tried relative pathing, doesn't work because of the index.php mixing in anyway.
In my form-file (the actual Joomla article in the template)
´´´´
<form action="process.php" method="POST" />
<input type="submit" value="Submit" />
</ form>
´´´´
The form.php file is located in the same folder as the process.php folder.
The form-php contents' URL has also the index.php, but is functional.
In the processing code I have this:
´´´´´´´´´´
$table = $_POST['formID'];
echo ($table);
$keys = implode(", ", (array_keys($_POST)));
$values = implode("', '", (array_values($_POST)));
´´´´´´´´´´
but the $table is simply empty, due to this index.php part I can't get rid of, I believe.
All this code is in a remote folder following the classical joomla folder structure for modules, so /modules/mod_xyz/tmpl/process.php
Is there a way to properly target the form action so that the index.php is not getting mixed in in any files in the above-mentioned folder? I'd like to keep the index.php in all other links, as they work, and also, I'd like to understand why this isn't working?
Thanks a lot again
Idea is just to be able to click on the submit on the form, so that it POST data can be used in the process.php file (=entering data in the mysql database).
This question can be considered closed.

Different between actions

I want to know different between <form action="#" method="post"> and <form action="name of file" method="post">
I am always using # but don't know disadvantages.
Can you explain why I should use # or file name?
Thanks
form action = file name
It is used to send a request on the other page(i.e your file name) containing your form fields(inputs) with methods like GET and POST.
example my HTML page is having a form then and my PHP page is having all the backend code. Whatever I need to do with form inputs. I will give the file name of my PHP page in action. the action attribute of the form is used to send the form request to the destination we want to with methods like the POST and GET. If you do not want to send a request to another Page and want it to your default page. You can leave action ='' attribute of the form empty as I did.
An action of # indicates that the form stays on the same page, simply suffixing the URL with a #. A similar use occurs in anchors. Link for example, will stay on the same page.
Thus, the form is submitted to the same page, which then processes the data etc
The content of action allows you to know where you will put the code that will process the request.
If you put the name of a file it, then his file will process the request.
For example: you have your form on the index.php page and you want to put the PHP code of the form in a process.php file. You will put process.php in action (action="process.php").
If you do not put anything it is like sending the content of the request to the same file (index.php).

How to embed codeigniter script into external php script

l have a index file of my website in
localhost-->mywebsite-->index.php (this is my external script)
and i have build a registration form with codeigniter.
I can use the registration form using url http://localhost/codeigniter/index.php/form.
But how can i attach that registration form into my website index file.
using include_once"../codeigniter/index.php/form"; in my external php script(index.php of my website) is not working.
However if i make that 'form' the default controller file and use the following code from external php script
include_once "codeigniter/index.php"; it works well. but what if i need other controller files but not just 'form'?
Update:
I can also link to that file from external php script as:
<a href="codeigniter/index.php/form>Register</a>.
But not include. Whenever i include it displays no such file.
So if i understood you correctly you want to use codeigniter's form in some other php website, actually idea to do such thing is wrong (as you can't normally control your form action link etc better to build same for in other website directly), but answer for your question is following trick
Place this code in your other website where you want to have codeigniter form included
$output = shell_exec('php ABSOLUTE_PATH/codeigniter/index.php form index');
// where "ABSOLUTE_PATH" is absolute path to your codeigniter project
// "form" is your controller name
// "index" action name
echo $output; // will echo form html generated by codeigniter
In localhost-->mywebsite-->index.php, you could try this:
<?php include_once('/codeigniter/index.php/form'); ?>
If not you can move your index.php code into a codeigniter view and set it up that way.
try using below code...
<?php $data = file_get_contents("http://localhost/codeigniter/index.php/form/");
$html_encoded = htmlentities($data);
echo $html_encoded;
?>
In the above code we get all contents of the url in $data variable and then use htmlentities on that for html encoding...

Magento redirect to the page from that came

I have a module which had instaled a CMS page with some default URL and some text with form. On this form I have fields and submit. I validate my fields using ajax(send POST in controller of my module). If validation is OK, I redirect to the same page with "succes message".
The problem is, that the default URL of this CMS page in which I make redirect after succes submit can be changed in BO - that's why I cannot just $this->_redirect('default_URL') in my controller, because this url can be changed.
What should I do?
EDIT : Solution: use $this->_redirectReferer() in my controller after success validation
Try to put "back URL" to your form as a hidden field or you can use $this->_redirectReferer() to redirect back to CMS page.
See http://docs.magentocommerce.com/Mage_Core/Mage_Core_Controller_Varien_Action.html#method_redirectReferer
If you want to redirect to some certain CMS page (not the one where form is placed) you can do this:
Add dropdown to system configuration to be able to select "Success page" (much better than hardcode cms page ID)
Redirect to this page in your controller
Code:
$pageId = Mage::getStoreConfig('mymodule/config/success_page');
$page = Mage::getModel('cms/page')->load($pageId);
$this->_redirect($page->getUrlKey());
You can get a store config by using the getStoreConfig method, something like
Mage::getStoreConfig('helloworld_options/messages/hello_message');
See Alan's blog, about detailed instructions how to create custom config values (which you might already have) and to access them.
Use this code for redirect to referer
<?php Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());?>
For example in custom login form:
<form method="post" action="<?php echo Mage::helper('customer')->getLoginPostUrl() ?>">
<?php Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());?>
...
...

How to change the page language without refresh in MVC model?

In the settings.php i have some input for the realname,hobby,city and select tag for the languages
The html form is easy and i'm not going to copy it :)
This is the php code for the form
<?php
if(isset($_POST['submit'])){
if($this->edit->process()){
$s = 1;
}
}
if($s){echo '<p id="success">Success</p>';}
?>
This is in the view file and when the form is submit the $this->edit = the model for the updating the user data.
Everything work really good but in head.php there is this code
<?php $lang = $this->lange('global',$this->getUser->language($_SESSION['userID']));?>
With him this get the user current language and after that load the file with lange()
So if the submit is like this,the inputs and select tag are changing with what the user have choicen but the to see the new language they have to refresh the page. This is not good,because the user may be confuced that they did something wrong.
But if the form with method="POST" the page is refreshing and still with the old language
It is going to be quite hard to change all the texts in the DOM model to make the language change without redirect. I doubt it's really your desire.
You ought to make a GET method redirect after processing any POST form. So, instead of printing whatever "success" messages you have to reload the page.
Using session to store the language is not good method, the language have to be set by means of the page address - a subdomain (preferable) or a virtual directory.

Categories