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

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.

Related

Cant get https to work properly on ngrok. need https to test pyament api webhook

I just started implementing the mollie api to handle payments on my website.
You need a url to redirect to and a url as a webhook to update payment states.
I'm still developing the website locally, but localhost as a url isn't an option ofcourse.
I installed ngrok and tried the HTTPS URL assigned to me when running the ngrok http command.
when i access my website with the HTTP link everything looks fine, But when i go to my website via the HTTPS link my website fails to load in my own css scripts and chrome tells me the website is not secure, but my ssl certificate is valid (probably not secure because its self-signed)?
i tried to test the api anyhow by ordering something on the (broken https) website but after confirming the order i get a 419 error response (i develop my website in laravel 8).
So sorry if i left out crucial information, i'm the biggest noob when it comes to networking and i didn't even know where to begin.
EDIT: Here is additional information on what my problem is.
Im testing the payment api from mollie in my laravel controller where i create an order.
public function order(CreateOrderRequest $request){
$baseUrl = 'https://xxxx-xxx-xx-xxx-xx.ngrok.io/';
$payment = $this->mollie->payments->create([
"amount" => [
"currency" => "EUR",
"value" => "10.00"
],
"description" => "My first API payment",
"redirectUrl" => $baseUrl."/order/besteld",
"webhookUrl" => $baseUrl."/order/betaalupdate/".$id,
]);
dd($payment);
return redirect()->to($payment->getCheckoutUrl(), 303);
}
this controller is called from the route:
Route::post('/winkelwagen/bestellen/bevestig', [CartController::class, 'order'])->name('orderConfirmed');
which is called from the following form:
<form action="{{route('orderConfirmed')}}" method="post" class="d-block">
#csrf
<div class="row">
<div class="col-12 col-lg-6">
<h4 class="fat-title display-4 text-center mt20 text-white"><span class="text-color-light">AFLEVER</span>ADRESS</h4>
<hr class="hrdark mb40 mt40">
<div class="row">
<div class="col-12 col-md-6 mb20">
<label for="naam" class="fat-title">Volledige Naam</label>
<input id="naam" type="text" class="form-control" placeholder="Mary Fuego" name="naam"
#if($user != null) value="{{$user->naam}}" #endif required>
</div>
<div class="col-12 col-md-6 mb20">
<label for="email" class="fat-title">Email</label>
<input id="email" type="email" class="form-control" placeholder="Example#fuego.nl" name="email"
#if($user != null) value="{{$user->email}}" #endif required>
</div>
<div class="col-12 col-md-6 mb20">
<label for="tel" class="fat-title">Telefoonnummer</label>
<input id="tel" type="tel" class="form-control" placeholder="0612345678" name="tel">
</div>
<div class="col-12 col-md-6 mb20">
<label for="plaats" class="fat-title">Plaats</label>
<input id="plaats" class="form-control" type="text" placeholder="Holten" name="plaats" required>
</div>
<div class="col-6 col-md-3 mb20">
<label for="postcode" class="fat-title">Postcode</label>
<input id="postcode" class="form-control" type="text" minlength="4" maxlength="6" placeholder="7451PJ" name="postcode" required>
</div>
<div class="col-6 col-md-3 mb20">
<label for="huisnummer" class="fat-title">Huisnummer</label>
<input id="huisnummer" class="form-control" type="text" placeholder="1" min="1" name="huisnummer" required>
</div>
<div class="col-6 col-md-3 mb20">
<label for="toevoeging" class="fat-title">Toev. (opt.)</label>
<input id="toevoeging" class="form-control" type="text" placeholder="A" min="1" name="toevoeging">
</div>
<div class="col-6 col-md-3 mb20">
<label for="straat" class="fat-title">Straat</label>
<input id="straat" class="form-control" type="text" placeholder="Handelsweg" name="straat" required>
</div>
#if($user != null)
<div class="col-12 mb20">
<button class="btn darkgraybg text-white w-100 btn-widetxt"
data-bs-toggle="dropdown" aria-expanded="false" type="button">laad adress</button>
<div class="dropdown-menu softgreybg pb20 pt20 pr20 pl20">
<label for="addresscopy" class="fat-title">Adress</label>
<select class="form-select form-control" id="addresscopy" onchange="loadAdress(parseInt(this.value))">
<option value="0">Geen Adress Laden</option>
#foreach($addresses as $address)
<option value="{{$address->id}}">{{$address->plaats}} {{$address->straat}} {{$address->huisnummer}} {{$address->toevoeging}}</option>
#endforeach
</select>
</div>
</div>
<input type="hidden" name="user_id" value="{{$user->id}}">
#endif
</div>
</div>
<div class="col-12 col-lg-6">
<h4 class="fat-title display-4 text-center mt20 text-white"><span class="text-color-light">BETAAL</span>METHODE</h4>
<hr class="hrdark mb40 mt40">
<button type="submit" class="btn btn-orange btn-widetxt w-100">
BESTELLEN
</button>
</div>
</div>
</form>
After submitting this form on the https page i get a 419 PAGE EXPIRED, which isnt logged. After submitting it via http i get an error in the mollie client that i have to have an SSL

Submitting form doesn't work after using Recaptcha v3

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;

Comment Store in Laravel Redirecting to Home Page

I have a comment form in a page when I submit this form it's redirecting to the home page.
Routes
Route::get('/post/{slug}', 'API\PostController#show')->name('post.show');
Route::post('/post/{slug}', 'API\PostController#addComment')->name('post.comment');
Route::get('{path}',"HomeController#index")->where( 'path', '([A-z\d-\/_.]+)?' );
Blade
<form action="{{route('post.comment',$currentPost->slug)}}" method="POST">
<div class=" row blog-form">
{{csrf_field()}}
<div class="frm_grp col-md-6">
<input type="text" name="name" placeholder="Name"/>
</div>
<div class="frm_grp col-md-6">
<input type="text" name="email" placeholder="Email"/>
</div>
<div class="frm_grp col-md-12">
<input type="text" name="website" placeholder="Website"/>
</div>
<div class="frm_grp col-md-12">
<textarea name="message" placeholder="Message"></textarea>
</div>
<div class="frm_grp col-md-12">
<input type="submit" value="Post Comment"/>
</div>
</div>
</form>

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

Bootstrap form validator

I am new to Bootstrap 3. I am creating a login page and I have this code:
* I got this generated from Bootply.
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>Registry Login</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="input_email">Email</label>
<div class="col-md-8">
<input id="input_username" name="input_email" placeholder="" class="form-control input-md" required="" type="email">
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="input_password">Password</label>
<div class="col-md-8">
<input id="input_password" name="input_password" placeholder="" class="form-control input-md" required="" type="password">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for=""></label>
<div class="col-md-4">
<button id="" name="" class="btn btn-default">Login</button>
</div>
</div>
</fieldset>
</form>
I keyed in on my Email field this sample string abcde and I received a small tooltip saying that Please enter an email address. Is there a way for me to change the text?
You'll have to change the form options with Codeigniter, I'm not too familiar with it, but it sounds like it would be under a submit code for a post.

Resources