How to get all flash messages in Codeigniter? - php

I have a number of fields that have numerous validations from codeigniter validations. but now its showing one single validation error flash that is truly validated message
Here is my controller block code
public function customer_upd()
{
extract($_POST);
$err = '';
$date1 = $_POST['cust_upd_bd'];
$date2 = $_POST['cust_upd_dom'];
if($date2 != "") {
$datediff = (strtotime($date2) - strtotime($date1));
$res = floor($datediff / (60 * 60 * 24));
if ($res == " ") {
$err .= "Please Enter a Date";
} elseif ($res < 365) {
$err .= "Child marriage is prohibited";
}
if ($err != '') {
$_SESSION['dateerror'] = $err;
redirect('customer/edit/'.$_POST['ctmr_upd_id']);
}
}
$original_value1 = $this->db->query("SELECT customer_email FROM customer WHERE id = ".$_POST['ctmr_upd_id'])->row()->customer_email ;
if($_POST['cust_upd_email'] != $original_value1) {
$this->session->set_flashdata('add_failed','Email id must be unique & valid email address.');
$is_unique = '|is_unique[customer.customer_email]';
} else {
$is_unique = '';
}
$original_value2 = $this->db->query("SELECT customer_mobile FROM customer WHERE id = ".$_POST['ctmr_upd_id'])->row()->customer_mobile ;
if($_POST['cust_upd_mobile'] != $original_value2) {
$this->session->set_flashdata('add_failed','Mobile no must be unique & exact 10 digit numeric length. ');
$is_phoneunique = '|is_unique[customer.customer_mobile]';
} else {
$is_phoneunique = '';
}
$this->form_validation->set_rules('cust_upd_email', 'Email', 'required|valid_email|trim'.$is_unique);
$this->form_validation->set_rules('cust_upd_mobile', 'Mobile', 'required|exact_length[10]|is_natural|trim'.$is_phoneunique);
$this->form_validation->set_rules('cust_upd_name', 'Customer name', 'trim|required|min_length[3]|callback_customAlpha');
$this->session->set_flashdata('cust','The Customer field must be at least 3 characters in length. ');
$this->form_validation->set_rules('cust_upd_bd', 'Date of birth', 'regex_match[(0[1-9]|1[0-9]|2[0-9]|3(0|1))-(0[1-9]|1[0-2])-\d{4}]');
$this->form_validation->set_rules('cust_upd_dom', 'Date of marriage', 'regex_match[(0[1-9]|1[0-9]|2[0-9]|3(0|1))-(0[1-9]|1[0-2])-\d{4}]');
if ($this->form_validation->run() ) {
$userdata = $this->session->userdata();
$userId = $userdata['id'];
if (!$userId):
redirect(site_url());
endif;
extract($_POST);
print_r($_POST); exit;
$data = array(
'customer_name' => ucwords($_POST['cust_upd_name']),
'birth_date' => $_POST['cust_upd_bd'],
'anniversery_date' => $_POST['cust_upd_dom'],
'customer_mobile' => $_POST['cust_upd_mobile'],
'customer_email' => $_POST['cust_upd_email'],
'status' => $_POST['cust_upd_status'],
'address' => $_POST['ctmr_address'],
'cat_type' => $_POST['file_cat']
);
$userdata = $this->session->userdata();
$userId = $userdata['id'];
$this->db->where('user_id', $userId);
$this->db->where('id', $_POST['file_cat']);
$this->db->where('cat_status', 'Enable');
$get_file = $this->db->get('category');
$res_file = $get_file->num_rows();
if($res_file >0){
$userdata = $this->session->userdata();
$userId = $userdata['id'];
$this->db->where('user_id', $userId);
$this->db->where('id', $_POST['ctmr_upd_id']);
$ctmr_upd = $this->db->update('customer', $data);
} else {
$this->session->set_flashdata('edit_failed','Something went wrong.');
redirect('customer/edit/'.$_POST['ctmr_upd_id']);
}
redirect(site_url() . '/customer');
} else {
redirect('customer/edit/'.$_POST['ctmr_upd_id']);
}
}
And here is my view code
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<?php if($error = $this->session->flashdata('add_failed')): ?>
<div class="row">
<div class="col-lg-9">
<div class="alert alert-dismissible alert-danger col-md-offset-4">
<?php echo $error; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if($error1 = $this->session->flashdata('edit_failed')): ?>
<div class="row">
<div class="col-lg-9">
<div class="alert alert-dismissible alert-danger col-md-offset-4">
<?php echo $error1; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if($error2 = $this->session->flashdata('cust')): ?>
<div class="row">
<div class="col-lg-9">
<div class="alert alert-dismissible alert-danger col-md-offset-4">
<?php echo $error2; ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if($_SESSION['dateerror']){
echo '<div class="alert alert-danger col-sm-7 col-md-offset-3" role="alert">'.$_SESSION['dateerror'].'</div>';
unset($_SESSION['dateerror']);
}
?>
And here is a snap
Whenever i tries to submit with their validate data, its showing this above error flash message.
i tried many times but unable to achieve any success.
Please guide me and tell me where am i going wrong?

Use below mentioned code to retrieve all flashdata.
$this->session->flashdata();
It will return array with all flashdata, simply omit the key parameter.
Let me know if it not works.

Related

Register page not store data in the database

I have a problem with the register page in PHP language. When I click the submit button the form is submitting but no data is storing in the database. And can not use the registered user to login into the site. The same codes are working properly in the local server (Wampp server) but not working in the website.
these are the codes:
<?php
require_once("../includes/functions.php");
$sess_start->start_session(false);
if(check_login(1, $sess_start->get_dbhandler()) == true)
{
header('Location: userportal.php');
}
else
{
if (!empty($_POST['RegisterFname']) || !empty($_POST['RegisterLname']) || !empty($_POST['RegisterEmail']) || !empty($_POST['RegisterUsername']) || !empty($_POST['RegisterPassword']) || !empty($_POST['RegisterRPassword']) || !empty($_POST['RegisterDob']) || !empty($_POST['RegisterAddress']) || !empty($_POST['RegisterRegion']) || !empty($_POST['RegisterCountry']) || !empty($_POST['RegisterPhone']))
{
if (!empty($_POST['RegisterFname']) && !empty($_POST['RegisterLname']) && !empty($_POST['RegisterEmail']) && !empty($_POST['RegisterUsername']) && !empty($_POST['RegisterPassword']) && !empty($_POST['RegisterRPassword']) && !empty($_POST['RegisterDob']) && !empty($_POST['RegisterAddress']) && !empty($_POST['RegisterRegion']) && !empty($_POST['RegisterCountry']) && !empty($_POST['RegisterPhone']))
{
if (($_POST['RegisterPassword'] == $_POST['RegisterRPassword']))
{
if (strlen($_POST['RegisterRPassword']) >= 8)
{
$registeruser = new user();
$registeruser->nickname = clean_string($sess_start->get_dbhandler(), $_POST['RegisterUsername']);
$registeruser->sql = mysqli_query($sess_start->get_dbhandler(), "SELECT * FROM `users` WHERE n_name = '$registeruser->nickname'");
if (mysqli_num_rows($registeruser->sql) == 0)
{
$registeruser->fname = clean_string($sess_start->get_dbhandler(), $_POST['RegisterFname']);
$registeruser->lname = clean_string($sess_start->get_dbhandler(), $_POST['RegisterLname']);
$registeruser->email = clean_string($sess_start->get_dbhandler(), $_POST['RegisterEmail']);
$registeruser->password = $_POST['RegisterRPassword'];
$registeruser->password = hash('sha512', $registeruser->password);
$registeruser->dob = clean_string($sess_start->get_dbhandler(), $_POST['RegisterDob']);
$registeruser->addr = clean_string($sess_start->get_dbhandler(), $_POST['RegisterAddress']);
$registeruser->state = clean_string($sess_start->get_dbhandler(), $_POST['RegisterRegion']);
$registeruser->country = clean_string($sess_start->get_dbhandler(), $_POST['RegisterCountry']);
$registeruser->phone = clean_string($sess_start->get_dbhandler(), $_POST['RegisterPhone']);
$registeruser->regtime = time();
$registeruser->sql = mysqli_query($sess_start->get_dbhandler(), "INSERT INTO `users` (f_name, l_name, email, n_name, password, age, addr, state, country, phone, l_login, r_time) VALUES ('$registeruser->fname', '$registeruser->lname', '$registeruser->email', '$registeruser->nickname', '$registeruser->password', '$registeruser->dob', '$registeruser->addr', '$registeruser->state', '$registeruser->country', '$registeruser->phone', '0', '$registeruser->regtime')");
if (!empty($_GET['RegisterPromo']))
{
$registeruser->coupon = clean_string($sess_start->get_dbhandler(), $_POST['RegisterPromo']);
$registeruser->sql = mysqli_query($sess_start->get_dbhandler(), "UPDATE `users` SET promo = '$registeruser->coupon' WHERE n_name = '$registeruser->nickname'");
}
$_SESSION['RegisterUserError'] = 5;
header('Location: register.php');
}
else
{
$_SESSION['RegisterUserError'] = 4;
header('Location: register.php');
}
}
else
{
$_SESSION['RegisterUserError'] = 3;
header('Location: register.php');
}
}
else
{
$_SESSION['RegisterUserError'] = 2;
header('Location: register.php');
}
}
else
{
$_SESSION['RegisterUserError'] = 1;
header('Location: register.php');
}
}
else
{
echo '
meta tages and links for the stylesheets
';
?>
<?php
?>
<div class="container" id="registration-form">
<div class="image"></div>
<form role="form" class="form-signin" method="post" action="<?php echo clean_url($_SERVER['PHP_SELF']); ?>">
<section class="panel">
<div class="panel-body">
<?php
if (isset($_SESSION['RegisterUserError']))
{
if ($_SESSION['RegisterUserError'] == 1)
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>Fill all mandatory fields(*) for completing user registeration</strong>
</div>
<?php
}
else if ($_SESSION['RegisterUserError'] == 2)
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>Entered passwords do not match</strong>
</div>
<?php
}
else if ($_SESSION['RegisterUserError'] == 3)
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>Passwords must be 8 or more character longer</strong>
</div>
<?php
}
else if ($_SESSION['RegisterUserError'] == 4)
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>There is already a user exist with this same username</strong>
</div>
<?php
}
else if ($_SESSION['RegisterUserError'] == 5)
{
?>
<div class="alert alert-success fade in">
<strong>Successfully completed the user registeration. However, your account is not verified unless you complete "Know your customer" process after login to your account.</strong>
</div>
<?php
}
else
{
?>
<div class="alert alert-block alert-danger fade in">
<strong>Unexpected error occured</strong>
</div>
<?php
}
unset($_SESSION['RegisterUserError']);
}
else
{
?>
<div class="alert alert-success fade in">
<strong>Fields indicated using * are mandatory in registeration</strong>
</div>
<?php
}
?>
<div class="frm">
inputs here
</form>
<div class="form-footer">
<div class="row">
<div class="col-xs-5 col-sm-5 col-md-5">
<i class="fa fa-check"></i> Sign In
</div>
</div>
</div>
</div>
</div>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
<?php
}
}
?>
if it is working on your local server, then check your web hosting service. Most Service provider will ask you to the these three things :
1.Create the database
2.Create a database user
3.Assign the user to the database
These steps could be confusing depending on your host and is usually carried out in your cpanel database page or use the database creation wizard if available.

PHP Script Loading Forever

This is not a duplicate of Maximum execution time in phpMyadmin; this has nothing to do with phpmyadmin.
On my site, there is a form which sends POST data to a PHP script and loads a new page. When you submit the form, the page loads forever and then results in:
The XXX.XXX page isn’t working XXX.XXX is currently unable to handle
this request. HTTP ERROR 500
I thought it may be a traffic issue so I upgraded my hosting SSD and made the website only available to me to test it, but the problem still persisted. Here is my script:
<?php
$used_file = 'used.txt';
$codes_file = 'codes.txt';
# Generates a random unused code from the code file
function genCode() {
global $used_file, $codes_file;
$codes = file_get_contents($codes_file);
$codes = explode("\n", $codes);
$used = file_get_contents($used_file);
$used = explode("\n", $used);
foreach($codes as $code) {
if(!in_array($code, $used))
return $code;
}
}
# Generate error string from error code
function getError($err) {
switch($err) {
case 1: return 'No submit';
case 2: return 'Wrong password';
case 3: return 'No password';
}
}
# Adds generated code to the 'used' codes file
function append_used($code) {
global $used_file, $codes_file;
$str = $code . '\n';
file_put_contents($used_file, $str, FILE_APPEND);
}
# Get user's IP (for cookie handling)
function getIP() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
# Cookie handling
# Set a cookie for how many times the form has been submitted by user
$used = 0;
if(isset($_COOKIE['used_twice'])) {
$used = 3;
}
if(isset($_COOKIE['used_once']) && !isset($_COOKIE['used_twice'])) {
setcookie('used_twice', getIP(), time()+18000);
$used = 2;
}
if(!isset($_COOKIE['used_once'])) {
setcookie('used_once', getIP());
$used = 1;
}
# Check if all the POST data is correct
$password = $_POST['inputPassword'];
$submit = $_POST['submit'];
if(isset($password)) {
if($password == 'test123') {
if(isset($submit)) {
$code = genCode();
}
else
$err = 1;
} else
$err = 2;
} else
$err = 3;
# Now generate the new page
include 'web_functions.php';
getHead('Generated', 'Generated code');
getBody('Generated code');
?>
<img src="goback.png"></img>
<h2>Code Generated</h2>
<br/>
<?php
if(!isset($err) && isset($thecode) && $used == 1) {
?>
<center>
<div class="bs-component">
<div class="alert alert-dismissible alert-success">
<p>Your code is: </p> <strong> <?php echo $thecode; append_used($thecode); ?> </strong>
</div>
</div>
</div>
</center>
<?php
} elseif(isset($err)) {
?>
<center>
<div class="bs-component">
<div class="alert alert-dismissible alert-danger">
<p>There was an error:</p> <strong><?php echo getError($err); ?></strong>
</div>
</div>
</div>
</center>
<?php
} elseif(!isset($err) && $used != 1){
?>
<center>
<div class="bs-component">
<div class="alert alert-dismissable alert-danger">
<p>You can only use the code generator once every 5 hours. Please try again later.</p>
</div>
</div>
</div>
</center>
<?php } else { ?>
<div class="bs-component">
<div class="alert alert-dismissable alert-danger">
<p>There was an unexpected error. Please try again.</p>
</div>
</div>
</div>
<?php } ?>
<br/>
<br/>
<br/>
<?php closeTags();
getFooter(); ?>
</div>
</div>
</div>
</div>
What could be causing this issue?
Edit: The error log says:
PHP Fatal error: Maximum execution time of 60 seconds exceeded on line 13
Line 13 is within the foreach loop.

Cannot post radio value in Codeigniter

view:
<?php
$attr_form = array('class' => 'form-horizontal');
echo form_open('login/create', $attr_form); ?>
<div class="form-group">
<label class="col-sm-4 control-label">Gender</label>
<div class="col-sm-4">
<?php echo form_radio('gender', 'M'); ?>
<?php echo form_radio('gender', 'F'); ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<?php
$data_submit = array('class'=> 'btn btn-info', 'name' => 'submit', 'value'=> 'Create Account');
echo form_submit($data_submit);?>
</div>
</div>
controllers:
function create ()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('gender', 'Gender', 'required');
if($this->form_validation->run() == FALSE)
{
$this->signup();
}
else
{
$this->load->model('parents_model');
if($query = $this->parents_model->create_member())
{
$data['main_content'] = 'successful';
$this->load->view('include/template', $data);
}
else
{
$this->signup();
}
}
}
model:
function create_member ()
{
$new_parents = array(
'gender' => $this->input->post('gender')
);
$insert = $this->db->insert('parents', $new_parents);
return $insert;
}
I just simplified the other form inputs.
Can anyone figure out whats wrong with my code? It cannot go to successful page.
Or do I use wrong form_radio code ?
I have tried many times! Please help me....
You have a syntax error.
$this->input->post->('gender')
should be:
$this->input->post('gender')
try this
$gender = $this->input->post('gender')['M'] ? 'M':'F';
$new_parents = array('gender' => $gender);
After I restarted my localhost, everything works again.
Cause I have created a column in the table without restarting!

Getting results from giant query in codeigniter

I've been stuck for about a week now on trying to get some query results in my reply to comments module in codeigniter. I am most certainly able to insert the replies to comments and have them linked to the proper comment.
I am not able to return the results of the replies however. I have based my query structure on the comments results which I'm able to display.
Here is the code:
inserting the replies and trying to pull the results on the controller:
public function insert_airwaves_comments_replies($profile_id)
{
//echo $profile_id;
$this->load->model('account_model');
$this->load->library('session');
$this->load->helper('date');
$user = $this->account_model->user();
$session_id = $this->session->userdata['id'];
$data['user'] = $user;
$this->load->model('community_model');
$this->load->library('form_validation');
$submit = $this->input->post('sub_comment_reply');
$this->load->library('session');
$airwave = $this->community_model->get_airwave_comments($profile_id);
$data['airwave'] = $airwave;
if(isset($submit))
{
foreach($airwave as $airwave_id)
//if($this->form_validation->run() == FALSE)
// {
// $data['main_content'] = 'account/profile';
// $this->load->view('includes/templates/main_page_template', $data);
// }
// else
//{
$save_data = array(
'airwave_id' => $airwave_id['id'],
'from_id' => $session_id,
'comment' => $this->input->post('airwaves_comments_replies'),
'status' => 'active',
'datetime' => date('Y-m-d H:i:s',now())
);
$query = $this->community_model->save_airwaves_comments_replies($profile_id,$save_data);
$airwave_reply = $this->community_model->get_airwaves_comments_replies($profile_id);
$data['airwave_reply'] = $airwave_reply;
redirect('/account/profile/'.$profile_id);
}
//}
}
getting the results from the model:
public function get_airwaves_comments_replies($profile_id)
{
$session = $this->session->userdata('is_logged_in');
$user_id= $this->session->userdata('id');
if($profile_id == $user_id)
{
$comments_query = "SELECT
awr.id AS id,
awr.airwave_id AS airwave_id,
awr.from_id AS from_id,
awr.comment AS comment,
awr.status AS status,
awr.thumbsup_reply AS thumbsup_reply,
awr.datetime AS datetime,
u.first_name AS first_name
FROM
airwaves_comments_replies awr,
users u
WHERE
u.id=awr.from_id
AND awr.from_id =".$profile_id."
order by
awr.datetime
desc" ;
}
else
{
$comments_query = "SELECT awr.id AS id,
awr.airwave_id AS airwave_id,
awr.from_id AS from_id,
awr.comment AS comment,
awr.status AS status,
awr.thumbsup_reply AS thumbsup_reply,
awr.datetime AS datetime,
u.first_name AS first_name FROM airwaves_comments_replies awr,users u WHERE u.id = awr.from_id AND awr.from_id =".$profile_id." order by awr.datetime desc" ;
}
$query = $this->db->query($comments_query);
if($query->num_rows() >= 1)
{
$data = $query->result_array();
// return whole resultset. It contains zero, one or more records
return $data;
}
else return false;
}
displaying the results in my view:
if ($airwave_reply)
{
foreach ($airwave_reply as $airwave_reply_comment_row)
{ ?>
?>
<?php echo $airwave_reply_comment_row['from_id']; echo "<br />";
echo $airwave_reply_comment_row['first_name'];?>
<div class="response_structure_future">
<a name="response_<?php echo $airwave_reply_comment_row['id']; ?>"></a>
<div class="response_polaroid_future">
<a href="">
<img src='/styles/images/prof_thumbnail_2.jpg'/>
</a>
</div>
<div class="response_body_future">
<div class="response_arrow_future"></div>
<div class="response_tail_future"></div>
<div class="response_data_future">
<div class="response_name_future">
<a href="">
<?php echo $airwave_reply_comment_row['first_name'];?>says...
</a>
</div>
comment here
<div class="respond_info_future">
at <?php echo date('M d, Y',strtotime($airwave_reply_comment_row['datetime'])); ?>
<?php //if($auth->id == $replier->id || $auth->id == $result['ToUserID']) ?>
<a onclick="confirmation('');"> • delete</a>
<?php ?>
<div id="thumb_holder">
<div id="thumb_report">
<a href="mailto:info#cysticlife.org">
report
</a>
</div>
<div class= "thumb_counter" id="thumb_counter<?php// echo $reply['id']; ?>">
+<?php //echo $reply['thumbsUp_reply']; ?>
</div>
<div id="thumb_thumb">
<?php $comment_reply_id = $reply['id'];?>
<a class="myButtonLink" href="Profile.php?id=<?php //echo $prof->id; ?>" id="<?php //echo $comment_reply_id; ?>">Vote Up!</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
?>
<a name='reply_form_<?php echo $airwave_comment_row['id']; ?>' style="clear:both"></a>
<div id='reply_to_<?php echo $airwave_comment_row['id']; ?>' class="respond_structure_future" <?php if(isset($_GET['reply_to']) && $_GET['reply_to'] == $airwave_comment_row['id']) { echo 'style="display:block;"';}else{ echo 'style="display:none;"';} ?>>
<div class="response_polaroid_future">
<a href="http://www.cysticlife.org/Profile.php?id=<?php// echo $auth->id; ?>">
<img src="/styles/images/prof_thumbnail_2.jpg" />
</a>
</div>
<?php
echo validation_errors();
echo form_open('community/insert_airwaves_comments_replies/'.$this->uri->segment(3));
?>
<div class="respond_body_future">
<div class="response_arrow_future"></div>
<div class="response_tail_future"></div>
<div class="respond_data_future">
<?php
$data = array('name' => 'airwaves_comments_replies', 'id' => 'reply_to'. $airwave_comment_row['id'].'_textarea', 'class' => 'respond');
echo form_textarea($data, set_value('airwaves_comments_replies'));
$data = array('type' => 'hidden', 'name' => 'comment', 'value' => $airwave_comment_row['id']);
echo form_input($data);
?>
<div class="respond_nevermind">
nevermind
</div>
<?php
echo form_submit('sub_comment_reply', 'Reply');
?>
</div>
</div>
</form>
</div>
please let me know what else you may need to help and thanks in advance.
What is your result right now?
With the code you are showing, your controller inserts the comment replies in a foreach-loop but redirects the user to
redirect('/account/profile/'.$profile_id)
I don't see any code where you call the view to show the comments, so i think we can't help you any further without some more explanation and code.

Simple File Upload for FuelPHP

Does anyone have experience of uploading a series of files to a web server with FuelPHP?
My current setup adds content to a database from a Form, but I'd like to process images at this point too - so basically move them to my web server when submitting a form.
Is this simple to do?
I have my 'action_add()' method in my controller, but not sure how to update it to loop through all my file fields and move files.
public function action_add()
{
$val = Model_Article::validate('add_article');
if ($val->run())
{
$status = (Input::post('save_draft') ? 0 : 1);
if ( ! $val->input('category_id'))
{
$category_id = null;
}
else
{
$category_id = $val->validated('category_id');
}
$article = new Model_Article(array(
'user_id' => $this->user_id,
'category_id' => $category_id,
'title' => $val->validated('title'),
'body' => $val->validated('body'),
'published' => $status,
));
if ($article->save())
{
Session::set_flash('success', 'Article successfully added.');
}
else
{
Session::set_flash('error', 'Something went wrong, '.
'please try again!');
}
Response::redirect('articles/add');
}
$this->template->title = 'Add Article';
$this->template->content = View::forge('articles/add')
->set('categories', Model_Category::find('all'), false)
->set('val', Validation::instance('add_article'), false);
}
My Form:
<h2>Add an Article</h2>
<p>Publish a new article by filling the form below.</p>
<div class="options">
<div class="option">
<?php echo Html::anchor('articles', 'View Articles'); ?>
</div>
<div class="option">
<?php echo Html::anchor('categories/add', 'Add a Category'); ?>
</div>
</div>
<?php echo $val->show_errors(); ?>
<?php echo Form::open(array('enctype' => 'multipart/form-data')); ?>
<?php $select_categories = array(null => 'Uncategorized'); ?>
<?php foreach ($categories as $category): ?>
<?php $select_categories[$category->id] = $category->name; ?>
<?php endforeach; ?>
<div class="input select">
<?php echo Form::label('Category', 'category_id'); ?>
<?php echo Form::select('category_id', e($val->input('category_id')),
$select_categories); ?>
</div>
<div class="input text required">
<?php echo Form::label('Title', 'title'); ?>
<?php echo Form::input('title', e($val->input('title')),
array('size' => '30')); ?>
</div>
<div class="input textarea required">
<?php echo Form::label('Body', 'body'); ?>
<?php echo Form::textarea('body', e($val->input('body')),
array('rows' => 4, 'cols' => 40)); ?>
</div>
<div class="input textarea required">
<?php echo FORM::file('filename'); ?>
</div>
<div class="input submit">
<?php echo Form::submit('add_article', 'Publish'); ?>
<?php echo Form::submit('save_draft', 'Save Draft'); ?>
</div>
<?php echo Form::close(); ?>
Many thanks for any pointers.
Okay I can give you some instruction.
First fuelphp upload documentation
Hope it helps sorry if there are typos in it
public function action_add()
{
$val = Model_Article::validate('add_article'); //<-- maybe its just me but I never saw any similar to this in fuelphp sorry about this if I'm wrong
// if your form validation is okay than continue with everyhing else
if ($val->run())
{
$article = Model_Article::forge();
// Custom configuration for this upload
$config = array(
'path' => DOCROOT.DS.'foldername/tomove/your/images',
'randomize' => true,
'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
);
Upload::process($config);
// if a valid file is passed than the function will save, or if its not empty
if (Upload::is_valid())
{
// save them according to the config
Upload::save();
//if you want to save to tha database lets grab the file name
$value = Upload::get_files();
$article->your_file_input_name = $value[0]['saved_as'];
}
$status = (Input::post('save_draft') ? 0 : 1);
if ( ! $val->input('category_id'))
{
$category_id = null;
}
else
{
$category_id = $val->validated('category_id');
}
$article->user_id = $this->user_id;
$article->category_i = $category_id;
$article->title = $val->validated('title');
$article->body = $val->validated('body');
$article->published = $status;
if ($article->save())
{
Session::set_flash('success', 'Article successfully added.');
}
else
{
Session::set_flash('error', 'Something went wrong, '.
'please try again!');
}
Response::redirect('articles/add');
}
$this->template->title = 'Add Article';
$this->template->content = View::forge('articles/add')
->set('categories', Model_Category::find('all'), false)
->set('val', Validation::instance('add_article'), false);
}

Categories