how to run a form with parameter in codeigniter? - php

I am new to codeigniter and i want to run my sms web service code in view when user insert number.
but the post method is empty! can anyone help me?
var_dump($_POST['sendSms']);exit;
if(array_key_exists('sendSms', $_POST)) {
sendSms();
}
function sendSms(){ //my sms web service code}
echo '<form method="Post" action= "http://crm.oynarco.ir/admin/settings?group=sms">';
?>
<input type="hidden"
name="<?php echo $this->security->get_csrf_token_name()?>"
value="<?php echo $this->security->get_csrf_hash()?>">
<?php
echo '<input type="hidden" name="username" value="09172030433"/><br />';
echo '<input type="hidden" name="password" value="Oynar1234" /><br />';
echo '<input type="text" name="to" class="form-control test-phone" placeholder="'._l('staff_add_edit_phonenumber').'" /><br />';
echo '<textarea type="text" name="text" class="form-control sms-gateway-test-message" placeholder="'._l('test_sms_message').'" ></textarea><br />';
echo '<input type="text" name="From" class="form-control" value="5000203069627" /><br />';
echo '<input type ="submit" name="sendSms" class="btn btn-info send-test-sms" value="'._l('send_test_sms').'" />';
echo '</form>';

in action root to controller then in controller get the post method and add your sms function.
?>
<form method="Post" action= "settings/sendSms">
<input type="hidden"
name="<?php echo $this->security->get_csrf_token_name()?>"
value="<?php echo $this->security->get_csrf_hash()?>">
<?php
echo '<input type="hidden" name="username" value = "09172030433"/><br />';
echo '<input type="hidden" name="password" value ="Oynar1234" /><br />';
echo '<input type="text" name="to" class="form-control test-phone" placeholder="'._l('staff_add_edit_phonenumber').'" /><br />';
echo '<textarea type="text" name="text" class="form-control sms-gateway-test-message" placeholder="'._l('test_sms_message').'" ></textarea><br />';
echo '<input type="text" name="From" class="form-control" value = "5000203069627" /><br />';
echo '<input type ="submit" name="sendSms" class="btn btn-info send-test-sms" value = "'._l('send_test_sms').'" />';
echo '</form>';
in controller:
public function sendSms(){
//var_dump($_POST);exit;
if (isset($_POST) ){
//send sms
}

Related

How to get array data from HTML form?

I have a form in HTML, and it stores data into array structure.
echo '<input type="text" style="text-align:right;" size="5" name="row[1][kidname]" />';
echo '<input type="text" type="number" style="text-align:right;" size="5" name="row[1][kidweight]" />';
echo '<input type="text" type="number" style="text-align:right;" size="5" name="row[1][kidheight]" />';
echo '<input type="text" style="text-align:right;" size="5" name="row[2][kidname]" />';
echo '<input type="text" type="number" style="text-align:right;" size="5" name="row[2][kidweight]" />';
echo '<input type="text" type="number" style="text-align:right;" size="5" name="row[2][kidheight]" />';
Supposed I need to get the second kid's weight value, how should I do? I have tried:
$_POST[row[2][kidweight];
$_POST['row[2][kidweight'];
You can try also.
$_GET['row'][2]['kidweight'];

PHP CMS Trouble

I am in the middle of creating a CMS in PHP & MySQL for the company I work for and have hit a bump in the road.
So I have a table that fetches and lists everything from a table, then next to each record is an edit button.
This button has the following code:
<?php
echo '<td><form method="POST" action="editRecord.php?id='.$id.'">
<input type="submit" name="Edit"></form></td>';
?>
Which then obviously goes to that page, however on the next page i have the following code and it's not running anything.
I don't understand why it's not fetching the information from the database if I have given it the ID...
include 'login/connection.php';
$id = $row['id'];
$result = $db->query("SELECT * FROM vehicleOrderForm WHERE id = ' $id ' ");
$row = mysqli_fetch_array($result);
That code is at the start and then further down is this;
<?php
echo $row["id"];
$id = $row["id"];
$make = $row["make"];
$varient = $row["varient"];
$stockno = $row["stockno"];
$transmission = $row["transmission"];
$cc = $row["cc"];
$colour = $row["colour"];
$delivery = $row["delivery"];
$stock = $row["stock"];
$sold = $row["sold"];
$customer = $row["customer"];
$tax = $row["tax"];
$comments = $row["comments"];
?>
<div>
<h1><?php echo $id; ?></h1>
</div>
<form method="POST" action="">
<p>Make:</p>
<?php echo '<input type="text" name="make" value="'.$make.'" />;' ?>
<p>Varient:</p>
<input type="text" name="varient" value=" <?php echo $varient; ?>" /> <br />
<p>Stock Number:</p>
<input type="email" name="stockno" value="<?php echo $stockno; ?>" /> <br />
<p>Transmission:</p>
<input type="number" name="transmission" value="<?php echo $transmission; ?>" /> <br />';
<p>CC:</p>
<input type="username" name="cc" value="<?php echo $cc; ?>" /> <br />';
<p>Colour:</p>
<input type="text" name="colour" value="<?php echo $colour; ?>" /> <br />';
<p>Expected Delivery:</p>
<input type="text" name="delivery" value="<?php echo $delivery; ?>"/> <br />';
<p>In Stock:</p>
<input type="text" name="stock" value="<?php echo $stock; ?>"/> <br />';
<p>Status:</p>
<input type="text" name="sold" value="<?php echo $sold; ?>"/> <br />';
<p>Customer:</p>
<input type="text" name="customer" value="<?php echo $customer; ?>"/> <br />';
<p>Tax:</p>
<input type="text" name="tax" value="<?php echo $tax; ?>"/> <br />';
<p>Comments:</p>
<input type="text" name="comments" value="<?php echo $comments; ?>"/> <br />';
<input type="Submit" name="Edit" value="Edit">';
</form>
If anyone can understand it, that would be great.
That form around the Edit button looks like it's totally useless.. You can't sent the form with POST method, and attach an id to the action url: that param won't be sent.
Solution 1: If you can, I would suggest you to switch to GET param and use an anchor. Like this:
<?php echo '<td>Edit</td>'; ?>
And edit your code on page editRecord.php as follows:
$id = $_GET['id']; // you need to receive the param from the url
Solution 2: If you want to keep the <form>, you should write the following code:
<?php
echo '<td><form method="POST" action="editRecord.php"> '.
'<input type="hidden" name="id" value="'.$id.'" />'.
'<input type="submit" name="Edit"></form></td>';
?>
And on page editRecord.php:
$id = $_POST['id']; // you need to receive the param from the url

How can I style these echo statements that make up my form

I want to style these echo statements like a login form. How can I style these echo statements?
echo '<form action="login.php" method="post"><input type="hidden" name="ac" value="log"> ';
echo 'Username: <input type="text" name="username" />';
echo 'Password: <input type="password" name="password" />';
echo '<input type="submit" value="Login" />';
echo '</form>';
Try Following snipets
echo '<style>.testclassName{ text-align:right; }</style>';
echo '<form action="login.php" method="post"><input type="hidden" name="ac" value="log"> ';
echo 'Username: <input type="text" name="username" class="testclassName"/>';
echo 'Password: <input type="password" name="password" />';
echo '<input type="submit" value="Login" />';
echo '</form>';

Concatenate right an input

I am trying to concatenate this code but i can not do it right
echo '<input type="text" id="text" name="username"
value=".<?php if(isset($_COOKIE['.'rememberme'.']))
{echo $_COOKIE['.'remember me'.'];}?>."
placeholder="Username"/><br />';
You're already in PHP there...
<?php
echo '<input type="text" id="text" name="username"';
if( isset($_COOKIE['rememberme'])) echo ' value="'.htmlspecialchars($_COOKIE['rememberme']).'"';
echo ' placeholder="Username" /><br />';
printf('<input type="text" id="text" name="username" value="%s" placeholder="Username"/><br />',
(isset($_COOKIE['remember_me'])) ? htmlspecialchars($_COOKIE['remember_me']) : ''
);

Not validating one of the search fields

I want to check if either of my search fields are empty, and if they are i write out a failure message. For some reason the following code doesn't work when I try to submit empty values in both search fields, or leaving the q2 search field empty. It only writes out the failure message when I only insert a value into the first field. Hope you guys can help.
<div id="searchField">
<form name="searchField" action="" method="get">
<input type="search" name="q" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/>
<input type="search" name="q2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/>
<input type="hidden" id="v" name="v" value="2" />
<input type="hidden" id="b" name="b" value="" />
<button type="submit" id="loop" style="border:0px; background:transparent; vertical-align:middle; margin-left:-85px; margin-top:-3px;">
<img src="images/loop.png" width="75" height="75" alt="submit" />
</button>
</form>
</div>
<div id="theData">
<?
if(str_replace(" ", "",$_GET['q'])!="" && str_replace(" ","",$_GET['q2'])!=""){
$qContent = $_GET['q'];
$succes = mysql_query("SELECT*FROM film WHERE name='".$qContent."'");
include("searchMaster.php");
if(mysql_num_rows($succes)) {
while($o = mysql_fetch_array($succes)){
echo $o['name'];
if($o['trailer']){
echo '<div id="ytplayerWrap">';
echo '<iframe id="ytplayer" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/'.$o['trailer'].'?http://amnestic.ueuo.com"
frameborder="0"/>';
echo '</div>';
}else {
echo '<span style="font-size:20px;">';
echo '<br /><br /> No trailer was found for <em>'.$_GET['q'].'</em> :(';
echo '</span>';
}
}
}else{
echo 'You did the fuckup :(';
}
}else{
echo 'You did the fuckup :(';
}
?>
The name and id of your input fields must be same
Like this
<input type="text" name="submitQuery" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/>
<input type="text" name="submitQuery2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/>

Categories