Clicking on edit icon filled form should open , and proced to update
Controller code
public function update_menus( $id ) {
$data = array(
'menu_title' => $this->input->post('menu_title'),
'filepath' => $this->input->post('filepath'),
'description' => $this->input->post('description'),
'left_content' => $this->input->post('left_content'),
'right_content' => $this->input->post('right_content'),
'url_path' => $this->input->post('url_path'),
'created_date' => date('Y-m-d H:i:s')
);
if ($this->login_database->update($id, $data) == TRUE) {
$this->session->set_flashdata('flash_message', 'updated');
} else {
$this->session->set_flashdata('flash_message', 'not_updated');
}
$this->load->view('update_menus');
$data = array();
$data['menus'] = $this->login_database->get_menus_by_id($id);
$this->load->view('menu_details', $data);
}
Model code
public function update($id)
{
$data = array(
'menu_title'=> $this->input->post('menu_title'),
'filepath' => $this->input->post('filepath'),
'description' => $this->input->post('description'),
'left_content' => $this->input->post('left_content'),
'right_content' => $this->input->post('right_content'),
'url_path' => $this->input->post('url_path'),
'created_date' =>date('Y-m-d H:i:s')
);
$this->db->where('id',$id);
$menus = $this->db->update('menu_details', $data);
return $menus->result();
}
view code
<?php
echo form_open('user_authentication/update_menu_submit');
?><?php foreach ($menus->result() as $row) {
?>
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">Menu Title</label>
<input type="text" name="menu_title" class="form-control" id="exampleInputTitle" placeholder="Enter Menu Title">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Menu Url</label>
<input type="text" name="url_path" class="form-control" id="exampleInputurl" placeholder="Enter File Path">
</div>
<div class="form-group">
<label for="exampleInputFile">Upload Image</label>
<input type="file" name="filepath" id="exampleInputFile">
</div>
<div class="form-group">
<label for="exampleInputDesc">Description</label>
<textarea id="editor4" name="description" rows="10" cols="80" placeholder="Enter Description"></textarea>
</div>
<div class="form-group">
<label for="exampleInputcontl">Left Content</label>
<textarea id="editor5" name="left_content" rows="10" cols="80" placeholder="Enter Left Content"></textarea>
</div>
<div class="form-group">
<label for="exampleInputcontr">Right Content</label>
<textarea id="editor3" name="right_content" rows="10" cols="80" placeholder="Enter Right Content"></textarea>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
<?php
}
echo form_close();
?>
</div>
Once click on edit action it should redirect to view page and should open filled form, Its showing error like
Fatal error: Call to a member function result() on boolean in
C:\xampp\htdocs\codecms\application\models\login_database.php on line
205 in model code,
can you just check the generated query using :
$this- db- last_query();
$data = array(
'menu_title'=> $this->input->post('menu_title'),
'filepath' => $this->input->post('filepath'),
'description' => $this->input->post('description'),
'left_content' => $this->input->post('left_content'),
'right_content' => $this->input->post('right_content'),
'url_path' => $this->input->post('url_path'),
'created_date' =>date('Y-m-d H:i:s')
);
$this->db->where('id',$id);
$menus = $this->db->update('menu_details', $data);
$this->db->last_query();
Check the generated query in your php admin .
is return $menus->result(); required ?
Related
I have problem that my input "type" is never post in database because I don't give input type in the view (I want value of my type is set by controller/hidden)... and this is my code
Controller :
<?php
public function addSmsCampaign() {
if (isset($_POST['addSmsCampaign'])) {
$this->form_validation->set_rules('campaign_name', 'campaign name', 'required|is_unique[campaigns.campaign_name]');
$this->form_validation->set_rules('sequence_qty', 'sequence quantity', 'required|integer');
$this->form_validation->set_rules('label_id', 'label id', 'required');
$this->form_validation->set_rules('type', '', 'required');
//if form validation true
if ($this->form_validation->run() == TRUE) {
$sms = 1;
$newcampaign = [
'campaign_name' => $_POST['campaign_name'],
'sequence_qty' => $_POST['sequence_qty'],
'label_id' => $_POST['label_id'],
'type' => $this->input->post('type'),
'created_at' => date('Y-m-d')
];
$this->db->insert('campaigns', $newcampaign);
redirect('userCont/sequenceform', 'refresh');
}
}
?>
and this is my view:
<form action="" method="POST">
<div class="form-group">
<label for="campaign_name">Input Campaign Title </label>
<input type="text" class="form-control" name="campaign_name" id="name">
</div>
<div class="form-group">
<label for="sequence_qty">Sequence qty </label>
<input type="text" class="form-control" name="sequence_qty" id="qty">
<input type="hidden" class="form-control" name="type" value="1">
</div>
<div class="form-group">
<label for="label_id">Choose Category</label>
<select class="form-control" name="label_id" id="label_id">
<?php
foreach ($label_content as $e) {
echo "<option value='$e->id;'>" . $e->label_name . "</option>";
}
?>
</select>
</div>
<div class="text-right">
<button class="btn btn-primary form-control" value="1" name="addSmsCampaign type">next</button>
</div><hr>
</form>
every time I post value of type is default = 0, and I want set value to 1...
thanks a lot
try changing name from 'type' to some other name in db, controller and view
I made a user registration form on the CodeIgniter framework so users can registrate to my website. Now the only thing that doesn't work is that I cant upload a profile picture. When I click on the register button I'm getting 2 errors. I want the profile picture to be uploaded in the product_foto column.
This is my view file: (register.php) :
<form action="" method="POST" enctype='multipart/form-data'>
<div class="form-group">
<label for="voornaam">Voornaam</label>
<input class="form-control" name="voornaam" id="voornaam" type="text">
</div>
<div class="form-group">
<label for="achternaam">Achternaam</label>
<input class="form-control" name="achternaam" id="achternaam" type="text">
</div>
<div class="form-group">
<label for="achternaam">Straat en huisnummer</label>
<input class="form-control" name="straat" id="straat" type="text">
</div>
<div class="form-group">
<input class="form-control" name="huisnummer" id="huisnummer" type="text">
</div>
<div class="form-group">
<label for="huisnummer">Huisnummer</label>
<input class="form-control" name="huisnummer" id="huisnummer">
</div>
<div class="form-group">
<label for="postcode">Postcode</label>
<input class="form-control" name="postcode" id="postcode">
</div>
<div class="form-group">
<label for="woonplaats">Woonplaats</label>
<input class="form-control" name="woonplaats" id="woonplaats">
</div>
<div class="form-group">
<label for="email">Email adres</label>
<input class="form-control" name="email" id="email" type="emai">
</div>
<div class="form-group">
<label for="wachtwoord">Wachtwoord</label>
<input class="form-control" name="wachtwoord" id="wachtwoord" type="password">
</div>
<div class="form-group">
<label for="wachtwoord">Herhaal wachtwoord</label>
<input class="form-control" name="wachtwoord2" id="wachtwoord" type="password">
</div>
<div class="form-group">
<label for="profiel_foto">Profiel foto</label>
<input class="form-control" type="file" name="profiel_foto" id="profiel_foto">
</div>
<div class="form-group">
<label for="beschrijving">Beschrijving</label>
<input class="form-control" name="beschrijving" id="beschrijving">
</div>
<div class="form-group">
<label for="geboortedatum">Geboortedatum</label>
<input class="form-control" name="geboortedatum" id="geboortedatum" type="date">
</div>
<div class="form-group">
<label for="geslacht">Geslacht</label>
<select class="form-control" id="geslacht" name="geslacht">
<option value="Man">Man</option>
<option value="Vrouw">Vrouw</option>
</select>
</div>
<div>
<button class="btn btn-primary" name="register">Registreren</button>
</div>
</form>
This is the register code in the controller:
public function register() {
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
$this->input->post('profiel_foto');
$data_upload_files = $this->upload->data();
$image = $data_upload_files['./upload/'];
//voeg gebruiker toe aan database
$data = array(
'voornaam' => $_POST['voornaam'],
'achternaam' => $_POST['achternaam'],
'email' => $_POST['email'],
'wachtwoord' => ($_POST['wachtwoord']),
'startdatum' => date('Y-m-d'),
'postcode' => $_POST['postcode'],
'huisnummer' => $_POST['huisnummer'],
'woonplaats' => $_POST['woonplaats'],
'beschrijving' => $_POST['beschrijving'],
'geboortedatum' => $_POST['geboortedatum'],
'geslacht' => $_POST['geslacht'],
'profiel_foto' => $image
);
$this->db->insert('users', $data);
$this->session->set_flashdata("success", "Uw account is nu geregistreerd, u kunt nu inloggen");
redirect("auth/register", "refresh");
}
And these are the 2 errors I'm getting when I'm trying to registrate:
PHP Error was encountered
Severity: Notice
Message: Undefined index: ./upload/
Filename: controllers/Auth.php
Line Number: 131
Backtrace:
File: /home/ubuntu/workspace/application/controllers/Auth.php
Line: 131
Function: _error_handler
File: /home/ubuntu/workspace/index.php
Line: 315
Function: require_once
A Database Error Occurred
Error Number: 1048
Column 'profiel_foto' cannot be null
INSERT INTO `users` (`voornaam`, `achternaam`, `email`, `wachtwoord`, `startdatum`, `postcode`, `huisnummer`, `woonplaats`, `beschrijving`, `geboortedatum`, `geslacht`, `profiel_foto`) VALUES ('hallo', 'hallo', 'hallo#gmail.com', 'hallo', '2017-06-28', 'hallo', 'hallo', 'hallo', 'hallo', '2017-06-10', 'Man', NULL)
Filename: controllers/Auth.php
Line Number: 149
Your First error is being caused by:
$image = $data_upload_files['./upload/'];
As stated './upload/' is not a valid index nor is an existing one in that array. It's not clear where you have defined that.
Next: What does this line do?
$this->input->post('profiel_foto');
Next: Debug: Inspect your array $data prior to the insert and check it.
// Snip of other code
$data = array(
'voornaam' => $_POST['voornaam'],
'achternaam' => $_POST['achternaam'],
'email' => $_POST['email'],
'wachtwoord' => ($_POST['wachtwoord']),
'startdatum' => date('Y-m-d'),
'postcode' => $_POST['postcode'],
'huisnummer' => $_POST['huisnummer'],
'woonplaats' => $_POST['woonplaats'],
'beschrijving' => $_POST['beschrijving'],
'geboortedatum' => $_POST['geboortedatum'],
'geslacht' => $_POST['geslacht'],
'profiel_foto' => $image
);
$this->db->insert('users', $data);
var_dump($data);
exit();
// Snip of other code
And read the user guide as I stated above in my comments... Cause I aint writing that out here for you... That should get you started.
I want to update user data in the Code-igniter (user details)
below is my code for more checking . please check it out why I get error when i push "update" button.
note: I used some of these information in my view that I didn't copied theme for now (no need in-fact )
controller:
public function edit(){
//validation form
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('email','Email','trim|required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('username','Username','trim|required|min_length[3]|max_length[16]');
$this->form_validation->set_rules('password','Password','trim|min_length[3]|max_length[50]');
$this->form_validation->set_rules('password2','Confirm Password','trim|matches[password]');
$this->form_validation->set_rules('cellphone','Cellphone Number','trim|required');
$this->form_validation->set_rules('activation_code','Activation Code','trim');
//$data['groups'] = $this->User_model->get_groups();
//$data['user'] = $this->User_model->get_user($uid);
if($this->form_validation->run() == FALSE) {
//view
$data = array(
'userid' => $this->session->userdata('user_id')->id,
'first_name' => $this->session->userdata('user_id')->first_name,
'last_name' => $this->session->userdata('user_id')->last_name,
'fathers_name' => $this->session->userdata('user_id')->fathers_name,
'id_card_number' => $this->session->userdata('user_id')->id_card_number,
'national_number' => $this->session->userdata('user_id')->national_code,
'national_code' => $this->session->userdata('user_id')->national_code,
'age' => $this->session->userdata('user_id')->age,
'gender' => $this->session->userdata('user_id')->gender,
'is_addict' => $this->session->userdata('user_id')->is_addict,
'hiv_status' => $this->session->userdata('user_id')->hiv_status,
'hepatitis_status' => $this->session->userdata('user_id')->hepatitis_status,
'email' => $this->session->userdata('user_id')->email,
'needed_services' => $this->session->userdata('user_id')->needed_services,
'username' => $this->session->userdata('user_id')->username,
);
//$data['last_name'] = $this->session->userdata('user_id')->last_name;
//$data['data'] = $this->Profile_Model->get_user_profile();
//$this->base->set_message($msg,$type);
redirect(site_url('admin/profile'),'refresh');
$data['courses'] = $this->Profile_Model->get_user_profile();
//load view
$data['main_content'] = 'profile/index';
$this->load->view('profile/layouts/main', $data);
}else{
//create articles data array
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'cellphone' => $this->input->post('cellphone'),
'group_id' => 2,
);
if($this->input->post('user_id') == $this->session->userdata('user_id')->id){
$uid = $this->input->post('user_id');
}
$password = $this->input->post('password');
$password2 = $this->input->post('password2');
if($password != '' && $password = $password2 ){
$data['password'] = md5($this->input->post('password'));
}
if($this->input->post('activation_code') !=''){
$data['activation_code'] = $this->input->post('activation_code');
}
$this->Profile_Model->update($data, $uid);
//Create Message
$this->session->set_flashdata('User_saved','You have successfully registered');
//redirect to page
redirect('admin/profile');
}
}
also below is my model snippet code:
model:
public function update($data, $uid)
{
$this->db->where('id', $uid);
$result = $this->db->update($this->table_users, $data);
return $result;
}
and below is my view form:
view:
<?php echo form_open(base_url('admin/profile/edit'),'class="form-horizontal"');?>
<?php $uid = $this->session->userdata('user_id')->id;
$uid = intval($uid);
?>
<div class="form-group">
<label class="col-sm-1 control-label" for="first_name">نام</label>
<input type="hidden" name="user_id" value="<?php echo $uid;?>">
<div class="col-sm-5">
<input type="text" id="first_name" name="first_name" class="form-control" value="<?php echo set_value('first_name',$first_name);?>">
</div>
<label class="col-sm-1 control-label" for="last_name">نام خانوادگی</label>
<div class="col-sm-5">
<input type="text" id="last_name" name="last_name" class="form-control" value="<?php echo set_value('last_name',$last_name);?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-1 control-label" for="email">ایمیل</label>
<div class="col-sm-5">
<input type="email" id="email" name="email" class="form-control" value="<?php /** #var dbObject $email */
echo set_value('email',$email);?>">
</div>
<label class="col-sm-1 control-label" for="username">نام کاربری</label>
<div class="col-sm-5">
<input type="text" class="form-control" value="<?php echo $username;?>" disabled aria-disabled="true" title="You cant't change your username" />
</div>
</div>
<div class="form-group">
<label class="col-sm-1 control-label" for="password">رمز ورود</label>
<div class="col-sm-5">
<input type="password" id="password" name="password" class="form-control">
</div>
<label class="col-sm-1 control-label" for="password2">تایید رمز</label>
<div class="col-sm-5">
<input type="password" id="password2" name="password2" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-1 control-label" for="cellphone">شماره تلفن همراه</label>
<div class="col-sm-5">
<input type="tel" id="cellphone" name="cellphone" class="form-control">
</div>
<label class="col-sm-1 control-label" for="cellphone_activation">کد تایید پیامکی</label>
<div class="col-sm-5">
<input type="text" id="cellphone_activation" name="cellphone_activation" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-sm-5 col-sm-offset-1">
<p>
<button class="btn mybtn btn-custom" type="submit">ویرایش</button>
</p>
</div>
</div>
<?php echo form_close();?>
Model Should be like this write table name instead of $this->table_users
public function update($data, $uid)
{
$this->db->where('id', $uid);
$result = $this->db->update(user, $data);
return $result;
}
I am trying to upload image to the folder on the server and store another data in the databse from the same form simultaneously. But it is showing error You did not select a file to upload.
Below is my view and controller for the same:
View:
<form role="form" method="post" action="job_insert" enctype="multipart/form-data">
<div class="box-body">
<div class="form-group">
<label>Job Name*</label>
<input type="text" class="form-control" name="jname" placeholder="Enter Job Name" required>
</div>
<div class="form-group">
<label>Description</label>
<textarea rows="4" cols="10" class="form-control" name="description" required></textarea>
</div>
<div class="form-group">
<label>File input</label>
<input type="file" name="userimage">
</div>
<div class="form-group">
<label>Paper Size*</label>
<div class="form-group">
<label>Paper Cutting Size</label>
<div>
<input id="cutting_size" name="cutting_size" type="text" placeholder="Cutting Size" class="form-control input-md" required>
</div>
</div>
<div class="form-group">
<label>Sheet</label>
<div>
<input id="sheet" name="sheet" type="text" placeholder="No. of Sheet" class="form-control input-md" required>
</div>
</div>
<div class="form-group">
<label>Tin No.</label>
<div>
<input id="sheet" name="tin" type="text" placeholder="Tin No." class="form-control input-md" required>
</div>
</div>
</div>
<!-- /.box-body -->
<div style="margin-left: 600px" class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
Controller:
public function job_insert()
{
$this->form_validation->set_rules('jname', 'job_name', 'trim');
if($this->form_validation->run()== FALSE)
{
$this->load->view('invalid_jobname');
}
else
{
$this->do_upload();
$data = $_SESSION['email'];
$id = $this->user_model->get_client_id($data);
$data = array('cid' => $id,
'job_name' => $this->input->post("jname"),
'job_id' => $this->input->post("job_id"),
'description' => $this->input->post("description"),
'img_name' => $img_name,
'adate' => Date('Y-m-d'),
'status' => 'NEW',
'paper_size' => $this->input->post("paper_size"),
'paper_type' => $this->input->post("paper_type"),
'cutting_size'=> $this->input->post("cutting_size"),
'sheet'=> $this->input->post("sheet"),
'tin' => $this->input->post("tin"),
'lamination' => $this->input->post("checkboxes"),
'print_type' => $this->input->post("checkboxes1"),
'binding' => $this->input->post("checkboxes2"),
);
$query = $this->user_model->job_insert($data);
if ($query == TRUE)
{
$this->load->view('job_submitted');
}
else
{
$this->load->view('error_page');
}
}
}
Here's my do_upload function:
public function do_upload()
{
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => FALSE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
$image = $this->input->post("image");
echo $image;
if(!$this->upload->do_upload('userimage'))
{
$error = $this->upload->display_errors();
echo $error;
}
}
Change this to
<input type="file" name="image">
to
<input type="file" name="userfile"/>
and in do_upload
if(!$this->upload->do_upload())
to
if ( ! $this->upload->do_upload('userfile'))
Provide enctype="multipart/form-data" in your form tag. Without it you cannot upload image.
update form tag with below code
<form role="form" method="post" action="job_insert" enctype="multipart/form-data">
I want to display a form via shortcode in wordpress and when the user submits the entry, some of the information should be send to an api and some should be stored in the database:
<?php
function form($atts, $content = null) {
extract( shortcode_atts( array(
), $atts ) );
echo '
<form id="trello" class="form-horizontal" method="post">
<div class="form-group">
<div class="col-md-6">
<input type="text" name="name" placeholder="Name" class="form-control"/>
</div>
<div class="col-md-6">
<input type="email" name="email" placeholder="eMail" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="text" name="title" placeholder="Title" class="form-control" required/>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea name="content" cols="40" rows="10" placeholder="Content" class="form-control" required></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="file" name="attachment" class="form-control">
</div>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="notification"> Get an email, if something happens to the card
</label>
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit">
</div>
</form>';
if (isset($_POST['title'])) { $title = $_POST['title']; };
if (isset($_POST['content'])) {$content = $_POST['content']; };
if (isset($_POST['name'])) {$name = $_POST['name']; };
if (isset($_POST['email'])) {$email = $_POST['email']; };
if (isset($_POST['attachment'])) {$file = $_POST['attachment']; };
if (isset($_POST['notification'])) {$notification = $_POST['notification']; };
if(isset($_POST['submit'])) {
trello_handler($title, $content, $name, $email, $file);
db_save($email, $notification);
}
}
add_shortcode('form', 'form');
the trello handler and the db_save looks like this:
function trello_handler($title, $content, $name, $email, $file) {
$titan = TitanFramework::getInstance( 'trello-tools' );
$key = $titan->getOption( 'trello_key' );
$token = $titan->getOption( 'trello_token' );
$trello = new Trello($key, null, $token);
$desc = $content."\r\n Reported by ".$name." (".$email.")";
$trello->actions->post("cards", json_encode(['name' => $title, 'desc' => $desc, 'idList' => "54f882603b3b0af795078283", 'pos' => "top", 'fileSource' => $file ]));
}
function db_save($email, $notification) {
global $wpdb;
$table_name = $wpdb->prefix . 'trello_submits';
$wpdb->insert(
$table_name,
array(
'email' => $email,
'notification' => $notification,
)
);
}
The problem is, that when I press the submit button, the page reloads and it displays a 404 error (the url is exactly the same) and no database entries are saved.
(The trello thing is managed by this framework: https://bitbucket.org/mattzuba/php-trello and settings by http://www.titanframework.net)
Can somebody tell me, why the form isn't correct submitted?
Figured out what the problem was:
https://wordpress.org/support/topic/404-pops-after-custom-form-submission-by-post
Wordpress uses "name" intern and therefore this caused the 404 error.
Channing "name" to "clientname" fixed the issue.