Controller
public function searchNew()
{
$sid = //account_sid;
$token = //auth_token;
$client = new Services_Twilio($sid, $token);
$country = $this->input->post('select_country');
$type = $this->input->post('type');
$params = array(
'Contains' => $this->input->post('contains'),
'SmsEnabled' => $this->input->post('SMS'),
'MmsEnabled' => $this->input->post('MMS'),
'VoiceEnabled' => $this->input->post('Voice'),
'ExcludeAllAddressRequired' => TRUE,
'ExcludeLocalAddressRequired' => TRUE,
'ExcludeForeignAddressRequired' => TRUE
);
$numbers = $client->account->available_phone_numbers->getList($country, $type, $params);
return $numbers;
}
View
<form action="<?php echo base_url('tenant/phone_numer/searhNew');?>" method="post">
<input type="text" name="contains" class="form-control mbottom1" id="user_firstname" placeholder="Enter a description name for your number">
<select name="select_country" id="select_country" class="form-control">
<option disabled selected>Country</option>
<option value="US">USA (+1)</option>
</select>
<input id="checkcap1" type="checkbox" name="Voice" class="radio1" value="True"/>Voice
<input id="checkcap2" type="checkbox" name="SMS" class="radio1" value="True"/>SMS
<input id="checkcap3" type="checkbox" name="MMS" class="radio1" value="True"/>MMS
<input id="checktype1" type="radio" name="type" class="radio2" value="Local"/>Local
<input id="checktype2" type="radio" name="type" class="radio2" value="Mobile"/>Mobile
<input id="checktype3" type="radio" name="type" class="radio2" value="TollFree"/>Toll-Free
<input id="checktype3" type="radio" name="type" class="radio2" value="National"/>National
<button type="Submit">Test Submit</button>
</form>
I need help in getting the $country,$type,$params from my view file. I have done a few testing and when I change $country = $this->input->post('select_country'); to $country = "US" and the other variables into a static value, the code works fine, but when I change it their respective inputs the error message I am receiving is
The requested resource
/2010-04-01/Accounts/acount_sid/AvailablePhoneNumbers//Tollfree.json
was not found
Thanks for any help.
Do it with step by step flow of codeigniter.. After submit form , In controller print your post data..
print_r($_POST);
Check all data come from Form.. And check all by isset and pass in params,type , category. It will working fine..One More thing , In twilio library all parameters passing are important e.g.
$params=array();
if(isset($this->input->post('Voice'))){
$params['VoiceEnabled']=$this->input->post('Voice');
}
Related
I decided to create my first Wordpress plugin, then I switched to create a template instead, because I had problems with sending the data through form action. Now I have problems with adding data to databse using a template. I have a problem with my functions.php file I think. Can someone help me, please? The code:
<?php
if(isset($_POST['submitbtn']))
{
global $wpdb;
$data_array = array(
'OrderNum' => $_POST['OrderNum'],
'OrderStatus' => $_POST['OrderStatus'],
'ClientFirstName' => $_POST['ClientFirstName'],
'ClientLastName' => $_POST['ClientLastName']
);
$table_name = 'ordernumber';
$sql=$wpdb->insert($table_name, $data_array, $format=NULL);
if($sql == 1){
echo '<h1>Added</h1>';
}else{
echo 'Error';
}
}
?>
EDIT:
For some reason I can't add my whole second php file here so here is just the form, and I want to add I am a beginner in this all. `
<form method = "post">
<fieldset>
<p><label for="ClientFirstName">First name:</label>
<input type="text" id="ClientFirstName" name="ClientFirstName"/>
</p>
<p><label for="ClientLastName">Last name:</label>
<input type="text" id="ClientLastName" name="ClientLastName"/>
</p>
<p><label for="OrderNum">Order number: </label>
<input type="text" id="OrderNum" name="OrderNum"/>
</p>
<p><label for="OrderStatus">Order status: </label>
<select name="OrderStatus" id="OrderStatus">
<option value="Your order is wating for">Your order is wating</option>
<option value="Order is shipped">Order is shipped.</option>
<option value="Done">Done</option>
<option value="Error in order">Error in order </option>
</select>
</p>
</fieldset>
<p><input type="submit" value="Add order" name="submitbtn"></p>
</form>`
my view page
<form action="<?php echo base_url()?>Quiz/add_stu_ans" method="POST">
<label>Who is usa president</label>
<input type="text" name="answer[]">
<label>Dhoni is cricket player player</label>
<input type="radio" name="answer[]" value="True">True
<input type="radio" name="answer[]" value="False">False
<label>Which is asian country</lable>
<input type="checkbox" name="answer[]" value="newyork">newyork
<input type="checkbox" name="answer[]" value="india">india
<input type="checkbox" name="answer[]" value="srilanka">srilanka
</form>
My controller page
public function add_stu_ans()
{
$values['stu_answer'] = $this->input->post('ans');
$this->Common_model->insert_record('student',$values);
$this->session->set_flashdata('message_name' , 'Your Data is Inserted');
redirect('Quiz/question');
}
And this is model
public function insert_record($table,$values) {
$this->db->insert($table,$values);
return $this->db->insert_id();
}
please anyone can tell me how to customize the code in controller
Only possible if you take another hiddent text field where your 'qstn_id' will be in value. take this field in array.
in coding part while taking foreach loop you have to take qstn_id as in "[key]" format otherwise you cant find skipped records.
for eg. :
foreach ($que as $key => $ansValue) {
$val2 = $ansValue[$key];
}
// $val2 store as your output.
This is code to save the data using json_encode. Let me know you get any error I have not run this code.
View File
<form action="<?php echo base_url()?>Quiz/add_stu_ans" method="POST">
<label>Who is usa president</label>
<input type="text" name="usa_president">
<label>Dhoni is cricket player player</label>
<input type="radio" name="cricket_player" value="True">True
<input type="radio" name="cricket_player" value="False">False
<label>Which is asian country</lable>
<input type="checkbox" name="country[]" value="newyork">newyork
<input type="checkbox" name="country[]" value="india">india
<input type="checkbox" name="country[]" value="srilanka">srilanka
</form>
Controller
public function add_stu_ans()
{
$usa_president = $this->input->post('usa_president');
$cricket_player= $this->input->post('cricket_player');
$country= $this->input->post('country');
$final_data = array(
'usa_president' => $usa_president,
'cricket_player' => $cricket_player,
'country' => $country,
);
$json_encode_data = json_encode($final_data);
$this->Common_model->insert_record('student',$json_encode_data);
$this->session->set_flashdata('message_name' , 'Your Data is Inserted');
redirect('Quiz/question');
}
Please check this at your end and time of fetch the data from the database then you need to pass that return data from the function json_decode.
$json_decode_data = json_decode($return_data_from_data_table);
i have some thing like this in my html multi checkbox
<label for="Status"><h2>Status:</h2></label>
<input type="checkbox" name="status[]" value="new">New<br>
<input type="checkbox" name="status[]" value="assigned">Assigned<br>
<input type="checkbox" name="status[]" value="resolved">Resolved<br>
<input type="checkbox" name="status[]" value="verified">Verified<br>
<input type="checkbox" name="status[]" value="closed">Closed<br>
myphp
$status = $_POST["status"];
$url = "http://some-example.com/project="abc" and state in [".$status."]/";
header("Location:$url");
i want the url to be like:
$url = "http://some-example.com/project="abc" and state in ["new","assigned","resolved","verified","closed"]/
is it possible to do this? if so please help.
Use http_build_query :
$url = "http://some-example.com/" . http_build_query([
"project" => "abc",
"state" => ["new","assigned","resolved","verified","closed"]
]);
Output :
http://some-example.com/project=abc&state%5B0%5D=new&state%5B1%5D=assigned&state%5B2%5D=resolved&state%5B3%5D=verified&state%5B4%5D=closed
I want insert following data by insert_batch as in following example in database table (mysql):
HTML:
<input name="u_id[0][0]" value="76">
<input name="un[0][0]" value="1">
<input type="text" name="ue[0][0]" value="11">
<input type="text" name="up[0][0]" value="111">
<input name="u_id[1][0]" value="77">
<input name="un[1][1]" value="2">
<input type="text" name="ue[1][1]" value="22">
<input type="text" name="up[1][1]" value="222">
<input name="un[1][2]" value="3">
<input type="text" name="ue[1][2]" value="33">
<input type="text" name="up[1][2]" value="333">
PHP:
$u_id = $this->input->post('u_id');
$un = $this->input->post('un');
$up = $this->input->post('up');
$ue = $this->input->post('ue');
$data = array();
foreach ($un as $idx => $name) {
$data[] = array(
'u_id' => $u_id[$idx],
'un' => $un[$idx],
'up' => $up[$idx],
'ue' => $ue[$idx],
);
};
$this -> db -> insert_batch('units', $data);
I want insert they as this:
How should change php code and html code? what do i do?
I am assuming you are using CodeIgniter and that the name of the database table that you want to insert to is called 'units' and that its 'id' column is autoincrement.
I am basing off my solution from CodeIgniter User Guide Version 2.0.3 using a call to a helper ($this->db->insert_string()) of the Database class.
foreach ($data as $row)
{
$error_code = $this->db->insert_string('units', $row);
}
Refer to http://codeigniter.com/user_guide/database/helpers.html
The insert_string function that the Database class provides appears to take an associative array, build an INSERT statement from the elements inside, execute it and then return a numerical error code.
LOL, it's not pretty, but it might work sometimes:
<input name="u_id[]" value="76">
<input name="un[]" value="1">
<input type="text" name="ue[]" value="11">
<input type="text" name="up[]" value="111">
<input name="u_id[]" value="77">
<input name="un[]" value="2">
<input type="text" name="ue[]" value="22">
<input type="text" name="up[]" value="222">
<input name="un[]" value="3">
<input type="text" name="ue[]" value="33">
<input type="text" name="up[]" value="333">
$u_id=$this->input->post('u_id');
$un=$this->input->post('un');
$up=$this->input->post('up');
$ue=$this->input->post('ue');
for($i=0;$i<count($u_id);$i++){
for($ii=0;$ii<count($un[$i]);$ii++){
(count($un[$i])>1)?$unn=$un[$i][$ii+1]:$unn=$un[$i][$ii];
(count($ue[$i])>1)?$uen=$ue[$i][$ii+1]:$uen=$ue[$i][$ii];
(count($up[$i])>1)?$upn=$up[$i][$ii+1]:$upn=$up[$i][$ii];
$this->db->insert('units', array(//use db insert here
'u_id'=>$u_id[$i][0],
'un'=>$unn,
'ue'=>$uen,
'up'=>$upn,
));
}
}
I'd go so far as to suggest you not use it. But perhaps it might inspire someone to offer a better solution.
Cheers.
So I have a Radio button group, like so:
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>Choose a pet:</legend>
<input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" checked="checked" />
<label for="radio-choice-1">Cat</label>
<input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2" />
<label for="radio-choice-2">Dog</label>
<input type="radio" name="radio-choice-1" id="radio-choice-3" value="choice-3" />
<label for="radio-choice-3">Hamster</label>
<input type="radio" name="radio-choice-1" id="radio-choice-4" value="choice-4" />
<label for="radio-choice-4">Lizard</label>
</fieldset>
</div>
Now if I just submit the for I get this $_POST (Note I have multiple Radio group questions)
Array
(
[radio-choice-1] => choice-1
[radio-choice-2] => choice-4
[radio-choice-3] => choice-2
[submit] => submit
[PHPSESSID] => 11111111111111111
)
How Can I restructure the HTML or $_POST data before submission to make it look like this:
Array
(
[type-1] => radio-choice-1
[answer-1] => choice-1
[type-2] => radio-choice-2
[answer-2] => choice-4
[type-3] => radio-choice-3
[answer-3] => choice-2
[submit] => submit
[PHPSESSID] => 11111111111111111
)
Maybe jQuery as an option?
You can do it post submission, the code below should work if you keep your original naming conventions.
$postValues = $_POST;
$altered = Array();
$unaltered = Array();
foreach ($postValues as $key => $val) {
if ( FALSE !== stripos($key, 'radio-choice-') ) {
$num = explode('-', $key);
$num = $num[2];
$altered['type-'.$num] = $key;
$altered['answer-'.$num] = $value;
} else {
$unAltered[$key] = $value;
}
}
$manipulatedPOSTData = array_merge($altered, $unAltered);
// Keep doing what you intended
I assume you are talking about a form that you are submitting?
If you want to add finer control over what gets posted, you can do one of two things:
1) add hidden variables
or
2) use jQuery .post() (http://api.jquery.com/jQuery.post/) instead of doing a normal form submission.
Personally, I think the first of the two is simplest:
<div data-role="fieldcontain">
<input type="hidden" name="type-1" value="radio-choice-1" />
<fieldset data-role="controlgroup">
<legend>Choose a pet:</legend>
<input type="radio" name="answer-1" id="radio-choice-1" value="choice-1" checked="checked" />
<label for="radio-choice-1">Cat</label>
<input type="radio" name="answer-1" id="radio-choice-2" value="choice-2" />
<label for="radio-choice-2">Dog</label>
<input type="radio" name="answer-1" id="radio-choice-3" value="choice-3" />
<label for="radio-choice-3">Hamster</label>
<input type="radio" name="answer-1" id="radio-choice-4" value="choice-4" />
<label for="radio-choice-4">Lizard</label>
</fieldset>
</div>
By changing the name of the radio ground to answer-1 and adding a hidden variable, that should meet your requirements (do the same for your other radio elements).
Avoid client side elaboration if you can.
Otherwise use .submit() and hand code what you need. but it's harder.