Submitting form doesn't work after using Recaptcha v3 - laravel

I'm trying to use Recaptcha v3 on my form but submitting the form only works when Recaptcha is removed.
When Recaptcha is enabled, I can click on the submit button but nothing happens. I don't even get an error message in the console even though I can see the protected by reCAPTCHA logo in the frontend on the bottom right.
I'm using Laravel 6.
My form template looks like this:
<div class="row mt-150">
<div class="col-12 text-center text-white">
<h1>Contact</h1>
</div>
</div>
<div class="row justify-content-center">
<div class="col-md-4 col-sm-12">
<form action="{{route('contact_form')}}" method="POST">
#csrf
<div class="form-group">
<label for="email" class="text-white">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="form-group">
<label for="textarea" class="text-white">Message</label>
<textarea class="form-control" id="textarea" rows="3" name="message" required></textarea>
</div>
<input type="submit"
id="submitButton"
class="g-recaptcha btn btn-primary"
data-sitekey="MY-PUBLIC-KEY"
data-callback='onSubmit'
data-action='submit'
name="submit">
</form>
</div>
</div>
<script src="https://www.google.com/recaptcha/api.js"></script>
There is also an app.js included which contains the captcha callback function:
function onSubmit(token) {
document.getElementById("submitButton").submit();
}
window.onSubmit = onSubmit;
Can someone give me a hint what I'm doing wrong implementing recaptcha?
I tried to do it just like this:
Google reCaptcha v3

This will not work because you are trying to trigger submit() on a button. Give the form an id and then trigger submit() on the form
<form action="{{route('contact_form')}}" method="POST" id="contactForm">
#csrf
<div class="form-group">
<label for="email" class="text-white">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="form-group">
<label for="textarea" class="text-white">Message</label>
<textarea class="form-control" id="textarea" rows="3" name="message" required></textarea>
</div>
<input type="submit"
id="submitButton"
class="g-recaptcha btn btn-primary"
data-sitekey="MY-PUBLIC-KEY"
data-callback='onSubmit'
data-action='submit'
name="submit">
</form>
Then in javascript get the form and trigger submit on it
function onSubmit(token) {
document.getElementById("contactForm").submit();
}
window.onSubmit = onSubmit;

Related

How to submit traditional blade form from livewire component?

I am trying to reuse laravel's default authentication components in livewire component. But when the login form is submitting I am getting a console error
wire-directives.js:86 Uncaught TypeError: Cannot read properties of
null (reading 'match')
The login form working perfectly fine when I am using the default login blade. But when I am reusing the login form in my livewire component, it is not working. Here is my code:
In my livewire component, I have this
<div>
<x-login-form/>
</div>
and the login form component is laravels default login form:
<form role="form" class="text-start" method="POST" action="{{ route('login') }}">
#csrf
<div class="input-group input-group-outline my-3">
<input type="email" id="email" class="form-control" name="email" :value="old('email')" required placeholder="email">
</div>
<div class="input-group input-group-outline mb-3">
<input type="password" class="form-control" id="password" type="password" name="password" required autocomplete="current-password" placeholder="password">
</div>
<div class="form-check form-switch d-flex align-items-center mb-3">
<input class="form-check-input" type="checkbox" id="remember_me" name="remember">
<label class="form-check-label mb-0 ms-2" for="rememberMe">Remember Me</label>
</div>
<div class="text-center">
<button type="submit" class="btn bg-gradient-primary w-100 my-4 mb-2">Sign In</button>
</div>
#if (Route::has('password.request'))
<p class="text-xs text-center">
Forgot your password?
</p>
#endif
</form>

Laravel - Display Image in Modal while editing

I am a beginner of laravel. I want to edit a record which contains image, but it just show the input type for file same as insert records, instead of displaying the image. I have no ideas how to make it. Any comments are appreciated. Thanks.
Modal
<div class="modal-body">
<form method="POST" id="memberCardForm" name="memberCardForm" class="form-horizontal" enctype="multipart/form-data">
#csrf
<input type="hidden" name="id" id="id">
<div class="form-group">
<label for="">Card Type</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="card_type" name="card_type" maxlength="50" required>
</div>
</div>
<div class="form-group">
<label for="">Description</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="card_desc" name="card_desc" maxlength="50" required>
</div>
</div>
<div class="form-group">
<label for="">Entitlement</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="card_entitlement" name="card_entitlement" maxlength="50">
</div>
</div>
<div class="form-group">
<label for="">Card Image</label>
<div class="col-sm-12">
<input type="file" class="form-control" id="image" name="image" required>
</div>
</div>
<div class="modal-footer">
Close
<button type="submit" id="saveBtn" class="btn btn-success">Save</button>
</div>
</form>
</div>
JS for Edit record
//Edit
$('body').on('click', '.editRecord', function() {
var id = $(this).data('id');
$.get("{{ url('membercards/edit') }}" + '/' + id, function(data) {
$('#exampleModalLabel').html("Edit Member Card");
$('#saveBtn').html('Save');
$('#exampleModal').modal('show');
$('#id').val(data.id);
$('#card_type').val(data.card_type);
$('#card_desc').val(data.card_desc);
$('#card_entitlement').val(data.card_entitlement);
$('#image').val(data.image);
})
});

How to validate multiple value (Array of value ) in single Input (form) in codeigniter

this is the html part when i add more email id's only first email is being validated and rest of emails treat as normal even if they are not in proper
<form action="<?php echo base_url()?>index.php/EMail/show_email">
<div class="form-group">
<label for="exampleInputEmail1">To :</label>
<input type="email" name="toa[]" ng-model="to" placeholder="To" class=" tagsinput" value="ss" />
</div>
<div class="form-group">
<label for="exampleInputEmail1">Subject :</label>
<input type="text" class="form-control" ng-model="sub" name="suba" id="exampleInputEmail1" placeholder="Subject">
<div>{{sub}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">CC :</label>
<input type="text" class="form-control" ng-model="to" name="cca" id="exampleInputEmail1" placeholder="CC">
<div>{{to}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">BCC:</label>
<input type="text" class="form-control" name="bcca" id="exampleInputEmail1" placeholder="BCC">
</div>
<div class="form-group ">
<label for="ccomment" class="control-label">Message</label>
<textarea class="form-control " id="ccomment" name="msg" required></textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<input type="submit" onclick="mail()" class="btn btn-primary" value="Send"/>
<button type="submit" class="btn btn-Success">Draft</button>
</form>
this is my controller and "toa "is that field which i mentioned in the image
function show_email(){
$this->form_validation->set_rules("toa[]","To","valid_email");
$this->form_validation->set_rules("cca","CC ","valid_email");
$this->form_validation->set_rules("suba","Subject","required");
$this->form_validation->set_rules("bcca","bcc","valid_email");
$this->form_validation->set_rules("msg","Message","required");
if($this->form_validation->run()==FALSE){
$data["title"]="EMail";
$this->load->view('header',$data);
$this->load->view('sidebar');
$this->load->view('Mail/mail');
}else{
//finish
$ccdata=$this->input->post("cca");
$bccdata=$this->input->post("bcca");
$sub=$this->input->post("suba");
$ms=$this->input->post("msg");
$dataa["username"]="MyProject";
$dataa["msg"]=$ms;
$msg=$this->load->view('Email_Temp/mail',$dataa,TRUE);
$todata=explode(",",$data);
print_r($todata[0]);
//$this->SendEmail($todata,$ccdata,$bccdata,$msg,$sub);
}
}
[Image] this is the field (to) that i want to validate

What are all the steps I have to do to get my bootstrap email form working?

What should I do to get my form working? My website and everything is set up. I just can't get my form working. Can I do it from rdp? or firezila server?
<form>
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Name">
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Email address">
</div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<textarea name="message" id="message" required="required" class="form-control" rows="3" placeholder="Message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Submit Request</button>
</div>
</div>
</div>
</div>
</form>
Submit your form to php and send the mail, ulter the code as below and consider adding a subject field too:
<form name="nameforform" action="thephpfilename.php" method="POST">
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Name" name="name">
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Email address" name="email">
</div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<textarea name="message" id="message" required="required" class="form-control" rows="3" placeholder="Message" name="message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Submit Request</button>
</div>
</div>
</div>
</div>
</form>
Then create a php file (eg: thefilename.php) [besure to change the action attribute of the form element to that of the created php file's name.
The php file should have the following code:
<?php
$to = $_POST['email'];
$subject = '';
$message = $_POST['message'];
$headers = 'From:'. $_POST['name'] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
It would work, be sure to tweak your server's settings and also specify more info in the question next time.
Lastly how it works,
On submitting the form the browser sends a get/post request to the file specified on the action attribute of the form element. The php
file handles the request and does the needy. The data is stored with
reference to the name attribute of the input and textarea elements.
The data can be stored as arrays too. Here we use the php's mail()
function to send the mail using appropriate headers. HTML or bootstrap
cannot send mail independently without server intervention.
Be sure to comment for more info and other help, enjoy out there.

Bootstrap contact form sucess with ajax in the same page

I have this:
<form role="form" method="post" action="validar.php" data-toggle="validator">
<h2>¿Te interesa?<br>
Nosotros te llamamos</h2>
<div class="form-group">
<label for="Nombre">Nombre*</label><input data-error="Debes facilitarnos tu nombre" class="form-control" id="Nombre" name="Nombre" type="text" required />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="Empresa">Empresa</label><input class="form-control" id="Empresa" name="Empresa" type="text">
</div>
<div class="form-group">
<label for="Correo">Correo electrónico*</label><input data-error="Debes facilitarnos tu correo electrónico" class="form-control" id="Correo" name="Correo" type="email" required />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="Telefono">Teléfono</label><input class="form-control" id="Telefono" name="Telefono" type="tel">
</div>
<div class="form-group">
<label for="Horario">Qué día y hora prefieres</label><input class="form-control" id="Horario" name="Horario" type="text">
</div>
<button type="submit" class="btn btn-image" name="send"><span style="position:relative;top: -20px;">Solicitar información</span></button>
<div class="checkbox">
<label><input type="checkbox" required /><a target="_blank" href="http://www.trisquel.com/privacidad/">Acepto las condiciones</a></label>
</div>
</form>
validar.php recollect all the data (POST) and send and email.
I would like to add ajax/jquery code to show a Sucess Message (f.e: Thxs for all!) bellow the submit buttom when the user clicks in "submit" in the same page that the form and execute validar.php in the index page.
THXS!
// this is the id of the form
$("#idForm").submit(function() {
var url = "validar.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#idForm").serialize(), // serializes the form's elements.
success: function(data)
{
$("message").text("Success Message");
}
});
return false; // avoid to execute the actual submit of the form.
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form role="form" id="idForm" method="post" action="validar.php" data-toggle="validator">
<h2>¿Te interesa?<br>
Nosotros te llamamos</h2>
<div class="form-group">
<label for="Nombre">Nombre*</label><input data-error="Debes facilitarnos tu nombre" class="form-control" id="Nombre" name="Nombre" type="text" required />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="Empresa">Empresa</label><input class="form-control" id="Empresa" name="Empresa" type="text">
</div>
<div class="form-group">
<label for="Correo">Correo electrónico*</label><input data-error="Debes facilitarnos tu correo electrónico" class="form-control" id="Correo" name="Correo" type="email" required />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="Telefono">Teléfono</label><input class="form-control" id="Telefono" name="Telefono" type="tel">
</div>
<div class="form-group">
<label for="Horario">Qué día y hora prefieres</label><input class="form-control" id="Horario" name="Horario" type="text">
</div>
<button type="submit" class="btn btn-image" name="send"><span style="position:relative;top: -20px;">Solicitar información</span></button>
<div class="checkbox">
<label><input type="checkbox" required /><a target="_blank" href="http://www.trisquel.com/privacidad/">Acepto las condiciones</a></label>
</div>
<span id="message"></span>
</form>
Use jquery to serialize your form and post it. Give your form an id so you can reference it(like myForm)
var serializedForm = $("#myForm").serialize();
Then post it with an Ajax call(read the jquery ajax docs).
In the success callback of the Ajax call you do the following.
$('#contactDiv').hide();
$('#successDiv').show();
So you'll need to create some divs around the form and another around the success message.

Resources