Like in topic. How can I call the overrider controller from html form like this below:
<form method="post" action="index.php?controller=CmsController">
<input name="test" type="text" />
<input name="action" value="getStatus" type="hidden" />
<input value="test" type="submit" />
</form>
This code above I have in my tpl file.
File: /override/controllers/front/CmsController.php
---edit
{$link->getModuleLink('blockcms', 'CmsController')|escape:'html'}
doesn’t work.
---edit
public function initContent() {
parent::initContent();
if (Tools::getValue('action') && Tools::getValue('action') == 'getStatus') {
$id = $this->getIdByCode(Tools::getValue('voucher'));
$obj = new CartRuleCore($id);
$context = Context::getContext();
$response = $obj->checkValidity($context);
if ($response == NULL or $response == 'Koszyk jest pusty'){
$response = 'Kod ';
}
}
if (isset($this->cms)) {
$this->cms->content = str_replace("<!--response-->", $response, "{$this->cms->content}");
}
$this->setTemplate(_PS_THEME_DIR_ . 'cms.tpl');
This is part of initContent function in \override\controllers\front\CmsController.php And in my file tpl I have
<form method="post" action="index.php?controller=CmsController">
<input name="test" type="text" />
<input name="action" value="getStatus" type="hidden" />
<input value="test" type="submit" />
Related
<body>
<div id='container'>
<pre>
<fieldset>
<legend>login</legend>
<?php echo validation_errors(); ?>
<form method="post" id="login" name="login">
username :<input type="text" name="uname" id="uname" value="<?php echo $this->session->flashdata('uname') ?>" ><br>
password :<input type="password" name="upass" id="upass">
<input type="checkbox" name="remember">Remember me
<input type="submit" value="login" class="submit" name="login"> <input type="submit" value="signup" name="signup">
</form>
</fieldset>
</pre>
<div><?php echo $this->session->flashdata('error'); ?></div>
</div>
<div id="error"></div>
</body>
controller:
public function view()
{
if($this->input->post("login"))
{
if($this->input->post('remember')=='on')
{
$uname=$this->input->post("uname");
$this->session->set_flashdata('uname',$uname);
}
$this->form_validation->set_rules('uname','username','trim|required');
$this->form_validation->set_rules('upass','password','required');
$data['title']='login page';
if ($this->form_validation->run() === FALSE)
{
$this->session->set_flashdata('error','enter username and password');
$this->load->view('stud_det/login',$data);
}
else
{
$data['result']=$this->stud_model->login();
if(!empty($data['result']))
{
$session=array(
'uname'=>$this->input->post('uname'),
'upass'=>$this->input->post('upass')
);
$this->session->set_flashdata($session);
$this->session->set_userdata($session);
$this->load->view('stud_det/view',$data);
}
else{
$this->session->set_flashdata('error','username or password is incorrect');
$this->load->view('stud_det/login',$data);
}
}
}
else{
$this->load->view('stud_det/index',array('title'=>''));
}
In your first if condition, you are loking for 'login' POST variable, however 'login' is the name of the submit input type. You have to test the post value 'uname' and 'upass'. Something like this:
if($this->input->post("uname") && $this->input->post("upass")) {
// Your code...
}
Other thing, you do not need define name to form tag. The name 'login' it is duplicated in form and input tags.
This form takes in data only in the "inp" field. To multiply two numbers you'd have to input the first number then hit "=" to send the number to the "out" field then type in the second number and hit "*". I am attempting to post the results($result) of calculations into the "out" field and not sure how to do this using php. Any help would be greatly appreciated.
php:
$input = $_POST['inp'];
$output= $_POST['out'];
if($_POST['submit'] == 'add') {
$result = $input + $output;
//set result to "out"
}
else if($_POST['submit'] == 'sub') {
$result = $input - $output;
//set result to "out"
}
else if($_POST['submit'] == 'mul') {
$result = $input * $output;
//set result to "out"
}
else if($_POST['submit'] == 'div') {
$result = $input / $output;
//set result to "out"
}
else if($_POST['submit'] == 'equ') {
$result = $input;
//set result to "out"
}
form:
<body>
<form action = "calc.php" method = "post">
<input type="text" value="0.0" name="out" readonly/>
<input type="text" value="0" name="inp"/>
<input type="submit" value="+" name="add"/>
<input type="submit" value="-" name="sub"/>
<input type="submit" value="*" name="mul"/>
<input type="submit" value="/" name="div"/>
<input type="submit" value="=" name="equ"/>
</form>
</body>
If you php and html code in the same file you can write simple write to out input value calculated result. Try something like this:
<body>
<form action = "calc.php" method = "post">
<input type="text"
value="<?=!empty($result)?$result:"0.0"?>" name="out" readonly/>
<input type="text" value="0" name="inp"/>
<input type="submit" value="+" name="add"/>
<input type="submit" value="-" name="sub"/>
<input type="submit" value="*" name="mul"/>
<input type="submit" value="/" name="div"/>
<input type="submit" value="=" name="equ"/>
</form>
</body>
I modified your code.
$result= '';
if ($_POST) {
$input = (int) $_POST['inp'];
$output= (int) $_POST['out'];
if(isset($_POST['add']) && !empty($input)) {
$result = $output + $input;
//set result to "out"
}
else if(isset($_POST['sub']) && !empty($input)) {
$result = $output - $input;
//set result to "out"
}
else if(isset($_POST['mul']) && !empty($input)) {
$result = $output * $input;
//set result to "out"
}
else if(isset($_POST['div']) && !empty($input)) {
$result = $output / $input;
//set result to "out"
}
else if(isset($_POST['equ']) && !empty($input)) {
$result = $input;
//set result to "out"
} else {
$error = "Please enter a number";
}
}
<body>
<form action="cal.php" method = "post">
<input type="text" value="<?=!empty($result)?$result:"0.0"?>" name="out" readonly/>
<input type="text" value="0" name="inp"/>
<input type="submit" value="+" name="add"/>
<input type="submit" value="-" name="sub"/>
<input type="submit" value="*" name="mul"/>
<input type="submit" value="/" name="div"/>
<input type="submit" value="=" name="equ"/>
</form>
<p><?=isset($error)?$error:''?></p>
<?php
$mysql_pekare=mysqli_connect("localhost", "1","2", "3") or die(mysqli_error($mysql_pekare));
if(!empty($_GET['name'])) {
$query = "INSERT INTO Personinfo(`Personname`, `Personage`) VALUES('$_GET[namn]', '$_GET[age]')";
if (!mysqli_query($mysql_pekare,$query)) {
die('Error: ' . mysqli_error($mysql_pekare));
}
echo "Welcome ". $_GET["namn"];
}
?>
<form id="Personinfo" action="index.php" > <!-- default form method is GET -->
<input type="text" id="namn" name="namn" placeholder="namn"/>
<input type="text" id="age" name="age" placeholder="age"/>
<input type="submit"/>
</form>
</body>
<body>
<?php
$mysql_pekare=mysqli_connect("localhost", "1","2", "3") or die(mysqli_error($mysql_pekare));
if(!empty($_GET['Product'])) {
$query = "INSERT INTO Produkter(`ProduktNamn`, `ProduktPris`) VALUES('$_GET[Product]', '$_GET[Price]')";
if (!mysqli_query($mysql_pekare,$query)) {
die('Error: ' . mysqli_error($mysql_pekare));
}
}
?>
<form id="Produkter" action="index.php" > <!-- default form method is GET -->
<input type="text" id="Product" name="Product" placeholder="Produkt" />
<input type="text" id="Price" name="Price" placeholder="Pris"/>
<input type="submit"/>
</form>
You have two forms with different input names, so you can check for these names, instead of generic $_GET:
if( isset( $_GET['namn'] ) )
{
(...)
}
elseif( isset( $_GET['Product'] ) )
{
(...)
}
If you want be more chic, you can identify different forms through an hidden <input> identifier:
<form id="Personinfo" action="index.php" >
<input type="hidden" name="formID" value="Personinfo"/>
(...)
<form id="Produkter" action="index.php" >
<input type="hidden" name="formID" value="Produkter"/>
(...)
and in you php code, check for this:
if( isset( $_GET['Personinfo'] ) )
{
(...)
}
elseif( isset( $_GET['Produkter'] ) )
{
(...)
}
Below is the code I use to process payment in my site. This cart has only one item. This code is for paypal. I want to sell same item on payza.
//process order for paypal
// Prepare GET data
$query = array();
$query['notify_url'] = 'http://mywebsite.com/ipn.php';
$query['cmd'] = '_cart';
$query['upload'] = '1';
$query['business'] = 'payment#mywebsite.com';
//main item
$query['item_name_1'] = $item_name;
$query['item_number_1'] = '1';
$query['amount_1'] = $item_price;
$query['currency_code'] = "USD";
// Prepare query string
$query_string = http_build_query($query);
header('Location: https://paypal.com/cgi-bin/webscr?' . $query_string);
<form method="post" action="https://secure.payza.com/checkout">
<input type="image" name="Checkout" src="btn_buynow.gif" />
<input type="hidden" name="ap_merchant" value="payza_email"/>
<input type="hidden" name="ap_purchasetype" value="item"/>
<input type="hidden" name="ap_itemname" value="SITENAME"/>
<input type="hidden" name="ap_itemcode" value="row->id"/>
<input type="hidden" name="ap_description" value="item1_desc"/>
<input type="hidden" name="ap_amount" value="amt"/>
<input type="hidden" name="ap_currency" value="CURRENCY_CODE"/>
<input type="hidden" name="ap_returnurl" value="returnurl"/>
<input type="hidden" name="ap_cancelurl" value="cancelurl"/>
</form>
Can someone explain or show me why my form is only posting in 1 column when it should be posting in 2 columns for example.
Here is my form
<form action="{$baseurl}/redirect" method="post" enctype="multipart/form-data" id="details_change">
<textarea name="about_me" cols="53" rows="5" class="submit_form_textfield">{$profile_user.about_me}</textarea>
<input type="text" name="profile_message" />
<input type="hidden" name="action" value="user_details" />
<input type="submit" class="submit_form_button" value="Update Details" id="details_change">
</form>
And here is my PHP
if (isset($action) && $action=='user_details' && isset($_SESSION['loggeduser_id'])) {
$user = new User();
if (isset($_POST['about_me']) && isset($_POST['about_me'])) {
$_POST['$about_me'] = preg_replace("/[^a-z]/i","",$_POST['about_me']);
} else {
$about_me = '';
}
if (isset($_POST['profile_message']) && isset($_POST['profile_message'])) {
$_POST['$profile_message'] = preg_replace("/[^a-z]/i","",$_POST['profile_message']);
} else {
$profile_message = '';
}
$user->update($_SESSION['loggeduser_id'],array("about_me" => $about_me,"profile_message" => $profile_message));
}
And I have columns in my user table called about_me and profile_message
And what happens is it will only post about_me and not profile_message any reason why?
You need to use $_POST['user_details'] and $_POST['profile_message']
In HTML:
<form action="{$baseurl}/redirect" method="post" enctype="multipart/form-data" id="details_change">
<textarea name="about_me" cols="53" rows="5" class="submit_form_textfield">{$profile_user.about_me}</textarea>
<input type="text" name="profile_message" />
<input type="hidden" name="user_details" value="" />
<input type="submit" class="submit_form_button" value="Update Details" name="action" >
</form>
PHP:
if (isset($_POST['action']) && isset($_SESSION['loggeduser_id'])) {
$user = new User();
if (isset($_POST['profile_message'])) {
$profile_message = preg_replace("/[^a-z]/i","",$_POST['profile_message']);
} else {
$profile_message = '';
}
if (isset($_POST['user_details']) && isset($_POST['user_details'])) {
$user_details = preg_replace("/[^a-z]/i","",$_POST['user_details']);
} else {
$user_details = '';
}
$about_me = $_POST['about_me'];
$user->update($_SESSION['loggeduser_id'],array("about_me" => $about_me,"profile_message" => $profile_message));
}