Html form not calling the action - php

I have a form that opens in a modal.
And the submit is not working, it is not calling the action.
I have set the method post, and action is supposed to call a php file.
However, it isnt working at all.
Here is the code, and you can test it here:
http://mentores.in/comprar.html
Click in "comprar" to open the modal.
<section id="first-step" class="wc-billing-step">
<div class="woocommerce-billing-step-one">
<h4>
Dados do Participante
</h4>
<form id="contact-form" method="post" action="enviar_inscricao.php">
<input type="text" name="nome" placeholder="Nome do participante">
<input type="text" name="cpf" placeholder="CPF">
<input type="text" name="nasc" placeholder="Data de Nascimento" onkeyup="
var date = this.value;
if (date.match(/^\d{2}$/) !== null) {
this.value = date + '-';
} else if (date.match(/^\d{2}\-\d{2}$/) !== null) {
this.value = date + '-';
}" maxlength="10">
<input type="email" name="email" placeholder="E-mail">
<input type="text" name="celular" placeholder="Celular">
<input type="text" name="end" placeholder="Endereço">
<input type="text" name="cid" placeholder="Cidade">
<input type="text" name="esta" placeholder="Estado">
<input type="text" name="cep" placeholder="CEP">
<p>Caso seja menor de idade</p>
<input type="text" name="resp" placeholder="Nome do responsável">
<input type="text" name="tel" placeholder="Telefone">
<p>Caso o pagamento seja em nome de terceiro</p>
<input type="text" name="pagseg" placeholder="Nome do titular do cartão">
<!-- <input type="text" placeholder="Produtores"> -->
<select type="text" name="indi" value="" class="form-control" placeholder="Quem te indicou?">
<option value="Escolha">Escolha uma opção</option>
<option value="Marcelo Caldas">Marcelo Caldas</option>
<option value="Nenhum desses">Nenhum desses</option>
</select>
<input class="price-btn subm" type="submit" name="submit-form" value="Continuar" id="accept" />
</form>
</div>
</section>
I need that form to call the php page in the action.

You had defined an on click behaviour on price-btn to open the modal.
$('.price-btn').on('click', function(e) {
So you need to be more specific with your selectors because your Form hast the same selector.

Either use this url like: "/enviar_inscricao.php " (add a slash to the front),
or enter the full url.

Related

How to get the page title into a input's value?

I want my hidden input field to get the page title as its value.
This is my testmail.php code.
<p>From: <?php echo $_POST['name']; ?></p>
<p>Subject: <?php echo $_POST['subject']; ?></p>
<p>Email: <?php echo $_POST['email']; ?></p>
<p>Phone Number: <?php echo $_POST['phone']; ?></p>
<p style="width:300px;">Message: <?php echo $_POST['message']; ?></p>
and this is my form code
<form action="testmail.php" method="post" class="cf">
<label for="name">* Name:</label>
<input type="text" name="name" placeholder="Your Name">
<input type="hidden" name="subject" value="<?php value $_POST['pagetitle']; ?>">
<label for="email">* Email:</label>
<input type="text" name="email" placeholder="Enter a valid Email Address">
<label for="phone"> Phone:</label>
<input type="text" name="phone" placeholder="Enter areacode and number">
<label for="message">* Message:</label>
<textarea name="message"></textarea>
<button type="input">Send</button>
</form>
Is there a way to get the title automatically?
Here's a pure javascript way using the onsubmit event.
<form onsubmit="this.subject.value=document.title;">
<input type="text" name="subject" value="" />
<input type="submit" />
</form>
To give you a better understanding of the onsubmit event as the name suggests it executes the contained javascript when the user submits the form. The operation this.subject.value=document.title working from right to left basically says assign the value of document.title to the value attribute of the element with the name of subject in this specific form.
Using your existing form it should look like this (I added the onsubmit event and fixed up errors in your html as well as added the appropriate id's to form elements):
<form action="testmail.php" method="post" class="cf" onsubmit="this.subject.value=document.title;">
<label for="name">* Name:</label>
<input type="text" id="name" name="name" placeholder="Your Name" />
<input type="hidden" name="subject" value="" />
<label for="email">* Email:</label>
<input type="text" id="email" name="email" placeholder="Enter a valid Email Address" />
<label for="phone"> Phone:</label>
<input type="text" id="phone" name="phone" placeholder="Enter areacode and number" />
<label for="message">* Message:</label>
<textarea id="message" name="message"></textarea>
<input type="submit" name="submit" value="submit" />
</form>
This will set the value of your hidden input field once the page has finished loading.
<script>
$(function() {
$('input[name="subject"]').val($('title').text());
});
</script>
You can use JavaScript to do so, assuming you're using jQuery, bind submit event to your form
$('your_form_selector').on('submit', function(){
$('<input />').attr('type', 'hidden')
.attr('name', 'title')
.attr('value', document.title)
.appendTo($(this));
});

AngularJS | How to Send the Data of Json to database in Codeigniter

I am trying to use Angular.
I am trying to Post Form of Angular, which have been done successfully, it is posting in JSON, But Problem is it only Post the input fields which have values, if i have NOT filled a textbox then it will NOT post that textbox value and fieldname, so how to know in controller which input fields have been posted.
Also how to send it to the model??
Here what i have done so far.
View.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
<link href="<?php echo base_url(); ?>/styles/formcss.css" rel="stylesheet" type="text/css"/>
<script src="<?php echo base_url(); ?>/scripts/angular.min.js"></script>
</head>
<body ng-app>
<div ng-controller="controller">
<form>
<label for="name">UserID:</label> <input type="text" name="UserID" ng-model="user.UserID" value=""><br>
<label for="UserName">Name:</label> <input type="text" name="UserName" ng-model="user.UserName" value=""><br>
<label for="rollno">In Game Name:</label> <input type="text" name="GameName" ng-model="user.InGameName" value="" ><br>
<label for="father">CNIC Number:</label> <input type="number" name="Cnic" ng-model="user.Cnic" value="" ><br>
<label for="age">Age:</label> <input name="Age" ng-model="user.Age" type="number" value="" ><br>
<label for="email1">Email:</label> <input name="Email" ng-model="user.Email" type="email" value="" ><br>
<label for="email2">Res enter Email:</label> <input id="email2" type="email" name="email2" value="" ><br>
<label for="pass1">Password:</label> <input id="pass1" type="password" name="Pass" ng-model="user.Password" value=""><br>
<label for="pass2">Re enter Password:</label> <input id="pass2" type="password" name="pass2" value="" ><br>
<label style="margin-bottom:-10px; " for="male">Male</label><input class="gen" ng-model="user.Gender" id="male" type="radio" name="g" value="Male"><br>
<label style="margin-bottom:15px;" for="female">Female</label><input class="gen" ng-model="user.Gender" id="female" type="radio" name="g" value="Female"><br>
<label class="dis" for="about" >About:</label> <textarea rows="5" cols="40" id="about" type="text" value=""></textarea><br>
<button style="margin-left: 225px;" ng-click="save()" >Save</button>
</form>
</div>
<script>
function controller ($scope,$http)
{
var angularform="<?php echo base_url(); ?>index.php/datacon/angform"
$scope.save=function()
{
$http.post(angularform, $scope.user);
}
}
</script>
</body>
</html>
Controller:
public function angform()
{
$get=file_get_contents('php://input');
$json_get=json_decode($get);
foreach($json_get as $key=>$value){
// i think something it has to do here.
}
$this->load->model('datamodel');
$this->datamodel->insert($data);
}
here is the screenshot, i have filled three fields so it posted the values of three fields only.
public function angform()
{
$get=file_get_contents('php://input');
$json_get=json_decode($get);
foreach($json_get as $key=>$value){
$data[$key]=$value; //Worked For Me.
}
$this->load->model('datamodel');
$this->datamodel->insert($data);
}
i check like this :-
if($this->input->get_post('male'))
{
// rest code goes here
}
Change your input name to match exactly like the database attribute(column) name. In that way you will not have to check anything:
$data = $this->input->post(null); #get the post array
$this->db->insert('table', $ata);

jquery to update dropdown menu from textbox

I am new to jquery. I have a textbox, and I want to take value from a textbox and show it in dropdown menu. I have searched for the solution in many websites,but can't get an appropriate answer. Kindly please help me how to do it in jquery.
The code for textbox are shown below. Thanks in advance, and sorry for my english.
<form method="post" action="inq.php">
<p><br>
<b>Question no:</b><br>
<input class="inp-form" type="Text" name="qno" size="30" required>
<br>
<br>
<b>Question:</b><br>
<textarea name="question" rows="4" cols="50" required></textarea>
<!--<input class="inp-form"type="Text" name="question" size="50">-->
<br>
<b>Option 1:</b><br>
<input class="inp-form" type="Text" name="opt1" size="30" required>
<br>
<b>Option 2:</b><br>
<input class="inp-form"type="Text" name="opt2" size="30" required>
<br>
<b>Option 3:</b><br>
<input class="inp-form"type="Text" name="opt3" size="30" required>
<br>
<b>Option 4:</b><br>
<input class="inp-form" type="Text" name="opt4" size="30" required>
<br>
<b>Answer</b> (must be identical to correct option):<br>
<input class="inp-form" type="Text" name="answer" size="30" required>
<br>
<br>
<input class="form-submit" type="Submit" name="submit" value="Add" required>
</p>
</form>
Try this. Add another class to options text box (i.e) option like below.
Add onclick="AddQS()" to submit button.
Add one dropdown box.
function AddQS() {
$('#sltOptions').empty();
$('.option').each(function() {
$('#sltOptions').append('<option value = ' + $(this).attr('name') + '>' + $(this).val() + '</option>');
});
}
<------------------>
<input class="inp-form option" type="Text" name="opt1" size="30" required>
<------------------>
<input class="form-submit" type="Submit" name="submit" value="Add" onclick="AddQS()" required>
<------------------>
<select id="sltOptions">
</select>
Please have a look at http://jsfiddle.net/2dJAN/47/
$('.options').change(function(){
var val = $(this).val().trim();
$("#answer").append("<option value='"+val+"'>"+val+"</option>");
});
Let me know is this example full fill your requirement or not.

formname.submit not working on IE8

I am currently developing an app and i am getting difficulties on IE8.
I have the following code:
<form class="fillClaimForm" name="fillClaimForm" method="POST" enctype="multipart/form-data" action="<?php print BASE_URL; ?>?action=insertBlogger" >
<label for="fblogName">Blog's name: </label>
<input type="text" name="fblogName" id="fblogName" class="cfInput" placeholder ="Complex" required />
<label for="fblogUrl">URL: </label>
<input type="text" name="fblogUrl" id="fblogUrl" class="cfInput" placeholder ="www.complex.com" required />
<label>Blog's logo: </label>
<div class="upload-file-container"><span>UPLOAD</span>
<input type="file" name="fblogLogo" id="fblogLogo"/>
<p class="ErrLoad error" style="display:none;">Please load your logo</p>
</div>
<label for="fEmail">Email adresse: </label>
<input type="email" name="fEmail" id="fEmail" class="cfInput" required />
<label for="frNum">Phone number: </label>
<input type="tel" name="frNum" id="frNum" class="cfInput" required />
<input type="hidden" name="idVid" id ="idVid" value=""/>
<input type="hidden" name="idRubrique" id ="idRubrique" value=""/>
<button id="sendClaim" class="sendClaim">SEND</button>
Consequently, I am doing a form submission using jquery:
......submit(function(){
validate=false;
formInfo = validateForm(validate,$thisLi);
if(formInfo.validate){
**fillClaimForm.submit();**
}
return false;
});
It is working on all browsers except IE8
Can someone kindly help me.
Thanks
Close your form.
Also give the same name as the id for your form and use
$("#formId").submit();
Code
<form class="fillClaimForm" name="fillClaimForm" method="POST" enctype="multipart/form-data" action="<?php print BASE_URL; ?>?action=insertBlogger" >
<label for="fblogName">Blog's name: </label>
<input type="text" name="fblogName" id="fblogName" class="cfInput" placeholder ="Complex" required />
<label for="fblogUrl">URL: </label>
<input type="text" name="fblogUrl" id="fblogUrl" class="cfInput" placeholder ="www.complex.com" required />
<label>Blog's logo: </label>
<div class="upload-file-container"><span>UPLOAD</span>
<input type="file" name="fblogLogo" id="fblogLogo"/>
<p class="ErrLoad error" style="display:none;">Please load your logo</p>
</div>
<label for="fEmail">Email adresse: </label>
<input type="email" name="fEmail" id="fEmail" class="cfInput" required />
<label for="frNum">Phone number: </label>
<input type="tel" name="frNum" id="frNum" class="cfInput" required />
<input type="hidden" name="idVid" id ="idVid" value=""/>
<input type="hidden" name="idRubrique" id ="idRubrique" value=""/>
<button id="sendClaim" class="sendClaim">SEND</button>
</form>
$("#sendClaim").click(function(){
validate=false;
formInfo = validateForm(validate,$thisLi);
if(formInfo.validate){
$("#fillClaimForm").submit();
}
return false;
});
Try this:
document.forms.fillClaimForm.submit();
Or if the ...... in your code represents creating of a submit handler on that same form you can probably just say this.submit().

Form submit not posting Safari

I've got a registration form setup which works fine on all browsers...except Safari.
I thought it should be a problem that deals with Javascript, as it mostly is. But after I turned Javascript off in Safari, there's still no data being posted.
The form is live on:
http://tpgrf.nl/testserver/alpha/account/registreer/
I've added this text on top of the page, for testing, to make sure if data has been posted or not.
if($_SERVER['REQUEST_METHOD'] == 'POST'){
echo 'post';
}else{
echo 'niets gepost';
}
Any thoughts where to look for the answer?
EDIT: Here's the form (output HTML)
<form name="registerform" id="registerform" action="http://tpgrf.nl/testserver/alpha/account/registreer/" method="post">
<script type="text/javascript">
jQuery(document).ready(function($) {
//Since we want users to login with there email; there's no need to also register a username. Therefore the username field = email field
$("#user_login").live('change', function(){
$('#user_email').val($("#user_login").val());
});
//Display fields, depending on the selected role
$('#role').live('change', function(){
if($('#role').val() === 'docent'){
$('#messageRegisterDocent').show();
$('#pKlas').hide();
}else{
$('#messageRegisterDocent').hide();
$('#pKlas').show();
}
});
//The json call to automcplete School
var ajaxurl = 'http://tpgrf.nl/testserver/alpha/wp-admin/admin-ajax.php';
$("#school").autocomplete({
delay: 0,
minLength: 1,
source: function(req, response){
$.getJSON('http://tpgrf.nl/testserver/alpha/wp-admin/admin-ajax.php?callback=?&action=school_autocomplete', req, response);
},
select: function(event, ui){
$('#school').val(ui.item.label);
$('#school_id').val(ui.item.school_id);
}
});
});
</script>
<p>
<input type="hidden" name="user_email" id="user_email" class="input" value="" size="20" />
<p>
<label for="user_login">E-mail</label>
<input type="email" name="user_login" id="user_login" class="input" value="" size="20" />
</p>
<p>
<label>Voornaam</label>
<input id="first_name" type="text" size="25" value="" name="first_name" />
</p>
<p>
<label>Achternaam</label>
<input id="last_name" type="text" size="25" value="" name="last_name" />
</p>
<p>
<label>Ik ben...</label>
<select name="role" id="role">
<option value="">...selecteer</option>
<option value="leerling" >Leerling</option>
<option value="docent" >Docent</option>
</select>
<p class="message" id="messageRegisterDocent" style="display:none;"><strong>Let op:</strong> registreer met uw e-mailadres van de school waar u werkzaam bent. <br />Voor een aantal functies vindt namelijk handmatige autorisatie plaats; dit is niet mogelijk met een privé e-mailadres.</p>
</p>
<p>
<label>Mijn school</label>
<input type="text" id="school" class="autoComplete" size="25" value="" name="school" />
<input type="hidden" id="school_id" name="school_id" value="">
</p>
<p id="pKlas"style="display:none;">
<label>Mijn klas</label>
<input type="text" id="klas" size="25" value="" name="klas" />
</p>
<p id="reg_passmail">U zult een wachtwoord per e-mail ontvangen.</p>
<p class="submit">
<input type="submit" name="wp-submit" id="wp-submit" value="Registratie" />
of Ik heb al een account...
<input type="hidden" name="redirect_to" value="/testserver/alpha/account/login/?checkemail=registered" />
<input type="hidden" name="instance" value="" />
</p>
</form>
Your problem might be caused by the following line of code:
<input type="submit" name="wp-submit" id="wp-submit" value="Registratie" />
You wrap the submit button tag inside an 'a' tag which is pointing to an empty URL and causes a link to the current page only. It might be that Safari does not parse this wrapped button well, and instead prefers the A link over the submit button.
Unwrapping the 'input' tag and changing the code to:
<input type="submit" name="wp-submit" id="wp-submit" value="Registratie" />
might work.

Categories