Is Possible to call multiple Php file in singel button click - php

In php, i want call multiple php files in single button click action
just like that
<form action="php1.php , php2.php">
<form>
Is it possible ?? How can i call multiple files

In action attribute can be only one file, but you can use for example include.
<form action="php1.php">...</form>
And php1.php file:
<?php
include 'php2.php';
// process form data

Write whatever would be in php2.php as a function in php1.php and call it when you need.

Related

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 keep Html file and its php file in Codeigniter?

I am very new to PHP , but i want to show a html page and handle it with and .php file in codeigniter, How can i do it.
Example could be like this :
http://www.w3schools.com/php/showphp.asp?filename=demo_form_post
I tried to do the same but in controller if i try to run the html file it works fine but as i click on submit and try to fetch values it give my errors.
i do:
1. Made 2 file in view namely: Test.html and Test_Values.php
in Test.html i keep : the code as mentioned in w3 link
and in Test_Value.php I wrote the logic.
2.In controller i calls : $this->load->view("Test.html");
it shows me my html page but as i click on the submit button it says 404 page not found.
Please help me. What am i doing wrong??
Firstly you will have to put your logic in a function in your controller and not a separate .php file. e.g:
class Yourcontrollername extends CI_Controller{
...
function form_processor(){...}
}
Then You are supposed to give the address and the name of the function which is going to process the form you sumbitted in the action attribute of your form! e.g:
<form action="yourControllerName/form_processor" method="post">
Finally, you really need to have to study the Codeigniter Manual

Pass form values into another php class through javascript

I have a MyAccount page for my website which is going to have a form to allow the users to upload an image.
<from action='javascript:uploadFile'>
<input type='file' name='Upload'>
</form>
What I would like to do is have it call another .php file like:
<script type="text/javascript">
function uploadFile()
{
addPhoto.php giving files $id and Upload (from the form)
}
How can I achieve this without the user actually leaving the MyAccount page?
You can use include or require within a PHP file.
The include statement includes and evaluates the specified file.
You would need AJAX/jQuery to call it through JavaScript.
Documentation

Can the form action attribute call a javascript function in an external javascript file?

I have the form tag written as such:
<form id="form" action="mail.php" method="post"><!--form here--></form>
Currently this poses some problems, so I am switching the form action to an AJAX solution, however, I would like the AJAX function to be in an external JavaScript file. I know that you can link the form action attribute to a file, but how would I tell the form to look at the specific function in the file?
Any help is greatly appreciated!
just include the script file using <script src="file.js" type="text/javascript" /> and call the function in file wherever you want... you don not need to tell the program where to look for function .. all the script code is included within the file with the use of <script>
you can use:
onsubmit="SubmitFormViaAjax();return false;"
This way the form won't submit itslef (return false) and you can use any function in the included form to submit the form's data directly to the recipient via ajax.
Just make sure to include the ajax functions file in the page.

Calling a php function with the help of a button or a click

I have created a class named as "member" and inside the class I have a function named update(). Now I want to call this function when the user clicks 'UPDATE' button.
I know I can do this by simply creating an "UPDATE.php" file.
MY QUESTION IS :-
Can I call the "update() function" directly without creating an extra file? I have already created an object of the same class. I just want to call the update function when the user clicks on update button.
an action.php example:
<?
if (isset($_GET[update])){
$id=new myClass;
$id::update($params);
exit;}
//rest of your code here
?>
Your button is in your view. Your method is in your class . You need a controller sitting in the middle routing the requests. Whether you use 1 file or many files for your requests is up to you. But you'll need a PHP file sitting in the middle to capture the button click (a POST) and then call the method.
As far as I know you can't do this without reloading your page, checking if some set parameters exist which indicate the button is clicked and than execute the button. If this is what you are looking for... yes it is possible on page reload. No as far as I know it is not possible directly because your php-function has to parse the results again.
Remember that a Model-View-Controller way is better and that this will allow you to ajax (or regular) requests to the controller-class.
You do it on the same page and have an if statement which checks for the button submission (not completely event driven) like so
if (isset($_POST['btn_update']))
{
update();
}
<input type="submit" name="btn_update" value="Update" />
That will have to be wrapped in a form.
Or you could do it with AJAX so that a full page refresh isn't necessary. Check out the jQuery website for more details.

Categories