calling a different classes function via a form php - php

We are toying about with the Open Source Flamer app. We noticed that they are able to call a function in a separate class located in a different PHP file via a form POST request. Here is an example of how they do it:
<div id="upldate_location_service" class="div_service">
<form action="process.php/upDetails" method="post">
<h3>Update location :</h3>
<div class="form_row">
<div class="form_label">Session Token *: </div>
<div class="form_field"><input type="text" name="ent_sess_token" />name= "ent_sess_token"</div>
</div>
<div class="form_row">
<div class="form_label"> </div>
<div class="form_field"><input type="submit" name="ent_submit" value="Submit" /></div>
</div>
</form>
</div>
The function they are trying to access is UpdateLocation in the file Process.php. We have tried to recreate this process but it wont work. We can echo outside of our class, but for some reason we cant access or run any content in our process.php function.
Here is a copy of our process document:
class LegitAPI Extends API{
public function upDetails($args)
{
echo "Hello World";
}
}
Theoretically, when submitting the form on the index page, it should load process.php and then the method upDetails in the LegitAPI Class and display hello world. However, a blank page is instead being displayed.
Any ideas?

Related

How do I change a CSS Style attribute once a condition is met? PHP, JS, CSS

Good Day!
I am having a difficulty when it comes to showing a pop-up box in my webpage. I would like to show it when it meets a certain condition inside my php code, which is under the Condition.php. I have included the js file, which removes a certain class to make the box visible. How would I execute the JS code inside the Condition.php when it meets a certain condition?
Here are my codes:
Condition.php
<?php
// Defined variables and additional codes section
if (strlen($str) == 4) {
// Show the popup box
}
// Additional Codes
?>
ConfirmCheck.js
$(document).ready(function () {
$('#confirm').click(function () {
$('.popup').removeClass("hide");
});
});
Check.php
<form class="frm" action="Condition.php" method="POST">
// Additional Codes here
<input type="submit" name="checkOutBtn" value="CONFIRM" id="confirm">
</form>
<?php include 'box.php';?>
<script src='ConfirmCheck.js'></script>
Box.php
<div class="popup hide" id="popupID">
<div class="box">
<div class="form">
<h1>SUCCESS!</h1>
<form action="home.php">
<div class="form-group">
<p class="paragraph">
Your order has been successfully placed!
</p>
<button class="homepageBtn" onclick="home.php">GO TO THE HOME PAGE</button>
</div>
</form>
</div>
</div>
</div>
To do what you require simply put the if condition inside box.php and remove condition.php as it serves no purpose having an entire PHP page for a single condition.
box.php
<div class="popup <? if (strlen($str) != 4) { ?>hide<? } ?>" id="popupID">
<div class="box">
<div class="form">
<h1>SUCCESS!</h1>
<form action="home.php">
<div class="form-group">
<p class="paragraph">
Your order has been successfully placed!
</p>
<button class="homepageBtn" onclick="home.php">GO TO THE HOME PAGE</button>
</div>
</form>
</div>
</div>
</div>
I guess the problem is that you've set the action of your form to Condition.php but included the box design and code on check.php.
Note that #confirm is and input of type submit so after its pressed it will redirect you to the page specified at the action of the form.
I can suggest two possible fixes to that:
[least suggested] display the confirmation box on the Condition.php page
[most suggested] use AJAX!
The first fix requires you to move the markup and styles for box to the Condition.php file and design a whole confirmation/post action page
The second fix is better because by sending the Data to the server using AJAX you're not only going to stay on the same page (check.php) but you can also sort of hide the address to Condition.php which is supposed to be a backend file(from what i understood)
The structure should look something like this:
check.php:
<div class="frm">
// Additional Codes here
<buttin name="checkOutBtn" id="confirm">CONFIRMM</button>
</form>
<?php include 'box.php';?>
<script src='ConfirmCheck.js'></script>
ConfirmCheck.js:
$(document).ready(function () {
$('#confirm').click(function () {
// code to get all of your fields and put them in a js object: FDATA
$.ajax({type:'POST', url:'Condition.php', data: FDATA,
success:function(){
$('.popup').removeClass("hide");
}});
});
});
Condition.php:
<?php
// Defined variables and additional codes section
if (strlen($str) == 4) { //success
echo "success message";
}else{ // failed
header('HTTP/1.0 400 Bad Request');
die("bad request");
}
// Additional Codes
?>
The request goes back and forth between check.php and Condition.php in the background and your code gets notified through a callback whether or not to show the box.

Codeigniter : Pass data from view to controller using anchor tag

I am working on a project where I need to pass an ID to controller when someone clicks on the link, and open response in new tab.
I googled for solution on this, but couldn't find proper result. I also tried by sending data through URL in anchor tag, but then it gave an error of config.php file, so I reversed the code.
Currently I am using form tag to pass data. Can ye do this using PHP, or will we have to take help of jquery?
Here's View code:
<form class="form-horizontal" method="post" action='<?php echo base_url() . "home/edit_policy"; ?>'>
<div class="form-group">
<input type="hidden" class="form-control" id="polid" name="polid" value="<?php echo $ajax_view_pol_response[0]->polid; ?>">
<div class="col-sm-offset-3 col-sm-3">
<button class="btn btn-primary" id="editpolsubmit">Edit this Policy</button>
</div>
</div>
</font>
This code is from Controller:
public function edit_policy() {
$polid = $this->input->post('polid');
}
I want to transfer the "polid" from view to controller function using anchor tag.
All positive suggestions are appreciated.

PHP redirect form to URL not working

So I'm trying to use this http://www.formget.com/how-to-redirect-a-url-php-form/ as an RSVP form.
Ideally, entering the right code on (http://baby.engquist.com/invite/) will lead you to a google form. However, when I enter any code (right or wrong) and press the button, it simply refreshes back to the /invite page.
My code is as follows:
<p style="text-align: center;">
<form action="index.php" id="#form" method="post" name="#form">
<div class="row">
<div class="large-3 columns large-centered">
<div class="row collapse">
<div class="small-10 columns">
<input id="code" name="code" placeholder="Enter the code to RSVP." type="text" >
</div>
<div class="small-2 columns">
<input id='btn' name="submit" type='submit' class="button prefix" value='Go'>
</div>
</div>
</div>
</div>
<?php
include "redirect.php";
?>
</form>
</p>
And the included redirect.php:
<?php
if(isset($_POST['submit'])){
// Fetching variables of the form which travels in URL
$code = $_POST['code'];
if($code ='show620')
{
// To redirect form on a particular page
header("Location:http://google.com/");
} else {
print "Oops that's not the right code. Try again!";
}
?>
Thanks so much for any help!
You should have action attribute pointing to file where you do processing after submitting. In your case its redirect.php
Use :
<form action="redirect.php" > ............
And dont include redirect.php at the bottom of the form.
You need to write ob_start(); on top of your page and die(); after header("Location:http://google.com/"); in redirect.php
The php header redirect only works if it's called from a page that is completely blank. You have to change your form action to "redirect.php" and simply get rid of the code at the bottom of your html.

can seem to submit form in codeigniter and go to next view?

below is my 'mainview.php' view. from here iam attempting to submit and just open the next view which is called 'carerview.php'.
<form action="<?php echo base_url()?>login" method="post">
<div class="input-prepend">
<span class="add-on"><i class="icon-envelope"></i></span>
<input type="text" id="" name="" placeholder="your#email.com"></br></br>
<div class="input-prepend">
<span class="add-on"><i class="icon-lock"></i></span>
<input type="password" id="" name="" placeholder="Password"></br></br>
<button type="submit" class="btn btn-primary"><i class="icon-user icon-white"></i>Sign in</button>
</div>
</div>
</form>
Iam trying to submit this is giving me issues.The Index page loads which contains the above view. but when i submit . i get requested URL not found on this server
. then if i use the full url action="application/controllers/user/login" i get a forbidden, dont have permission to access it.
my method in my controller class is just to load the next view on submit so i dont think there is an issue there . below is the controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
public function index()
{
if(!$this->isLoggedIn())
{
$this->load->view('mainview');
}
else
{
//do something
}
}
public function login()
{
$this->load->view('carerview');
}
public function isLoggedIn()
{
return false;
}
}
any help would be appreciated thanks.
if you didn't remove index.php from your URL and didn't set anything to base_url in configuration,try this
<?php echo base_url();?>index.php/user/login
localhost/your_app_folder/index.php/controller/action
Your form action is base_url(), which means is the application index route.
Try using form_open() (in the form_helper), which takes care of building the correct url:
<?php echo form_open('user/login');?>
... your form here
<?php echo form_close();?> // since I didn't see a close form tag in your form
Be careful of any routes that might intercept the request.
Alternatively, you could use site_url():
<form method="POST" action="<?php echo site_url('user/login');?>">

How Upload 2 file using backbone and rest api

How to upload files using backbone and rest api (codeignitier). following is my html form data:-
<form class="form-horizontal" id="upgrade_firmware" method="get" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label muted">IMG</label>
<div class="controls">
<input type="file" id="fu-img" value="" name="fu-img" >
</div>
</div>
<div class="control-group">
<label class="control-label muted">MD5</label>
<div class="controls">
<input type="file" id="fu-md5" value="" name="fu-md5">
</div>
</div>
</form>
How can i upload this in my view files. if it is a form to create or delete i can use model.save in backbone and pass that in to rest api.But in this case this is a upload so how can i do it with backbone and rest api.
if i click upload button i can upload it to /home/upload directory and it should be a get call , why because i need to check the file is already there or not..if i call get i will get backend response as {"file":true} ,it means file already there so i exit.
if get call success i redirect to progress page,{"progress": 40%}
Is it possible to upload like this? upload file using get call and take appropriate response from backend? using backbone and rest api.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
require(APPPATH.'/libraries/REST_Controller.php');
class FRM_Upload extends REST_Controller
{
function api_get()
{
//upload to /home/upload dir
$message = json_decode(file_get_contents("assets/json/firmware_progress.json"));
$this->response($message, 200);
}
}

Categories