Insert form information in Database. Magento 1.9 - database

I have some form.
<form action="<?php echo Mage::getUrl('siteblocks/test/test', array('_current' => true,'_use_rewrite' => true))?>" method="post">
<h3>Enter your information</h3>
<p>
<label for="name" class="name" >Customer Name</label>
<input id="customer_name" name="customer_name" required="required" type="text"/>
</p>
<p>
<label for="phone" class="phone" >Customer Phone</label>
<input id="customer_phone" name="customer_phone" required="required" type="text"/>
</p>
<p>
<label for="calltime" class="ctime" >Call Time</label>
<input id="calltime" name="call_time" required="required" type="text"/>
</p>
</form>
Information comes from the form to the controller
class Test_Test_Controller extends Mage_Core_Controller_Front_Action {
public function testAction()
{
$this->getRequest()->getPost();
Mage::getModel('siteblocks/callEntity')->setData($this->getRequest()->getPost())
->save();
}
}
config.xml
<config>
<modules>
<Test_Test>
<version>0.1.0</version>
</Test_Test>
</modules>
<global>
<models>
<siteblocks>
<class>Test_Test_Model</class>
<resourceModel>siteblocks_resource</resourceModel>
</siteblocks>
<siteblocks_resource>
<class>Test_Test_Resourse</class>
<entities>
<block>
<table>fast_call</table>
</block>
</entities>
</siteblocks_resource>
</models>
<resources>
<siteblocks_setup>
<setup>
<module>Test_Test</module>
</setup>
</siteblocks_setup>
</resources>
<helpers>
<siteblocks>
<class>Test_Test_Helper</class>
</siteblocks>
</helpers>
</global>
<frontend>
<routers>
<siteblocks>
<use>standard</use>
<args>
<module>Test_Test</module>
<frontName>siteblocks</frontName>
</args>
</siteblocks>
</routers>
<translate>
<modules>
<Test_Test>
<files>
<defaul>Test_Test.scv</defaul>
</files>
</Test_Test>
</modules>
</translate>
<layout>
<updates>
<mymodule>
<file>test_catalog.xml</file>
</mymodule>
</updates>
</layout>
</frontend>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<siteblocks before="Mage_Adminhtml">Test_Test_Adminhtml</siteblocks>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<default>
<web>
<routers>
<siteblocks_callentity>
<area>frontend</area>
<class>Test_Test_Controller_Router</class>
</siteblocks_callentity>
</routers>
</web>
</default>
</config>
The problem is that data is not sent in base
<?php
$installer = $this;
$installer->startSetup();
$table = $installer->getConnection()->newTable($installer->getTable('fast_call'))
->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, array(
'unsigned' => true,
'nullable' => false,
'primary' => true,
'identity' => true,
), 'id')
->addColumn('customer_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
'nullable' => false,
'default' => '',
), 'customer_name')
->addColumn('customer_phone', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
'nullable' => false,
'default' => '',
), 'customer_phone')
->addColumn('call_time', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
'nullable' => true,
'default' => '',
), 'call_time')
->setComment('fast_call');
$installer->getConnection()->createTable($table);
$installer->endSetup();
When information is sent form the controller receives it and seemingly must enter it into the database. But this is not happening. Debug gave nothing. Maybe someone will find a mistake

In your controller, change setData to addData

Related

Can we use angular js validation in symfony2 forms?

I am working on a registration form in symfony2 with angular js.
My doubt is can we do angular js validations in a symfony2 form?
because i cannot validate the form and also i dont know how to post form values to symfony controller..
please help..
I am stuck in project..
please check my registration.html.twig code..
<body ng-app="LoginApp">
<div id="register" class="animate form" ng-controller="RegisterController as registerCtrl">
{{ form_start(form, {'attr': {'name':'registerFrm', 'id':'registerFrmId','novalidate': '', 'ng-submit':'registerCtrl.registerFrm()'}}) }}
Your username
{{ form_row(form.username) }}
<span class="error" ng-show="submitted && registerFrm.adminuser[username].$error.required">Username is required!</span>
Your email
{{ form_row(form.email) }}
<span class="error" ng-show="submitted && registerFrm.adminuser[email].$invalid">Invalid email</span>
Your password
{{ form_row(form.plainPassword.first) }}
<span class="error" ng-show="submitted && registerFrm.adminuser[plainPassword][first].$error.required">Password is required!</span>
Please confirm your password
{{ form_row(form.plainPassword.second) }}
<span class="error" ng-show="submitted && registerFrm.adminuser[plainPassword][second].$error.required">Password is required!</span>
<p class="signin button">
<input type="submit" name="signup" ng-model="signup" ng-click="submitted=true" value="Sign up" />
</p>
{{ form_end(form) }}
</div>
<script>
var App = angular.module('LoginApp',[]);
App.controller('RegisterController', ['$scope',function($scope) {
}]);
</script>
</body>
My symfony form builder
$builder
->add('username', TextType::class , array(
'label' => false,
'attr' => array(
'ng-model' => 'formData.username',
'id' => 'usernamesignup',
'placeholder' => 'myusername690',
'required' => false)
))
->add('email', TextType::class , array(
'label' => false,
'attr' => array(
'ng-model' => 'formData.email',
'id' => 'emailsignup',
'placeholder' => 'mymail#mail.com',
'ng-pattern' => '/^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*#([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/',
'required' => false)
))
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array(
'label' => false,
'attr' => array(
'ng-model' => 'formData.password',
'id' => 'passwordsignup',
'placeholder' => 'eg. X8df!90EO',
'required' => false)
),
'second_options' => array('label' => false,
'attr' => array(
'ng-model' => 'formData.confirm_password',
'id' => 'passwordsignup_confirm',
'placeholder' => 'eg. X8df!90EO',
'required' => false)
),
)
);
registration form image
Hey Dmitry Grachikov,
Please change your code
<span class="error" ng-show="submitted && registerFrm.adminuser[username].$error.required">Username is required!</span>
to
<span class="error" ng-show="submitted && registerFrm['adminuser[username]'].$error.required">Username is required!</span>
Your code having syntactic JS error.
If you want to reference a property named adminuser[username], you should do it like this:
registerFrm['adminuser[username]'].$error
registerFrm.adminuser[username] is incorrectly interpreted as (registerFrm.adminuser)[username]
The easiest ways there is to render your form in twig just to get html of a form with field names. Afterwards you have to use exactly the same field names in form submit request and symfony forms component will handle it.

How can change the class of tags in date input in cakephp

as you see the class of datetime input is as class of other inputs. i used twitter bootstrap
but how can change the datetime input internal inputs classes? (without hacking the form helper)
this is my datetime picker input:
echo $this->Form->input('issue_date');
and the form created like this :
echo $this->Form->create('Certificate',array('class'=>'form-horizontal','inputDefaults' => array(
'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
'div' => array('class' => 'control-group'),
'label' => array('class' => 'control-label'),
'between' => '<div class="controls">',
'after' => '</div>',
'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-inline')))
));
This will work fine.
echo $this->Form->input('issue_date', array('class' => 'your class name'));
the above will generate output like this
<div class="input datetime">
<select name="data[Certificate][issue_date][month]" class="your class name" id="CertificateIssueDateMonth">
// options
</select>-
<select name="data[Certificate][issue_date][day]" class="your class name" id="CertificateIssueDateDay">
// options
</select>-
<select name="data[Certificate][issue_date][year]" class="your class name" id="CertificateIssueDateYear">
// options
</select>
<select name="data[Certificate][issue_date][hour]" class="your class name" id="CertificateIssueDateHour">
</select>:
<select name="data[Certificate][issue_date][min]" class="your class name" id="CertificateIssueDateMin">
// options
</select>
<select name="data[Certificate][issue_date][meridian]" class="your class name" id="CertificateIssueDateMeridian">
// options
</select>
</div>

Cannot insert into Wordpress database table from custom page

I created a custom page with a form and a new table in my wordpress database wp_applicants. When I submit, it returns the resultant echo message but does not insert into my database table. Kindly assist.
The code:
<?php
/**
*Template Name: Career Temp
*/
get_header();
?>
<div class="page-header-wrap">
<header class="page-header">
<h1 class="page-header-title"><?php the_title(); ?></h1>
</header>
</div>
<div id="primary" class="content-area span_16 col clr clr-margin">
<div id="content" class="site-content" role="main">
<!-- paul removed post loop -->
<?php
if(isset($_POST['submit'])) {
global $wpdb;
$fname=$_POST['txt_fname'];
$lname=$_POST['txt_lname'];
$tbl="wp_applicants";
$others= $_POST['txt_email'];
$wpdb->insert('wp_applicants', array('first_name' => $fname, 'last_name' => $lname, 'email' => $others), array('%s', '%s', '%s'));
$msg = "Data Submited";
echo $msg;
}
?>
<form action="" method="post">
first name - <input type="text" name="txt_fname"/>
last name - <input type="text" name="txt_lname"/>
email - <input type="text" name="txt_email"/>
<input type="submit" name="submit"/>
</form>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Try showing errors, as described in the Codex. Something like:
$wpdb->show_errors();
$wpdb->insert('wp_applicants', array('first_name' => $fname, 'last_name' => $lname, 'email' => $others), array('%s', '%s', '%s'));
$wpdb->print_error();
$wpdb->hide_errors();

How to add a div to a radio button?

I'm a new user of CakePHP.
I'm trying to add some div to contain my input + my label.
This is what I've got :
<?php
$option = array ("value1" => "labelContent1", "value2" => "abelContent2");
echo $this->Form->input('name', array('type' => 'radio', 'options' => $option, 'div' => true, "legend" => false));
?>
<div class="input radio">
<input type="hidden" name="data[Quiz][name]" id="ModelName_" value=""/>
<input type="radio" name="data[Quiz][name]" id="ModelName1" value="value1" />
<label for="ModelName1">labelContent1</label>
<input type="radio" name="data[Quiz][name]" id="ModelName2" value="value2" />
<label for="ModelName2">labelContent2</label>
</div>
And this what I would like to have :
<div class="input radio">
<input type="hidden" name="data[Quiz][name]" id="ModelName_" value=""/>
<div>
<input type="radio" name="data[Quiz][name]" id="ModelName1" value="value1" />
<label for="ModelName1">labelContent1</label>
</div>
<div>
<input type="radio" name="data[Quiz][name]" id="ModelName2" value="value2" />
<label for="ModelName2">labelContent2</label>
</div>
</div>
Do you know if it is possible to make it by using the FormHelper ?
I know it's an old thread but I had to reply.
The correct way to achieve this without creating a bad mark-up is to use before and after options:
echo $this->Form->input('name', array( 'type' => 'radio',
'separator'=> '</div><div>',
'before' => '<div>',
'after' => '</div>',
'options' => $option,
'label' => true,
"legend" => false
)
);
It looks like you can't achieve that with the Form Helper. The radio options are not wrapped in anything. See code.
You can add 'separator' => '<br/>' to the Form->input options, to display each option in its own line.
or implement it yourself.
you can try this
$option = array ("value1" => "labelContent1", "value2" => "abelContent2");
echo $this->Form->input('name', array( 'type' => 'radio',
'separator'=> '</div><div>',
'options' => $option,
'label' => true,
"legend" => false
)
);
<?php
$option = array ("value1" => "labelContent1", "value2" => "abelContent2");
echo $this->Form->input('name', array(
'type' => 'radio',
'options' => $option,
'templates' => ['radioWrapper' => '<div>{{label}}</div>'],
"legend" => false));
?>
This seems to work well for Cake 3.+

Add label for submit button

I'm new in cakephp. What I try to accomplish is this output :
<p><label> </label><input class="adminbut rad2" type="submit" name="submit" value="Login" /></p>
And this is what I did in my view file
<?php echo $this->Form->end(array(
'div' => false,
'label' => 'Login',
'class' => 'adminbut rad2',
'name' => 'submit',
'value' => 'Login',
'before' => '<p>',
'after' => '</p>'
));?>
And what I got is :
<input class="adminbut rad2" name="submit" value="Login" type="submit" /></p>
And as you can see, my output is missing :
<label> </label>
Any solution?
Thanks :)
Try
$form->create();
$form->submit("Login",array( 'div' => false, 'class' => 'adminbut rad2', 'name' => 'submit', 'value' => 'Login', 'before' => '<p><label> </label>', 'after'
=> '</p>'
));
$form->end();
echo $form->input('submit', array(
'type'=>'submit',
'value'=>'Login',
'class'=>'adminbut rad2',
'div'=>array('tag'=>'p'),
'label'=>" "
));
Try This my friend
Cakephp 2.X
$this->Form->submit(__('Submit'), array('class'=>'adminbut rad2'));
Cakephp 1.x
$form->submit(__('Submit'), array('class'=>'adminbut rad2'));

Resources