Laravel submitting form gets page expired - php

So i have a very basic controller located at : app/Http/Controllers/RentalRequestController
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
class RentalRequestController extends BaseController
{
public function store(Request $request, $obj)
{
$g = 0;
return view("success");
}
}
Then in my web.php i have the following:
Route::Post('/', 'RentalRequestController#store');
And then i have the following form in my view:
<form id="rentalForm" name="rentalForm" role="form" action="/" method="post">
<!-- Row -->
<div class="f-row">
<div class="form-group one-fourth">
<label for="address">Gade</label>
<input type="text" name="address" id="address"
data-parsley-required-message="Indtast venligst din gade" required
data-parsley-errors-container="#errAddress"/>
<div class="full-width">
<label id="errAddress"></label>
</div>
</div>
<div class="form-group one-fourth">
<label for="number">Husnummer</label>
<input type="number" name="number" id="number"
data-parsley-required-message="Indtast venligst dit husnummer" required=""
data-parsley-errors-container="#errNumber">
<div class="full-width" style="">
<label id="errNumber"></label>
</div>
</div>
<div class="form-group one-fourth">
<label for="zip">Postnr</label>
<input type="text" name="zip" id="zip" required=""
data-parsley-required-message="Indtast venligst dit postnr"
data-parsley-length-message="Indtast et dansk postnr"
data-parsley-length="[4,4]" data-parsley-zip="dk"
data-parsley-errors-container="#errZip">
<div class="full-width" style="">
<label id="errZip"></label>
</div>
</div>
<div class="form-group one-fourth">
<label for="city">By</label>
<input type="text" name="city" id="city" required=""
data-parsley-required-message="Indtast venligst din by"
data-parsley-errors-container="#errCity">
<div class="full-width" style="">
<label id="errCity"></label>
</div>
</div>
</div>
<!-- //Row -->
<!-- Row -->
<div class="f-row">
</div>
<!-- //Row -->
<div class="f-row">
<div class="form-group one-fourth">
<label for="kvm">kvadratmeter</label>
<input type="number" id="kvm" min="1" class="uniform-input number" name="kvm" required=""
data-parsley-required-message="Indtast venligst arealet på din bolig"
data-parsley-errors-container="#errKvm">
<div class="full-width" style="">
<label id="errKvm"></label>
</div>
</div>
<div class="form-group one-fourth">
<label for="price">Nuværende husleje</label>
<input type="number" id="price" name="price" step="0.01" required=""
data-parsley-required-message="Indtast venligst din nuværende husleje"
data-parsley-errors-container="#errPrice">
<div class="full-width" style="">
<label id="errPrice"></label>
</div>
</div>
<div class="form-group select one-fourth">
<label for="concatSelector">Vælg kontakt form</label>
<div class="selector">
<select id="concatSelector" required="" data-parsley-required-message="Indtast venligst din nuværende husleje">
<option selected="">Vælg kontakt form</option>
<option value="cell">Telefon</option>
<option value="mail">E-mail</option>
</select>
</div>
</div>
<div class="form-group one-fourth fadeIn" id="selectEmail">
<label for="email">Kontakt information</label>
<input type="email" id="email" name="email" placeholder="E-mail" required=""
data-parsley-type="email"
data-parsley-type-message="Indtast venligst en gyldig e-mail"
data-parsley-required-message="Indtast venligst en gyldig e-mail"
data-parsley-errors-container="#errEmail"
>
<div class="full-width" style="">
<label id="errEmail"></label>
</div>
</div>
<div class="form-group one-fourth fadeIn" id="selectCell">
<label for="mobile">Kontakt information</label>
<input type="number" id="mobile" name="phone" placeholder="Telefon" required=""
data-parsley-required-message="Indtast venligst et gyldig telefon nr."
data-parsley-errors-container="#errCell"
>
<div class="full-width" style="">
<label id="errCell"></label>
</div>
</div>
</div>
<div class="f-row">
<div class="form-group right one-fourth" style="margin-top: 35px">
<button type="button" onclick="sendInformation()" class="btn large black">Kan jeg spare penge?
</button>
</div>
</div>
Now when i submit the form it redirects me to a page saying:
The page has expired due to inactivity.
Please refresh and try again.
Can anyone tell me what ive done wrong?

You should add:
{{ csrf_field() }}
inside <form> element for example like this:
<form id="rentalForm" name="rentalForm" role="form" action="/" method="post">
{{ csrf_field() }}
This is called CSRF protection

<form id="rentalForm" name="rentalForm" role="form" action="/" method="post">
#csrf
<!-- do you awesome code here -->
</form>
if you do not use javascript to submit form just add #csrf below form tag

Related

No route found when I set a parameter

I'm developing an app with Symfony 4 but I'm having a little problem here.
I made a controller with a required parameter but when I to follow the route I get this message:
Here's the code of is my html file:
{% extends 'base.html.twig' %}
{% block title %}Registro Madre{% endblock %}
{% block body %}
<div class="container">
<h1>Ingrese los datos de la madre</h1>
<form action="/insertMadre" method="POST">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="nombre">Nombres:</label>
<input type="text" name="nombre" class="form-control" id="nombre" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="apellido">Apellidos:</label>
<input type="text" name="apellido" class="form-control" id="apellido" required>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<div class="form-group">
<label for="nacimiento">Fecha de nacimiento</label>
<input type="date" name="nacimiento" id="nacimiento" class="form-control" required>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="nacionalidad">Nacionalidad</label>
<input type="text" name="nacionalidad" id="nacionalidad" class="form-control" required>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="contacto">Teléfono de Contacto</label>
<input type="tel" name="contacto" id="contacto" class="form-control" required>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="dui">DUI (sin guiones)/No. Pasaporte</label>
<input type="text" name="dui" id="dui" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="direccion">Dirección:</label>
<input type="text" name="direccion" id="direccion" class="form-control" required>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="departamento">Departamento:</label>
<select name="departamento" id="departamento" class="form-control" required>
<option value="">Seleccione una opción..</option>
{% for departamento in departamentos %}
<option value="{{ departamento.id }}">{{ departamento.depname }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="municipio">Municipio:</label>
<select name="municipio" id="municipio" class="form-control" required>
<option value="">Seleccione una opción..</option>
</select>
</div>
</div>
</div>
<legend>Datos Clínicos</legend>
<div id="datos-clinicos">
<div class="row">
<div class="col-sm-2">
<span class="datos-clinicos-text">Fórmula Obstétrica</span>
</div>
<div class="col-sm-1">
<span class="datos-clinicos-text">G</span>
</div>
<div class="col-sm-1">
<input type="number" class="form-control" min="0" step="1" value="0" name="formG" id="formG">
</div>
<div class="col-sm-1">
<span class="datos-clinicos-text">P</span>
</div>
<div class="col-sm-1">
<input type="number" class="form-control" min="0" step="1" value="0" name="formP" id="formP">
</div>
<div class="col-sm-1">
<span class="datos-clinicos-text">P</span>
</div>
<div class="col-sm-1">
<input type="number" class="form-control" min="0" step="1" value="0" name="formP1" id="formP1">
</div>
<div class="col-sm-1">
<span class="datos-clinicos-text">A</span>
</div>
<div class="col-sm-1">
<input type="number" class="form-control" min="0" step="1" value="0" name="formA" id="formA">
</div>
<div class="col-sm-1">
<span class="datos-clinicos-text">V</span>
</div>
<div class="col-sm-1">
<input type="number" class="form-control" min="0" step="1" value="0" name="formV" id="formV">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="enfermedadMedica">Enfermedades médicas que afecten el desarrollo del embarazo</label>
<select name="enfermedadMedica" id="enfermedadMedica" class="form-control">
<option value="0">Elija una opción</option>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="enfermedadExantematica">Enfermedad exantemática durante el embarazo</label>
<select name="enfermedadExantematica" id="enfermedadExantematica" class="form-control">
<option value="0">Elija una opción</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="informacionExtra">Otra Información</label>
<textarea name="informacionExtra" id="informacionExtra" class="form-control" rows="5" style="resize:none"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 text-right">
<input type="submit" value="Registrar" class="btn-site">
</div>
</div>
</form>
</div>
{% endblock %}
Here's my controller:
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Madre;
use App\Entity\DatosClinicosMadre;
use App\Entity\ProductoObstetrico;
use App\Entity\CondicionProducto;
class ProductoController extends AbstractController
{
public function registro($id)
{
$madre = $this->getDoctrine()->getRepository(Madre::class)->find($id);
return $this->render('producto/register.html.twig');
}
}
And here's my route:
registro-producto:
path: /ingresar-producto/{id}
name_prefix: nuevoProducto
controller: App\Controller\ProductoController::registro
If I don't send a parameter I don't have any problems but when I want to send an ID it comes the issue, and if I set the route with a parameter and I don't send a parameter I get an error telling me that I must have to send a parameter. I don't know what's going on...
UPDATE
This is what I get when I run php bin/console debug:router
Thank you all!
This is because you haven't declared the param type.
Try amending your routes file to this:
registro-producto:
path: /ingresar-producto/{id}
name_prefix: nuevoProducto
controller: App\Controller\ProductoController::registro
requirements:
id: \d+
Doing this will set the {id} type to digit, allowing the /3 param.
See here:
Taken from Symfony Docs:
Adding {wildcard} Requirements
Imagine the blog_list route will contain a paginated list of blog posts, with URLs like /blog/2 and /blog/3 for pages 2 and 3. If you change the route's path to /blog/{page}, you'll have a problem:
blog_list: /blog/{page} will match /blog/*;
blog_show: /blog/{slug} will also match /blog/*.
When two routes match the same URL, the first route that's loaded wins. Unfortunately, that means that /blog/yay-routing will match the blog_list. No good!
To fix this, add a requirement that the {page} wildcard can only match numbers (digits)
ref: https://symfony.com/doc/current/routing.html

Make form fit on screen bootstrap

I have a background, but im also trying to get my form to just fit on the screen so it's not going past the screen.
Here is the code for the background image
<style>
body, html {
height: 100%;
margin: 0;
}
.bg {
/* The image used */
background-image: url("https://i.imgur.com/qnxtJse.jpg");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
Here is the code for the form. You can vist https://drivealongapp.com/dashboard/page-register.php
And see what I'm talking about. I want it to just be in the image area. and not go past it.
<!-- Main wrapper -->
<div id="main-wrapper">
<div class="unix-login">
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-lg-4">
<div class="login-content card">
<center><h3>Register Account</h3>
<p><strong>Create Account</strong> » Purchase » Begin</p></center>
<div class="login-form">
<form data-toggle="validator" method="post" id="register_form">
<div class="form-group">
<label>Name</label>
<input id="username" type="name" name="name" class="form-control" placeholder="First & Last Name" required>
</div>
<div class="form-group">
<label>Age</label>
<input type="dob" id="age" name="age"class="form-control" placeholder="03/26/2001" required></div>
<div class="form-group">
<label>Email address</label>
<input id="email" type="email" name="email" class="form-control" placeholder="Email" data-error="This email is invalid" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label>Password</label>
<input id="password" type="password" name="password" class="form-control" placeholder="Password" data-minlength="8" data-error="Minimum of 8 characters" required>
<div class="help-block"></div>
</div>
<div class="form-group">
<label>Choose Your Course</label>
<select name="course" class="form-control">
<option value="0" selected>Texas Parent Taught Drivers Ed</option>
<option value="1">Texas Instructor Taught Drivers Ed</option>
<option value="2">Texas Adult Drivers Ed</option>
</select>
</div>
<div class="form-group">
<label>Referral</label>
<input id="referral" type="text" name="referral" class="form-control" placeholder="Referral Code" value="<?php echo $refer?>">
</div>
<div class="form-group checkbox">
<label>
<input id="policy" type="checkbox" data-error="Don't you agree?" required> Agree the terms and Privacy Policy
</label>
<div class="help-block with-errors"></div>
</div>
<button name="register" type="submit" class="btn btn-primary btn-flat m-b-30 m-t-30" >Register</button>
<div class="register-link m-t-15 text-center">
<p>Already have account? Sign in</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I'm aiming for something like this:
I just removed all the labels. If you want to change something else let me know
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<!-- Main wrapper -->
<div id="main-wrapper">
<div class="unix-login">
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-lg-4">
<div class="login-content card">
<center>
<h3>Register Account</h3>
<p><strong>Create Account</strong> » Purchase » Begin</p>
</center>
<div class="login-form">
<form data-toggle="validator" method="post" id="register_form">
<div class="form-group">
<input id="username" type="name" name="name" class="form-control" placeholder="First & Last Name" required>
</div>
<div class="form-group">
<input type="dob" id="age" name="age" class="form-control" placeholder="AGE (03/26/2001)" required></div>
<div class="form-group">
<input id="email" type="email" name="email" class="form-control" placeholder="Email" data-error="This email is invalid" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<input id="password" type="password" name="password" class="form-control" placeholder="Password" data-minlength="8" data-error="Minimum of 8 characters" required>
<div class="help-block"></div>
</div>
<div class="form-group">
<select name="course" class="form-control">
<option value="0" selected>CHOOSE COURSE</option>
<option value="1" selected>Texas Parent Taught Drivers Ed</option>
<option value="2">Texas Instructor Taught Drivers Ed</option>
<option value="3">Texas Adult Drivers Ed</option>
</select>
</div>
<div class="form-group">
<input id="referral" type="text" name="referral" class="form-control" placeholder="Referral Code" value="<?php echo $refer?>">
</div>
<div class="form-group checkbox">
<label>
<input id="policy" type="checkbox" data-error="Don't you agree?" required> Agree the terms and Privacy Policy
</label>
<div class="help-block with-errors"></div>
</div>
<button name="register" type="submit" class="btn btn-primary btn-flat m-b-30 m-t-30">Register</button>
<div class="register-link m-t-15 text-center">
<p>Already have account? Sign in</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>

PHP Warning htmlentities() expects parameter 1 to be string, array given

I have a form to inject data in a database. When user clicks submit button this error shows up in a <input type=text>field. I have been looking around for a solution for hours but I do not know how to fix this.
Warning: htmlentities() expects parameter 1 to be
string, array given in
C:rr\xampp\htdocs\ecommerce\helpers\helpers.php on line
11
helpers.php
<?php
function display_errors($errors){
$display = ' <ul class="bg-danger">';
foreach($errors as $error){
$display .='<li class="text-danger">'.$error. '</li> ';
}
$display .='</ul>';
return $display;
}
function sanitize ($dirty){
return htmlentities($dirty, ENT_QUOTES, "UTF-8");
}
function money($number){
return '$ '.number_format($number,2);
}
form.php
<form action="products.php?add=1" method="POST" enctype="multipart/form-data">
<div class='container_12'>
<div class="form-group col-md-3">
<label for="prod_name">Product Name*:</label>
<input type="text" name="prod_name" id="prod_name" class="form-control" value="<?=((isset($_POST['prod_name']))?sanitize($_POST):' ');?>">
</div>
<div class="form-group col-md-3">
<label for="parent">Parent Category*:</label>
<select class="form-control" id="parent" name="parent">
<option value=""<?=((isset($_POST['parent']) && $_POST['parent'] == '')?'selected':'');?>></option>
<?php while($parent = mysqli_fetch_assoc($parentQuery)): ?>
<option value=" <?=$parent['id'];?>"<?=((isset($_POST['parent']) && $_POST['parent'] == $parent['id'])?' select':'');?>><?=$parent['category_name'];?></option>
<?php endwhile; ?>
</select>
</div>
<div class='form-group col-md-3'>
<label for='child'>Second Category*:</label>
<select id='child' name='child' class='form-control'></select>
</div>
</div>
<div class='container_12'>
<div class='form-group col-md-3'>
<label for='list_price'>List Price(OPTIONAL): </label>
<input type="text" id="list_price" name="list_price" class="form-control" value="<?=((isset($_POST['list_price']))?sanitize($_POST['list_price']):'');?>">
</div>
<div class="form-group col-md-3">
<label for="price">Price*:</label>
<input type="text" id="price" name="price" class="form-control" value="<?=((isset($_POST['price']))?sanitize($_POST['price']):'');?>">
</div>
<div class='form-group col-md-3'>
<label for='prod_width'>Width* (in inches):</label>
<input type="text" id="prod_width" name="prod_width" class="form-control" value="<?=((isset($_POST['prod_width']))?sanitize($_POST['prod_width']):'');?>">
</div>
<div class='form-group col-md-3'>
<label for='prod_depth'>Height*(in inches):</label>
<input type="text" id="'prod_depth" name="'prod_depth" class="form-control" value="<?=((isset($_POST['prod_depth']))?sanitize($_POST['prod_depth']):'');?>">
</div>
</div>
<div class='container_12'>
<div class='form-group col-md-3'>
<label for='prod_height'>Depth*(in inches):</label>
<input type="text" id="prod_height" name="prod_height" class="form-control" value="<?=((isset($_POST['prod_height']))?sanitize($_POST['prod_height']):'');?>">
</div>
<div class='form-group col-md-3'>
<label for='prod_material'>Construction Material:</label>
<input type="text" id="prod_material" name="prod_material" class="form-control" value="<?=((isset($_POST['prod_material']))?sanitize($_POST['prod_material']):'');?>">
</div>
<div class='form-group col-md-6'>
<label>Quantity * :</label>
<input type="text" id="quantity" name="quantity" class="form-control" value="<?=((isset($_POST['quantity']))?sanitize($_POST['quantity']):'');?>">
</div>
</div>
<div class='container_12'>
<div class="form-group col-md-3"> <label for="image_1">Product Photo #1:</label>
<input type="file" name="image_1" id="image_1" class="form-control">
</div>
<div class="form-group col-md-3"> <label for="image_2">Product Photo #2:</label>
<input type="file" name="image_2" id="image_2" class="form-control">
</div>
<div class="form-group col-md-3"> <label for="image_3">Product Photo #3:</label>
<input type="file" name="image_3" id="image_3" class="form-control">
</div>
<div class="form-group col-md-3"> <label for="image_4">Product Photo#4:</label>
<input type="file" name="image_4" id="image_4" class="form-control">
</div>
</div>
<div class='container_12'>
<div class="form-group col-md-6">
<label for="description">Description:</label>
<textarea id="description" name="description" class="form-control" rows="6"><?=((isset($_POST['description']))?sanitize($_POST['description']):'');?></textarea>
</div>
<div class="form-group col-md-6">
<label for="care_instructions">Care Instructions*:</label>
<textarea id="care_instructions" name="care_instructions" class="form-control" rows="6"><?=((isset($_POST['care_instructions']))?sanitize($_POST['care_instructions']):'');?></textarea>
</div></div>
<div class='container_12'>
<div class="form-group pull-right">
<input type='submit' value='Add Product' class='form-control btn-success pull-right'>
</div></div>
</form>
You are passing the whole $_POST variable to serialize in the product name input (that's why the error says 'array given').
Check this line:
<input type="text" name="prod_name" id="prod_name" class="form-control" value="<?=((isset($_POST['prod_name']))?sanitize($_POST):' ');?>">
And change it with this:
<input type="text" name="prod_name" id="prod_name" class="form-control" value="<?=((isset($_POST['prod_name']))?sanitize($_POST['prod_name']):' ');?>">

Codeigniter insert not working Database error occured

I have following code tried out.
class Vendor extends CI_Controller{
function __construct(){
parent::__construct();
}
public function vendor_add(){
$this->load->helper('url');
$this->load->view('header');
$this->load->view('sidebar');
$this->load->view('add_vendor');
$this->load->view('footer');
}
public function save(){
$this->load->helper(array('form','url'));
$this->load->model('Save_vendor');
$vendor_data = array(
'ven_name'=> $this->input->post['firstName'],
'ven_shop'=>$this->input->post['companyName'],
'ven_email_id'=>$this->input->post['email'],
'ven_contactno'=>$this->input->post['contactno'],
'ven_othercontactno'=>$this->input->post['contactno2'],
'ven_commission'=>$this->input->post['assigncommission'],
'ven_accname'=>$this->input->post['bankaccname'],
'ven_accountno'=>$this->input->post['bankaccno'],
'ven_ifsccode'=>$this->input->post['ifsccode'],
'ven_type'=>$this->input->post['optionsRadios']
);
$this->Save_vendor->vendor_insertdata($vendor_data);
redirect(base_url().'/vendor/vendor_add');
}
}
/* Model File */
class Save_vendor extends CI_Model{
public function vendor_insertdata($vendor_data){
$this->db->insert('tbl_vendor',$vendor_data);
}
/* VIew FIle */
<!-- BEGIN CONTENT -->
<div class="page-content-wrapper">
<div class="page-content">
<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<!-- BEGIN PAGE HEADER-->
<h3 class="page-title">
Add Vendor <small> Add New Vendor</small>
</h3>
<div class="row">
<div class="col-md-12">
<div class="portlet-body form">
<?php echo base_url();?>
<!-- BEGIN FORM-->
<form action="<?php echo base_url("index.php/Vendor/save") ?>" class="horizontal-form" method="post">
<div class="form-body">
<h3 class="form-section">Add Vendor</h3>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div class="radio-list">
<label class="radio-inline">
<input type="radio" name="optionsRadios" id="1" value="1" checked> Shop Vendor </label>
<label class="radio-inline">
<input type="radio" name="optionsRadios" id="2" value="2"> Vendor </label>
</div>
</div>
</div>
<!--/span-->
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Vendor Name<span class="required">*</span></label>
<input type="text" id="firstName" class="form-control" name="firstName">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Company/Shop/Business Name<span class="required">*</span></label>
<input type="text" id="companyName" class="form-control" name="companyName" >
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Email Id<span class="required">*</span></label>
<input type="text" id="email" class="form-control" name="email">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">Contact No<span class="required">*</span></label>
<input type="text" id="firstName" class="form-control" name="contactno" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">2nd Contact No</label>
<input type="text" id="firstName" class="form-control" name="contactno2">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">PIN Code<span class="required">*</span></label>
<input type="text" id="pincode" class="form-control" name="pincode" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">Assign Commision %<span class="required">*</span></label>
<input type="text" id="assigncommission" class="form-control" name="assigncommission">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">BANK Account Name<span class="required">*</span></label>
<input type="text" id="firstName" class="form-control" name="bankaccname" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">Account Number<span class="required">*</span></label>
<input type="text" id="bankaccno" class="form-control" name="bankaccno" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">IFSC Code<span class="required">*</span></label>
<input type="text" id="ifsccode" class="form-control" name="ifsccode">
</div>
</div>
</div>
<div class="form-actions right">
<button type="submit" class="btn yellow-crusta"> Add Vendor</button>
</div>
</form>
</div>
</div>
</div>
<!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
Above code but it will give an error Database error occured. Column name not be null. I am beginner in codeigniter please any suggestions for it.
I want to add data in my database.but it is not working.
Check your table "tbl_vendor" in which you are inserting values. One or more field is defined as NOT NULL means it will not accept empty value. You have to pass value to that field which is marked as NOT NULL.
Please read Codeigniter Query Builder reference first. You're making big mistakes. Your code should be like below:
$vendor_data = array(
'ven_name'=> $this->input->post['firstName'],
'ven_shop'=>$this->input->post['companyName'],
'ven_email_id'=>$this->input->post['email'],
'ven_contactno'=>$this->input->post['contactno'],
'ven_othercontactno'=>$this->input->post['contactno2'],
'ven_commission'=>$this->input->post['assigncommission'],
'ven_accname'=>$this->input->post['bankaccname'],
'ven_accountno'=>$this->input->post['bankaccno'],
'ven_ifsccode'=>$this->input->post['ifsccode'],
'ven_type'=>$this->input->post['optionsRadios']
);
$this->db->insert('your_table_name', $vendor_data);

How to get values of a two contact forms which is in two separate tabs in php?

I have a contact form in php which has has two tabs containing two different contact forms. I want to get all the values of both the forms and send it as an email. I have coded it for one of the tab, but i am not getting the values of each of the field in the contact form in that tab. Can anyone tell how to do this ? My code is shown below for one of the tab:
<form name="contactForm" id='contact_form' method="post" action=''>
<div tab-id="1" class="tab active">
<div class="form-inline">
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="name" id="exampleInputName" placeholder="name" >
</div>
<div class="form-group col-sm-12 padd">
<input type="email" class="form-control" name="email" id="exampleInputEmail" placeholder="email address">
</div>
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="telephone" placeholder="phone">
</div>
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="Country" id="exampleInputName" placeholder="Country" >
</div>
<div class="form-group col-sm-12 padd">
<textarea class="form-control" name="message" rows="3" id="exampleInputMessage" placeholder="message" ></textarea>
</div>
</div>
<div class="form-group col-xs-12 padd">
<div id='mail_success' class='success' style="display:none;">Your message has been sent successfully.
</div><!-- success message -->
<div id='mail_fail' class='error' style="display:none;"> Sorry, error occured this time sending your message.
</div><!-- error message -->
</div>
<div class="form-group col-xs-8 padd">
<div class="g-recaptcha" data-sitekey="6LcJqyITAAAAABks5hnD6U_2ptu09RiXYOHvNNud"></div>
</div>
<div class="form-group col-sm-4 padd" id='submit'>
<input type="submit" id='send_message' name="send" class="btn btn-lg costom-btn" value="send">
</div>
</div>
<div tab-id="2" class="tab">
<div class="form-inline">
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="name" id="exampleInputName" placeholder="full name" >
</div>
<div class="form-group col-sm-6 padd">
<input type="email" class="form-control" name="email" id="exampleInputEmail" placeholder="Email">
</div>
<div class="form-group col-sm-6 pad">
<input type="text" class="form-control" name="telephone" placeholder="Phone">
</div>
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="subject" id="exampleInputSubject" placeholder="Tell us about your project in your own words ?" >
</div>
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="subject" id="exampleInputSubject" placeholder="Tell us about you or your company" >
</div>
<div class="form-group col-sm-12 padd">
<p>Which services are you interested in ?</p>
<p>
<input type="checkbox" id="test1" />
<label for="test1"></label>
</p>
<p>
<input type="checkbox" id="test2"/>
<label for="test2"></label>
</p>
<p>
<input type="checkbox" id="test3"/>
<label for="test3"></label>
</p>
<p>
<input type="checkbox" id="test4"/>
<label for="test4"></label>
</p>
<p>
<input type="checkbox" id="test5"/>
<label for="test5"></label>
</p>
<p>
<input type="checkbox" id="test6"/>
<label for="test6"></label>
</p>
</div>
</div>
<div class="form-group col-xs-12">
<div id='mail_success' class='success' style="display:none;">Your message has been sent successfully.
</div><!-- success message -->
<div id='mail_fail' class='error' style="display:none;"> Sorry, error occured this time sending your message.
</div><!-- error message -->
</div>
<div class="form-group col-sm-12" id='submit'>
<input type="submit" id='send_message' class="btn btn-lg costom-btn" value="send">
</div>
</div>
</form>
Please try with this code.
<form name="contactForm" id='contact_form' method="post" action='php/email.php'>
//This is the first tab
<div tab-id="1" class="tab active">
<div class="form-inline">
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="name" id="exampleInputName" placeholder="name" >
</div>
<div class="form-group col-sm-12 padd">
<input type="email" class="form-control" name="email" id="exampleInputEmail" placeholder="email address">
</div>
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="telephone" placeholder="phone">
</div>
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="Country" id="exampleInputName" placeholder="Country" >
</div>
<div class="form-group col-sm-12 padd">
<textarea class="form-control" name="message" rows="3" id="exampleInputMessage" placeholder="message" ></textarea>
</div>
</div>
<div class="form-group col-xs-12 padd">
<div id='mail_success' class='success' style="display:none;">Your message has been sent successfully.
</div><!-- success message -->
<div id='mail_fail' class='error' style="display:none;"> Sorry, error occured this time sending your message.
</div><!-- error message -->
</div>
<div class="form-group col-xs-8 padd">
<div class="g-recaptcha" data-sitekey="6LcJqyITAAAAABks5hnD6U_2ptu09RiXYOHvNNud"></div>
</div>
<div class="form-group col-sm-4 padd" id='submit'>
<input type="submit" id='send_message' name="send" class="btn btn-lg costom-btn" value="send">
</div>
</div>
//This is the Second tab
<div tab-id="2" class="tab">
<div class="form-inline">
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="name" id="exampleInputName" placeholder="full name" >
</div>
<div class="form-group col-sm-6 padd">
<input type="email" class="form-control" name="email" id="exampleInputEmail" placeholder="Email">
</div>
<div class="form-group col-sm-6 pad">
<input type="text" class="form-control" name="telephone" placeholder="Phone">
</div>
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="subject" id="exampleInputSubject" placeholder="Tell us about your project in your own words ?" >
</div>
<div class="form-group col-sm-12 padd">
<input type="text" class="form-control" name="subject" id="exampleInputSubject" placeholder="Tell us about you or your company" >
</div>
<div class="form-group col-sm-12 padd">
<p>Which services are you interested in ?</p>
<form action="#">
<p>
<input type="checkbox" id="test1" />
<label for="test1">Web Design & development</label>
</p>
<p>
<input type="checkbox" id="test2"/>
<label for="test2">E-Commerce Solutions</label>
</p>
<p>
<input type="checkbox" id="test3"/>
<label for="test3">Digital Marketing</label>
</p>
<p>
<input type="checkbox" id="test4"/>
<label for="test4">SEO Solutions</label>
</p>
<p>
<input type="checkbox" id="test5"/>
<label for="test5">2D&3D Animation</label>
</p>
<p>
<input type="checkbox" id="test6"/>
<label for="test6">Game development</label>
</p>
</div>
</div>
<div class="form-group col-xs-12">
<div id='mail_success' class='success' style="display:none;">Your message has been sent successfully.
</div><!-- success message -->
<div id='mail_fail' class='error' style="display:none;"> Sorry, error occured this time sending your message.
</div><!-- error message -->
</div>
<div class="form-group col-sm-12" id='submit'>
<input type="submit" id='send_message' class="btn btn-lg costom-btn" value="send">
</div>
</form>
</div>
Assuming the following form-tab html structure:
<form name="contactForm" id='contact_form' method="post" action=''>
<div tab-id="1" class="tab active">
...
<input name="field1" value="" class="form-control" />
<input name="field2" value="" class="form-control" />
</div>
<div tab-id="2" class="tab">
...
<input name="field1" value="" class="form-control" />
<input name="field2" value="" class="form-control" />
</div>
</form>
As your div tabs have not attribute called id, and the class attribute you assigned is the same for every tab, it is not clear to see how to define the jquery selector for the inputs within those tabs you created.
You can access the values of each tab, using jquery as follows:
var fields = {}
fields.tab1 = {}
fields.tab1.field1 = $('div[tab-id=1] input[name=field1]').val()
fields.tab1.field2 = $('div[tab-id=1] input[name=field2]').val()
fields.tab2 = {}
fields.tab2.field1 = $('div[tab-id=2] input[name=field1]').val()
fields.tab2.field2 = $('div[tab-id=2] input[name=field2]').val()
Here is the fiddle of the working example.
var datastring = $("#contact_form").serialize();
alert(datastring);
try this in jquery after , you wiil get all the elements values between the
...
here data strings gives output as below
name=tj&email=tj#gmail.com&telephone=8888888888&Country=ind&message=msdfdf&name=tj&email=tj#gmail.com&telephone=12345689&subject=sub&subject=sub

Categories