Been working on this form for a while and I had it working properly. But I then re-did the form using the form helper in CodeIgniter and now when I click the submit button does nothing. Not even a refresh. I've tested my controller so I'm stuck for what it could be.
<?php
echo form_open('site/inputWorker');
echo form_label('Forename:', 'Forename');
echo form_input('Forename');
echo "<br>";
echo form_label('Surname:', 'Surname');
echo form_input('Surname');
echo "<br>";
echo form_label('Skill1:', 'Skill1');
echo form_dropdown('Skill1', $skills, 'None');
echo "<br>";
echo form_label('Skill2:', 'Skill2');
echo form_dropdown('Skill2', $skills, 'None');
echo "<br>";
echo form_label('Skill3:', 'Skill3');
echo form_dropdown('Skill3', $skills, 'None');
echo "<br>";
echo form_label('Availability:', 'Availability');
echo form_dropdown('Availability', $availability, 'None');
echo "<br>";
echo form_submit('Add Worker', 'Add Worker');
echo form_close();
?>
//Add a New Worker
public function inputWorker(){
$Forename=$this->input->post('Forename');
$Surname=$this->input->post('Surname');
$Skill1=$this->input->post('Skill1');
$Skill2=$this->input->post('Skill2');
$Skill3=$this->input->post('Skill3');
$Availability=$this->input->post('Availability');
$this->load->model("model_worker");
if($this->model_worker->insert_worker($Forename, $Surname, $Skill1, $Skill2, $Skill3, $Availability)){
$data['msg']="Sucessfully added the worker";
}
else{
$data['msg']="Something went wrong";
}
$this->load->view("view_confirmation", $data);
}
$forname = array(
'name' => 'forname',
'id' => 'forname',
'value' => '',
);
echo form_input('Forename');
Related
I need to get the value of a checkbox called Password using the Yii2 Framework, in the controller.
In my _form.php I define the checkbox:
<?= Html::checkbox('password', false, $options = ['label' => 'Reset password']) ?>
In my UserController.php I have the actionUpdate function:
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
echo '<pre>';
echo Yii::$app->request->post()['password'];
echo '</pre>';
return $this->render('update', [
'model' => $model,
]);
}
}
I always get the value 1 instead of true or false.
First of all, there is error in your code, it should be:
<?= Html::checkbox('password', false, ['label' => 'Reset password']) ?>
This checkbox generates 1 when checked by default. If you want to send 0 when checkbox is not selected you must add:
<?= Html::checkbox('password', false, ['label' => 'Reset password', 'uncheck' => 0]) ?>
Checkbox return 1 for true(checked) and return 0 for false(not checked).
You can check in controller as below
if(isset($model->password) && $model->password =="1") //check box is checked
{
// code
}
i have a login method but it doesn't seems to work correctly. For example if i try to login with a username that exists in the database and the password of another user, i can successfully login. Can someone spot the error in my code?
Controller:
public function login(){
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('', '');
$this->form_validation->set_rules('name_login', 'Utilizator', 'required|callback_validate_login|xss_clean|trim');
$this->form_validation->set_rules('password_login', 'Password', 'required|xss_clean|trim');
$this->form_validation->set_message('validate_login','login esuat');
$this->form_validation->set_message('required', '*');
if ($this->form_validation->run() === FALSE){
$this->render('login');
}
else {
// user successful login
$data = array(
'username' => $this->input->post('name_login'),
'is_logged_in' => 1
);
$this->session->set_userdata($data);
$this->load->view('homeview',$data);
}
}
public function validate_login(){
$username = $this->input->post('user_login');
$pass = $this->input->post('password_login');
if ($this->homemodel->login($username,$pass)){
return true;// form validation passed, u are now logged in
}
else {
return false;
}
}
Model:
public function login($user, $pass)
{
$query = $this->db->get_where('login', array('username' => $user, 'password' => $pass));
echo '<pre>';
print_r($query->result());
echo '</pre>';
if ($query->num_rows() === 1) {
return true;
} else {
return false;
}
View
<?php echo form_open('home/login') ?>
<label for="user">Username</label>
<input type="text" class="createform" name="user_login" value="<?php echo set_value('name_login'); ?> " />
<?php echo form_error('name_login') . '<br>'; ?>
<label for="pass">Password</label>
<input type="text" class="createform" name="password_login" value="<?php echo set_value('password_login'); ?> " />
<?php echo form_error('password_login') . '<br>'; ?>
<input type="submit" name="submit" value="Login" />
</form>
Oh,my bad, found the error : the username input name in the view file is "user_login" and in the controller i wrote 'name_login':
$this->form_validation->set_rules('name_login',...)
It looks like you are setting the session data to is_logged_in just on successful form submission:
if ($this->form_validation->run() === FALSE){
$this->render('login');
}
else {
// user successful login
$data = array(
'username' => $this->input->post('name_login'),
'is_logged_in' => 1
);
You need to validate the user first.
I would try something like:
if ($this->form_validation->run() === FALSE){
$this->render('login');
}
else {
$results = $this->validate_login();
// user successful login
if ($results){
$data = array(
'username' => $this->input->post('name_login'),
'is_logged_in' => 1
);
$this->session->set_userdata($data);
$this->load->view('homeview',$data);
}
else {
redirect('login');
}
}
Does that make sense? It doesn't look like you were actually checking or calling the validate_login() method.
i want to get all the orders from all the customers on admin side to export them in csv, but i am having problems getting them, in the foreach below dont know why it does not convert $collection to $col and give me the instance, can you help me please?
require_once('app/Mage.php');
Mage::app('admin');
Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*');
$min_diff = '60';
$from_date = date("Y-m-d H:i:s", strtotime("-".$min_diff." minute"));
$to_date = date("Y-m-d H:i:s");
$collection->addAttributeToFilter('updated_at', array(
'from' => $from_date,
'to' => $to_date
));
Mage::log("80",null,"ordenes.log");
foreach ($collection as $col) { //falls here Mage::log($col,null,"ordenes.log");
echo '<tr>';
echo "<td>".$col->getIncrementId()."</td>";
echo "<td>".$col->getCreatedAt()."</td>";
echo "<td>".$col->getUpdatedAt()."</td>";
echo "<td>".$col->getState()."</td>";
echo "<td>".$col->getStatus()."</td>";
echo "<td>".$col->getHpcOrderId()."</td>";
echo "<td>".$col->getHpcOrderFrom()."</td>";
echo '</tr>';
}
echo '</table>';
echo "<br />supplement order ends";
The Problem is in your addAttributeToFilter() filter. The collection is getting empty data.
If you remove date filter then your code is working. Or try to increase the From & To date difference.
require_once('app/Mage.php');
Mage::app('admin');
Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*');
$min_diff = '60';
$from_date = date("Y-m-d H:i:s", strtotime("-".$min_diff." minute"));
$to_date = date("Y-m-d H:i:s");
/*$collection->addAttributeToFilter('updated_at', array(
'from' => $from_date,
'to' => $to_date
));*/
Mage::log("80",null,"ordenes.log");
foreach ($collection as $col) { //falls here Mage::log($col,null,"ordenes.log");
echo '<tr>';
echo "<td>".$col->getIncrementId()."</td>";
echo "<td>".$col->getCreatedAt()."</td>";
echo "<td>".$col->getUpdatedAt()."</td>";
echo "<td>".$col->getState()."</td>";
echo "<td>".$col->getStatus()."</td>";
echo "<td>".$col->getHpcOrderId()."</td>";
echo "<td>".$col->getHpcOrderFrom()."</td>";
echo '</tr>';
}
echo '</table>';
echo "<br />supplement order ends";
In Zend Framework I'm trying to display an image through my controller.
class PictController extends Zend_Controller_Action
{
public function indexAction()
{
$objpict = new Application_Model_Page();
$objpict->CheminPictures(Application_Model_String::ExtractNamePict($this->getParam('niveau0')));
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->getHelper('layout')->disableLayout();
header('Content-Type: image/jpeg');
header('Content-Length: ' . filesize($file));
echo file_get_contents($file);
exit;
}
}
A road was also created, but it is not taken into account either!
$routeRegex = new Zend_Controller_Router_Route_Regex(
'img/([a-z-0-9-/-]+).jpg',
array('controller' =>'pict','action' => 'index'),
array(1 => 'niveau0',2 => 'niveau1',3 => 'niveau2'),'img/%s.jpg');
$this->_routeur->addRoute('routeimage', $routeRegex);
This does not work. It returns me the url of my page ...
<img alt="montitre" src="<?php echo $this->url(array('controller' => 'pict', 'action' => 'index')); ?>" >
How to call the controller from my sight so that it returns me the information?
Thank'you very much !
++
ps: sorry for English
I have a set of validation rules I am imposing on my model in Cakephp 2.0 and since they are all for fields that deal with web addresses, they are exactly the same. Cut and pasted exact. However, when I modify my db in my edit form, only the first rule works; all the others validate and update my record. Here is my model code:
public $validate=array(
'unit_website'=>array(
'rule'=>'url',
'message'=>'You must enter a valid website address.'
),
'rates'=>array(
'rule'=>'url',
'message'=>'You must enter a valid website address.'
),
'book'=>array(
'rule'=>'url',
'message'=>'You must enter a valid website address.'
),
'contact'=>array(
'rule'=>'url',
'message'=>'You must enter a valid website address.'
)
);
UPDATE* Here is my form:
<?php
echo $this->Form->create('Unit', array(
'action' => 'edit',
'inputDefaults' => array(
'label' => false,
'div' => false
)
)
);
echo $this->Form->hidden('id');
echo $this->Form->hidden('location_id');
echo $this->Form->hidden('Location.id');
echo $this->Form->hidden('Location.lat');
echo $this->Form->hidden('Location.lon');
echo $this->Form->input('Location.prop_name', array('label'=>'Property name where your unit is located', 'div'=>true));
if($this->data['Unit']['type']=='condo' || $this->data['Unit']['type']=='house') {
echo $this->Form->input('Unit.unitnum', array('label' => 'Unit\'s Name/Number'));
}
echo $this->Form->input('type', array('label'=>'Type of Property', 'onChange'=>'toggle()', 'options'=>array('condo'=>'Condo', 'house'=>'House', 'hotel'=>'Hotel or Motel', 'rentalco'=>'This is a rental company')));
echo $this->Form->input('Location.address', array('onChange'=>'getLatLong(address)', 'size'=>'50', 'div'=>true));
echo $this->Form->input('Location.city', array('onChange'=>'getLatLong(address)'));
echo $this->Form->input('Location.state', array('onChange'=>'getLatLong(address)', 'size'=>'2'));
echo $this->Form->input('Location.zip', array('size'=>'5'));
echo '<br />';
echo $this->Form->input('Location.area_code', array('size'=>'3'));
echo $this->Form->input('Location.exchange', array('size'=>'3'));
echo $this->Form->input('Location.sln', array('size'=>'4'));
echo '<br />';
echo $this->Form->input('unit_website', array('size'=>'65', 'label'=>'Your unit\'s website', 'error' => array('class' => 'error')));
echo '<br />';
echo $this->Form->input('specials', array('label' => 'Your website\'s Specials page', 'size'=>'65', 'error' => array('class' => 'error')));
echo '<br />';
echo $this->Form->input('rates', array('size'=>'65', 'error' => array('class' => 'error'), 'label'=>'Your unit\'s rates page'));
echo '<br />';
echo $this->Form->input('book', array('size'=>'65', 'error' => array('class' => 'error'), 'label'=>'Your unit\'s booking page or calendar'));
echo '<br />';
echo $this->Form->input('contact', array('size'=>'65', 'error' => array('class' => 'error'), 'label'=>'Your unit\'s contact or email page'));
echo '<br />';
if($this->data['Unit']['type']=='condo' || $this->data['Unit']['type']=='house') {
echo '<br /><div id="unit_info">';
echo $this->Form->input('sq_ft', array('label'=>'Square feet', 'min'=>'1000', 'max'=>'10000', 'step'=>'50'));
echo $this->Form->input('bedrooms', array('label'=>'Bedrooms', 'min'=>'1', 'max'=>'15', 'step'=>'1'));
echo $this->Form->input('baths', array('label'=>'Bathrooms', 'min'=>'1', 'max'=>'10', 'step'=>'.5'));
echo $this->Form->input('sleeps', array('label'=>'How many people does your unit sleep?', 'min'=>'1', 'max'=>'45', 'step'=>'1'));
echo '</div><br />';
echo $this->Form->input('unit_desc', array('div'=>true, 'cols'=>'150', 'rows'=>'4', 'label'=>'Describe your unit <span style="font-size:14px; font-style:italic">(Remember to include the sizes of beds in each bedroom, whether you have a sleeper sofa, deluxe kitchens and baths, balconies and their views, access to amenities, and any other items that distinguish your property.)</span>'));
}
else {
echo '<br />';
echo $this->Form->input('unit_desc', array('div'=>true, 'cols'=>'150', 'rows'=>'4', 'label'=>'Describe your hotel or rental company'));
}
echo '<br /> ';
echo $this->Form->end('Update Property');?>
<?php echo $this->Session->flash(); ?>
Does Cake have some sort of "you can only make this rule once" rule? Or do my model field names have to actually have the word website in them or something? Or have I just made some dumb syntax error?
UPDATE Here is my controller code:
function edit($id) {
$this->set('title', 'Edit your property');
$this->Unit->id = $id;
if (empty($this->data)) {
$this->data = $this->Unit->read();
} else {
if ($this->Unit->saveAll($this->data)) {
$this->Session->setFlash('Your property has been updated.', 'success');
}
}
}
What is the URL you are validating and what are you expecting? The url validation will not check for protocol unless you specify it. If you want to make sure http is in the url, you should specify your rule like this:
'rule' => array('url', true)
Please show sample URLs that are passing validation but are not valid.
UPDATE
$this->data should be changed to $this->request->data. This may not change the validation process. But $this->data is deprecated.
Try adding a beforeValidate callback in the Unit model and echo $this->data to see what is coming through.