0

I am brand new to Code Igniter but I can't seem to find a way to do this in the documentation, In normal PHP you can retrieve the contents of the entire POST variable like this

$_POST = $postedVars

But I can't seem to find something that does this in the same manner, I've tried

$arr = $this->input->post;

and

$arr = $this->input->post();

With no luck! Is this possible in CI? Thanks in advance!

asked Jul 12, 2010 at 21:16

3 Answers 3

3

First, you need a form or something that sets the variables Then, you retrieve them.

$this->input->post('first_name').

You are missing the name of the variable!

The signup form:

echo form_open('CHome/signup');
$data=array('name'=>'first_name', 'id'=>'first_name','size'=>40,'value'=>set_value('first_name'));
echo "<p><label for='first_name'>First Name </label>";
echo form_input($data);
echo form_submit('submit','Make Account');

The Model:

 function addUser(){
 //you should use $this->input->post('first_name')
 $data=array(
 'first_name'=>db_clean(ucfirst($_POST['first_name'])), //db_clean is a custom func
 'last_name'=>db_clean(ucfirst($_POST['last_name'])), 
 'email'=>db_clean($_POST['email']), 
 'username'=>db_clean($_POST['username']),
 'password'=>db_clean(sha1($_POST['password1'])), 
 'type'=>db_clean('user'),
 );
 $this->db->insert('users',$data);
 }

Codeigniter stores sessions in cookies, it's all weird. I suggest just using PHP's native sessions, such as $_SESSION['first_name']. Make sure to write "session_start();" in your controller/model so you can use sessions!! (usually do it in the constructor)

answered Jul 12, 2010 at 21:22
Sign up to request clarification or add additional context in comments.

Comments

0

well firstly you need a form to populate the form fields with variables and a submit button to post the the variables from the form fields

 <?php
 $attributes = array('class' => 'form-horizontal', 'id' => 
 'myform', 'role'=>'form');
 echo form_open('Iris/login_in', $attributes); ?>
 <div class="row">
 <div class="col-xs-10 col-md-offset-1">
 <div class="row">
 <div class ="col-xs-12">
 <div class="form-group ">
 <label for="email" class="text-warning" 
 >Email Address</label>
 <input type="email" class="form-control"
 name="email"
 placeholder="Your Email Address"
 required>
 </div>
 </div>
 </div>
 <div class="row">
 <div class ="col-xs-12">
 <div class="form-group " >
 <label for="password" class="text-
 warning">Password</label>
 <input type="password" class="form-
 control" name="password"
 placeholder="Your password"
 required>
 </div>
 </div>
 </div> 
 </form>
answered Apr 5, 2017 at 12:30

Comments

-1

You can set your data array to your post array like so. This is VERY usefull if you have many fields. Just make sure your input field name matches your database field name.

$data = $_POST;

If you have any additional elements in your post array (submit button, hidden fields, etc.) that will not be going into your database, remove them before running your insert.

unset($data['SubmitButton']);
unset($data['HiddenField1']);
$this->db->insert('users',$data);
answered Jun 22, 2017 at 19:35

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.