I try to understand why my form action is not taking me to the controller...I press the update button on my modal, which should update info on modal to the database...and when I press it, nothing happens, no error , no message, it just close the modal and that's it. HELP PLS !!!. Here is my code:
FORM
<div id="modal1" class="modal modal-fixed-footer">
<div class="modal-content">
<h3 class="center-align">Actualizar registro</h3>
<div class="row">
<form class="col s12" id="update_form" enctype="multipart/form-data" method="post" action ="<?= base_url()?>admin/update_politic">
<div class="row">
<div class="input-field col s6">
<input id="update_name" type="text" name="name" class="validate">
<label for="first_name">Nombre</label>
</div>
<div class="input-field col s6">
<input id="update_last_name" name="lastname" type="text" class="validate">
<label for="last_name">Apellido</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<input id="update_side" type="text" name="side" class="validate">
<label for="partido">Partido</label>
</div>
<div class="input-field col s6">
<input id="update_charge" type="text" name="charge" class="validate">
<label for="cargo">Cargo</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<div class="file-field input-field no-margin-top">
<div class="btn light-blue darken-4">
<span>Animación/Imagen</span>
<input type="file" name="animation_file">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" id="animation" name="animation" type="text">
</div>
</div>
</div>
<div class="input-field col s6">
<select id="update_section" name="section" autocomplete="off">
<option value="" disabled selected>Seleccione una opción</option>
<option value="1">Presidencia</option>
<option value="2">Senadores</option>
<option value="3">Diputados</option>
</select>
<label>Sección</label>
</div>
</div>
<input type="hidden" name="update_politic_hide" id="update_politic_hdn" value="">
<div class="row">
<button class="btn waves-effect waves-light light-blue darken-4" id="submit_update" type="submit" name="action">Actualizar</button>
</div>
</form>
</div>
</div>
CONTROLLER
public function update_politic(){
echo "entreeeeeeee";
if (empty($_FILES['animation_file']['name']))//Compruebo si el array $_files no tiene ningun valor en su elemento name
{
//El metodo obtenerImagen me retorna los valores de dicho id
$data = $this->politic->get_file_name($this->input->post('update_politic_hide'));
$imagen = $data->POLITIC_FILE;//recupero el nombre de la imagen
}
else{
//en caso exista algun valor se procede a subir
$this->load->library("upload");
$config['upload_path'] = "./public/uploads/";
$config['allowed_types'] = "*";
$config['max_size'] = "500000";
$config['max_width'] = "2000";
$config['max_height'] = "2000";
if (!$this->upload->do_upload("animation")) {
$data['uploadError'] = $this->upload->display_errors();
echo $this->upload->display_errors();
}
else {
$file_info = $this->upload->data();
$params["name"] = $this->input->post("name");
$params["lastname"] = $this->input->post("lastname");
$params["side"] = $this->input->post("side");
$params["charge"] = $this->input->post("charge");
$params["animation"] = $file_info['file_name'];
$params["section"] = $this->input->post("section");
if ($params["section"]=="Presidencia") {
$params["section"]=1;
}
if ($params["section"]=="Senadores") {
$params["section"]=2;
}
if ($params["section"]=="Diputados") {
$params["section"]=3;
}
$this->load->model("politic");
$this->politic->update($params);
}
}
}
You have used base_url()?>admin/update_politic for submitting your form. But you have not mentioned about that controller. If you have admin controller then it will be ok. Otherwise, this is the reason for this submission.
Try This
<?php echo form_open(base_url() . 'admin/update_politic' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));?>
Instead of button use <input type = "submit" value ="Submit" class="your class name here">
Related
i display with a foreach the content of a user_meta in wordpress. It displays input taht fills with the values (so they can be changed). I want to be able to store each content in a new array (so i can update the user_meta next.
So here is the main code :
<?php
function edit_profile_form() {
$current_user_id = get_current_user_id();
$data = get_user_meta ($current_user_id);
if (isset($_POST['button2'])) {
delete_user_meta($current_user_id, 'experiences');
}
if(isset($_POST['button1'])) {
save_extra_profile_fields($current_user_id);
};
$experiences = get_user_meta($current_user_id, 'experiences', true);
?>
<div class="container_form">
<form method="POST">
<h3>Vos expériences</h3>
<div class="experiences_container">
<?php
if (!empty($experiences)) {
$index=0;
foreach ($experiences as $key) {
$index++;
echo($index);
echo($key);
?>
<div class="past_experience">
<div class="experience_header">
<div>
<label for="team">Nom de l'équipe</label>
<input class="team" name="team" value="<?= $key['new_experience_team'];?>"/>
</div>
<div>
<label for="role">Rôle dans l'équipe</label>
<input class="role" name="role" value="<?= $key['new_experience_role'];?>"/>
</div>
</div>
<div class="experience_textarea">
<label for="description">Description du rôle</label>
<textarea class="description" name="description"><?= $key['new_experience_description']; ?></textarea>
<label for="palmares">Palmarés avec l'équipe</label>
<textarea class="palmares" name="palmares"><?= $key['new_experience_palmares']; ?></textarea>
</div>
</div>
<?php
}
} else {
?>
<div><p>Vous n'avez encore rentré aucune expérience</p></div>
<?php
}?>
</div>
<div class="add_container">
<div id="dropdown">
<i class="fas fa-plus-square" style="margin-right: 5px;"></i>
<p id="show" onClick="dropdown()" >Ajouter une expérience</p>
</div>
<div id="experience" style="display:none;">
<label for="new_experience_team">Nom de l'équipe</label>
<input type="text" name="experiences[new_experience_team]" id="experience_team">
<label for="new_experience_role">Rôle dans l'équipe</label>
<input type="text" name="experiences[new_experience_role]" id="experience_role">
<label for="new_experience_description">Description du poste</label>
<textarea type="text" name="experiences[new_experience_description]" id="experience_description"></textarea>
<label for="new_experience_palmares">Palmarés</label>
<textarea type="text" name="experiences[new_experience_palmares]" id="experience_palmares"></textarea>
</div>
</div>
<div id="button_container">
<input type="submit" name="button1" value="Sauvegarder" id='save'/>
<input type="submit" name="button2" value="Annuler"/>
</div>
</form>
</div>
The function's one :
<?php
function save_extra_profile_fields( $user_id ) {
if (!empty($_POST['experiences'])) {
$savedexperience = get_user_meta($user_id, 'experiences', true);
if (!empty($savedexperience) && is_array($savedexperience )) {
$experiences = $savedexperience;
}
$experiences[] = $_POST['experiences'];
update_usermeta($user_id, 'experiences', $experiences);
}
}
So i want to be able to stock in a array each group of team, role, description and palmares.
I don't know if it's clear at all :/
Thanks all
I come here to ask for help because despite the many topics on this subject, no answer allowed me to solve my problem:
The principle is simple: I have a form below with a div containing a captcha, my HTML also contains the script to load the captcha:
<form id="contactformpage">
<div class="messages"></div>
<div class="form-group row">
<label for="societepage" class="col-sm-6 col-form-label">Société</label>
<div class="col-sm-6 champ">
<input type="text" name="societe" class="form-control" id="societepage" placeholder="Nom de la société"
aria-describedby="indicsocietepage" required pattern =".{1,100}">
<small id="indicsociete" class="form-text text-muted"> * Obligatoire </small>
</div>
</div>
<div class="form-group row">
<label for="adressepage" class="col-sm-6 col-form-label">Adresse</label>
<div class="col-sm-6 champ">
<input type="text" name="adresse" class="form-control" id="adressepage" placeholder="Adresse">
</div>
</div>
<div class="form-group row">
<label for="codepostaletvillepage" class="col-sm-6 col-form-label">Code postal & ville</label>
<div class="col-sm-6 champ">
<input type="text" class="form-control" name="codepostaletville" id="codepostaletvillepage"
placeholder="Code postal & ville">
</div>
</div>
<div class="form-group row">
<label for="contactpage" class="col-sm-6 col-form-label">Nom du contact</label>
<div class="col-sm-6 champ">
<input type="text" class="form-control" name="contact" id="contactpage" placeholder="Nom du contact">
</div>
</div>
<div class="form-group row">
<label for="telephonepage" class="col-sm-6 col-form-label">Téléphone</label>
<div class="col-sm-6 champ">
<input type="tel" class="form-control" name="téléphone" id="telephonepage" placeholder="Numéro de téléphone"
aria-describedby="indictelephonepage" required pattern="^(?:0|\(?\+33\)?\s?|0033\s?)[1-79](?:[\.\-\s]?\d\d){4}$">
<small id="indictelephonepage" class="form-text text-muted"> * Obligatoire </small>
</div>
</div>
<div class="form-group row">
<label for="mailpage" class="col-sm-6 col-form-label">Adresse mail</label>
<div class="col-sm-6 champ">
<input type="email" class="form-control" name="mail" id="mailpage" placeholder="Entrez votre adresse mail"
aria-describedby="indicmailpage" required>
<small id="indicmailpage" class="form-text text-muted"> * Obligatoire </small>
</div>
</div>
<div class="form-group row">
<label class="col-sm-6 col-form-label" for="selecmarque" aria-describedby="indicmarquepage"> Marque du véhicule
</label>
<div class="col-sm-6 champ">
<select class="form-control" name="marque" style="height:20px;padding-bottom:0;padding-top:1;"
onchange="generechoixmodele('selecmarque','apreschoixmarquepage','apreschoixmodelepage','nommodelepage','choixmodelepage','choixtypepage');"
id="selecmarque">
<option selected> Séléctionnez </option>
</select>
<small id="indicmarquepage" class="form-text text-muted"> * Obligatoire </small>
</div>
</div>
<div class="form-group row" id="apreschoixmarquepage" style="display:none;">
<!-- Liste déroulante qui apparait après le choix de la marque -->
<label class="col-sm-6 col-form-label" for="apreschoixmarquepage" aria-describedby="indicmarque"
id="nommodelepage"></label>
<div class="col-sm-6 champ">
<select class="form-control" name="modele" style="height:20px;padding-bottom:0;padding-top:1;"
id="choixmodelepage"
onchange="generechoixtype('selecmarque','choixmodelepage','apreschoixmodelepage','nomtypepage','choixtypepage');">
</select>
</div>
</div>
<div class="form-group row" id="apreschoixmodelepage" style="display:none;">
<!-- Liste déroulante qui apparait après le choix du modèle -->
<label class="col-sm-6 col-form-label" for="apreschoixmodelepage" aria-describedby="indicmarque"
id="nomtypepage"></label>
<div class="col-sm-6 champ">
<select class="form-control" name="type" style="height:20px;padding-bottom:0;padding-top:1;" id="choixtypepage">
</select>
</div>
</div>
<p> Je souhaite recevoir les catalogues suivants (dynamique)</p>
<div id="choixcataloguepage">
</div>
<div class="form-group row">
<label class="col-sm-6 col-form-label" for="commentairepage">Commentaire</label>
<div class="col-sm-6 champ">
<textarea class="form-control" name="commentaire" id="commentairepage" rows="1"></textarea>
</div>
</div>
<div class="form-group row" style="margin-top:5px;">
<label for="captchapage" class="col-sm-6 col-form-label" style="margin-top:10px;">Captcha</label>
<div class="col-sm-6 champ captcha" >
<div class="g-recaptcha" id="captchapage" data-sitekey="6LfYqq8UAAAAAGi_ImKvNYvAhNLysLCf9SoD3gZd" data-badge="inline" style="transform:scale(0.74);-webkit-transform:scale(0.74);transform-origin:0 0;-webkit-transform-origin:0 0;"> </div>
</div>
</div>
<input type="submit" class="btn" id="submitpage">
</form>
Then during the validation of this form I retrieve the data entered in the form, and also the response of the captcha brought by Google (the "grecaptcha.getResponse ()"), in order to send them on a php page with an Ajax request:
$(document).ready(function(){
$("#contactformpage").submit(function(e){
e.preventDefault();
if (document.getElementById("selecmarque").value=="Séléctionnez") {
alert("Séléctionnez une marque (Obligatoire)");
}
else {
var cases = document.getElementById("contactformpage").getElementsByClassName("form-check");
var catalogues = [];
for (var i = 0; i < cases.length; i++) {
if ($(cases[i].firstChild).prop("checked")==true) {
catalogues[i]=cases[i].lastChild.innerHTML;
}
else {
}
}
$.ajax({
type: "POST",
url: 'sendform.php',
data: {
societe : $("#societepage").val(),
adresse : $("#adressepage").val(),
codepostaletville : $("#codepostaletvillepage").val(),
contact : $("#contactpage").val(),
telephone : $("#telephonepage").val(),
mail : $("#mailpage").val(),
marqueclient : $("#selecmarque").val(),
modeleclient : $("#choixmodelepage").val(),
typeclient : $("#choixtypepage").val(),
catalogues : JSON.stringify(catalogues),
commentaire : $("#commentairepage").val(),
captcha: grecaptcha.getResponse()
},
success: function (data)
{
var messageAlert = 'alert-' + data.type;
var messageText = data.message;
// let's compose Bootstrap alert box HTML
var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' + messageText + '</div>';
// If we have messageAlert and messageText
if (messageAlert && messageText) {
// inject the alert to .messages div in our form
$('#contactformpage').find('.messages').html(alertBox);
// empty the form
$('#contactformpage')[0].reset();
grecaptcha.reset();
}
},
error: function(xhr, status, error){
var errorMessage = xhr.status + ': ' + xhr.statusText
alert('Error - ' + errorMessage);
}
})
}
});
});
Here is the php script where I get the answer of the captcha and according to this answer I perform a task or an other :
try {
if (isset($_POST['captcha'])) {
$captcha = $_POST['captcha'];
$privatekey='6LfYqq8UAAAAAJHL90FXgdCjEIDYtY2HhkGw7sbs';
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => $privatekey,
'response' => $captcha,
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$curlConfig = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data
);
$ch = curl_init();
curl_setopt_array($ch, $curlConfig);
$response = curl_exec($ch);
curl_close($ch);
$jsonResponse = json_decode($response);
var_dump($response);
if ($jsonResponse->success === true) {
}
else {
throw new \Exception('Vous êtes un robot');
}
}
}
My problem is that the script validates the condition $jsonResponse->success === true all the time, I tried to make a var_dump($jsonResponse) and this one is always null. Here is the data sent when I execute my Ajax request :
Data sent with Ajax request
I been trying to figure out where my mistake is without success. I get no reported errors. I want to insert data into the supplier table from a PHP form. id_drugstore is a foreign key into the supplier table and can be chosen form a drop-down list (drop-down is working perfect). Another date is filled in by the user, except id_supplier.
<?
error_reporting(-1);
$conn = mysqli_connect("localhost", "root", "", "retete");
if(mysqli_connect_errno())
{
echo "Nu ma pot conecta la baza de date medical:" .mysqli_connect_error();
}
if(isset($_POST['submit']){
$id_drugstore=$_POST['id_drugstore'];
$name_suplier=$_POST['name_suplier'];
$country_supplier=$_POST['county_supplier'];
$county_supplier=$_POST['county_supplier'];
$town_supplier=$_POST['town_supplier'];
$street_supplier=$_POST['street_supplier'];
$bank_suplier=$_POST['bank_suplier'];
$no_cont_Bank=$_POST['$no_cont_Bank'];
$qry=mysqli_query("INSERT INTO supplier `VALUES('sss','%$id_drugstore%',$_POST['name_suplier']','$_POST['county_supplier']','$_POST['county_supplier']','$_POST['town_supplier']','$_POST['street_supplier']','$_POST['bank_suplier']','$_POST['$no_cont_Bank']";`
$inserted=($qry,$conn);
if($inserted){
echo "Datele au fost inserate cu suucess";
}else{
echo "datele nu au putut fi salvate in baza de date".mysqli_error($conn);
}
}
mysqli_close($conn);
}
?>
<body>
<div class="jumbotron">
<div class="container">
<h4 class="display-5">Adaugare Furnizori in baza de date</h4>
<p class="lead">Completati formularul de mai jos</p>
</div>
</div>
<form action="AdaugareFurnizori.php" method="POST">
<div class="form-row">
<div class="col-md-2 mb-3">
<label for="validationServer01">Farmacie</label>
<select name="name_drugstore">
<option>Selecteaza farmacie</option>
<?php
$conn = mysqli_connect("localhost", "root", "", "retete");
if(mysqli_connect_errno()){
echo "Nu ma pot conecta la baza de date medical:".mysqli_connect_error();
}
$q=mysqli_query($conn,"SELECT * FROM drugstore")or die(mysqli_error());
$c=mysqli_num_rows($q);
if($c==0){
echo 'Nu exista farmacie in baza de date';
}else{
while($row=mysqli_fetch_array($q)){
$id_drugstore=$row['id_drugstore'];
$name_drugstore=$row['name_drugstore'];
echo "<option value='$id_drugstore'>$id_drugstore/$name_drugstore<option>
}
}
mysqli_close($conn);
?>
</select>
</div>
</div>
<div class="form-row">
<div class="col-md-4 mb-3">
<label for="validationServer01">Denumire Furnizori</label>
<input type="text" name="name_suplier" class="form-control is-valid" id = "validationServer01" placeholder="Denumire Furnizor" required>
</div>
</div>
<div class="form-row">
<div class="col-md-2 mb-3">
<label for="validationServer02">Tara</label>
<input type="text" name="country_supplier" class="form-control is-valid" id="validationServer02" placeholder="Tara" required>
<div class="invalid-feedback">
Va rugam sa introduceti tara.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer03">Judet</label>
<input type="text" name="county_supplier" class="form-control is-valid" id="validationServer03" placeholder="Judet" required>
<div class="invalid-feedback">
Va rugam sa introduceti judetul.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer04">Oras</label>
<input type="text" name="town_supplier"class="form-control is-valid" id="validationServer04" placeholder="Oras" required>
<div class="invalid-feedback">
Va rugam sa introduceti orasul.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer05">Strada si numar</label>
<input type="text" name="street_supplier" class="form-control is-valid" id="validationServer05" placeholder="Strada" required>
<div class="invalid-feedback">
Va rugam sa introduceti strada.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer04">Banca</label>
<input type="text" name="bank_suplier"class="form-control is-valid" id="validationServer04" placeholder="Denumire Banca" required>
<div class="invalid-feedback">
Va rugam sa introduceti banca.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer05">Cont</label>
<input type="text" name="no_cont_Bank" class="form-control is-valid" id="validationServer05" placeholder="Numar Cont" required>
<div class="invalid-feedback">
Va rugam sa introduceti numarul contului.
</div>
</div>
<div class="submit">
<button class="btn btn-primary" type="submit">Submit form</button>
</div>
</div>
</form>
</body>
</html>
That query looks strange:
$qry=mysqli_query("INSERT INTO supplier `VALUES('sss','%$id_drugstore%',$_POST['name_suplier']','$_POST['county_supplier']','$_POST['county_supplier']','$_POST['town_supplier']','$_POST['street_supplier']','$_POST['bank_suplier']','$_POST['$no_cont_Bank']";`
Remove the backticks `
Missing an opening ' before $_POST['name_suplier']'
All of your $_POST variables in that string will never get replaced, put them in curly brackts: {$_POST['name_suplier']}
Make sure you have no typos in there name_suplier vs. town_supplier
Missing a closing bracket at the end of the query AND as a closing bracket for mysql_query()
Side note: Shouldn't there be a list of fields in that INSERT too?
your code should be.
If your supplier table have all this field which you are going to insert then this will works fine but if u skip any of the field then mysqli_query does not work
$qry="INSERT INTO supplier `VALUES('sss','%$id_drugstore%',$_POST['name_suplier']','$_POST['county_supplier']','$_POST['county_supplier']','$_POST['town_supplier']','$_POST['street_supplier']','$_POST['bank_suplier']','$_POST['$no_cont_Bank']')";
$inserted=mysqli_query($qry,$conn);
I'm trying to insert data to MySQL with a form that is in a Bootstrap modal but it doesn't work.
I don't know why but my form method is POST and it seems to be a GET because it prints the data in the web address.
When I try to insert the data through a basic form with the same php code (no format, simple as hell) it inserts the data.
Here's my form in the bootstrap modal.
<div class="container 2">
<button type="button" class="btn btn-primary btn-lg btn-block" data-toggle="modal" data-target="#newRoute">
CREAR NUEVA RUTA
</button>
<div class="modal fade" id="newRoute" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<form class="route" method="post">
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label for="name">Ponle un nombre a la ruta</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="form-group">
<label for="city">Ciudad</label>
<input type="text" class="form-control" id="city" name="city" required>
</div>
<div class="form-group">
<label for="length">Distancia</label>
<input type="text" class="form-control" id="length" name="length" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label for="start_point">Punto de salida</label>
<input type="text" class="form-control" id="start_point" name="start_point"
required>
</div>
<div class="form-group">
<label for="difficulty">Dificultad</label>
<input type="text" class="form-control" id="difficulty" name="difficulty"
required>
</div>
<div class="form-group">
<label for="date">Fecha de la ruta</label>
<input type="date" class="form-control" id="date" name="date" required>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<label for="description">Detalles de la ruta</label>
<textarea class="form-control" rows="5" id="description"
name="description"></textarea>
</div>
</div>
<div class="modal-footer">
<div class="form-group">
<button type="submit" name="submit" id="submit" class="btn btn-primary"
value="Enviar">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
and here is my PHP code
include('db/db.php');
if(isset($_POST['submit'])) {
// Adjudicar name a variable
$name = stripslashes($_POST['name']);
$name = mysqli_real_escape_string($conn, $name);
// Adjudicar city a variable
$city = stripslashes($_POST['city']);
$city = mysqli_real_escape_string($conn, $city);
// Adjudicar length a variable
$length = stripslashes($_POST['length']);
$length = mysqli_real_escape_string($conn, $length);
// Adjudicar start_point a variable
$start_point = stripslashes($_POST['start_point']);
$start_point = mysqli_real_escape_string($conn, $start_point);
// Adjudicar difficulty a variable
$difficulty = stripslashes($_POST['difficulty']);
$difficulty = mysqli_real_escape_string($conn, $difficulty);
// Adjudicar date a variable
$date = stripslashes($_POST['date']);
$date = mysqli_real_escape_string($conn, $date);
// Adjudicar description a variable
$description = stripslashes($_POST['description']);
$description = mysqli_real_escape_string($conn, $description);
// QUERY
$query = "INSERT INTO routes (name, city, length, start_point, difficulty, user_id, date, description) VALUES ('$name','$city',$length,'$start_point','$difficulty',".$_SESSION['id'].",'$date','$description')";
// Se realiza la query
$result = mysqli_query($conn,$query);
//Condición si se realiza la query correctamente
if($result){
header("Location: routes.php");
echo '<script type="text/javascript">alert("'.$query.'");</script>';
}else{
echo '<script>alert("ERROR");</script>';
}}
my db.php (connection to database)
$conn = new mysqli('localhost', 'root', "", 'users');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
Thanks in advance!
PS. When I submit the form, this is what appears in the address (all the fields were filled by sample text). It seems to be a get form.
http://localhost/Proyecto/routes.php?name=Test&city=Test&length=20&start_point=Test&difficulty=Test&date=2018-05-12&description=Test+description&submit=Enviar
Try to check if you have forget to close any other form somewhere on your code that should be with method="get" or without method attribute
and so when you submit the data it gets the method from that form.
The code you have publish here should work correctly.
Your form code is correct, I have checked it on my system. You must be checking/testing some other page or form.
i have a problem with the validation form. It does not work if i put "required", example:
controller:
public function updateBenefit(){
$result = array();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('beneficio', 'Nombre del Beneficio', 'required|alpha');
$this->form_validation->set_rules('info', 'Info', 'alpha');
$this->form_validation->set_rules('descrip', 'Descripción', 'alpha');
$this->form_validation->set_rules('orden', 'Orden', 'integer');
// $this->form_validation->set_rules('fecha', 'Fecha', 'date_valid');
$this->form_validation->set_message('required', 'El campo %s es requerido');
if ($this->form_validation->run() == TRUE){
if (isset($_POST['id'])){
$idb = $_POST['id'];
$benefit = BeneficiosManager::getInstance()->getHome($idb);
$result['message'] = "Se ha modificado el Beneficio con éxito";
} else{
$benefit = BeneficiosManager::getInstance()->create();
$result['message'] = "Se ha cargado el Beneficio con éxito";
}
$benefit->nombre = ucfirst(strtolower($_POST['beneficio']));
$benefit->content = ucfirst(strtolower($_POST['descrip']));
$benefit->intro = ucfirst(strtolower($_POST['info']));
$benefit->active = $_POST['optionsRadios2'];
$benefit->orden = $_POST['orden'];
// $benefit->date = $_POST['fecha'];
BeneficiosManager::getInstance()->save($benefit);
}else{
//no se validaron los datos ingresados
$result['message'] = "Error validación";
}
echo json_encode($result);
}
view:
{extends file='admin/base/base.tpl'}
{block name='content'}
<h3>Cargar Beneficio </h3>
</br>
<form action="{site_url()}admin/updateBenefit" class="form-horizontal" method="post" id="" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label">Beneficio</label>
<div class="controls">
<input type="text" name="beneficio" value="" class="m-wrap medium" />
<span class="help-inline">Nombre del Beneficio</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Info</label>
<div class="controls">
<textarea name="info" class="medium m-wrap" rows="3"></textarea>
<span class="help-inline">Información Clave</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Descripción</label>
<div class="controls">
<textarea name="descrip" class="large m-wrap" rows="3"></textarea>
<span class="help-inline">Descripción del Beneficio</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Activo</label>
<div class="controls">
<label class="radio line">
<input type="radio" name="optionsRadios2" value="1"/>Si</input>
</label>
<label class="radio line">
<input type="radio" name="optionsRadios2" value="0"/>No</input>
</label>
<span class="help-inline">Ofrecer Beneficio</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Orden</label>
<div class="controls">
<input type="text" name="orden" value="" class="m-wrap small" />
<span class="help-inline">Prioridad del Beneficio</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Fecha</label>
<div class="controls">
<input type="text" name="fecha" value="{$smarty.now|date_format}" class="m-wrap medium" />
<span class="help-inline"></span>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn blue"><i class="icon-ok"></i> Guardar</button>
<button type="button" class="btn">Cancelar</button>
</div>
</form>
{/block}
what might the problem be?
if i remove the "required" field, the form validates... but if i put it, it doesn't... i don't know what else to try, can't understand why this is happening
the code is working now, thanks to #Jonathan that corrected me, and i was also making an imput mistake when i was trying this method. I was trying to put two words in the same field (i.e: bon vivir); so the correct input would be: bonvivir.
I'm not sure you are using "title" as the name of your real title input element. Because I found you use this code to assign your title.
$benefit->title = ucfirst(strtolower(trim($_POST['beneficio'])));
So you may want to try to use
$this->form_validation->set_rules('beneficio', 'Nombre del Beneficio', 'required|alpha');
instead.
I am not sure I had the right guess. Just give it a go. Hope this helps.