How to block emoticons from input text field in codeignitier - codeigniter

I want to make input text field in such a way that it will block emoticons entry in text input field. I have made validation on controller for particular route by passing.Is it is a right way to block emoticons.
Controller code.
$this->form_validation->set_rules('registration', 'Registration', 'required|alpha_numeric');
$this->form_validation->set_rules('odometer', 'Odometer', 'required|alpha_numeric');
view code:
<input type="text" name="odometer" placeholder="Odometer" class="form-control profileControl odometer required number" id="odometer-<?php echo $vehicle_count; ?>" value="<?php echo $vehicle->intCarOdometer ?>"/>
<input type="text" placeholder="Registration" name="registration" class="form-control profileControl registration required" id="registration-<?php echo $vehicle_count; ?>" value="<?php echo $vehicle->vchCarRegistration ?>" pattern="[a-zA-Z0-9]+"/>

You can remove emoticons before sending to the server with jquery.
test this code.
var ranges = [
'\ud83c[\udf00-\udfff]', // U+1F300 to U+1F3FF
'\ud83d[\udc00-\ude4f]', // U+1F400 to U+1F64F
'\ud83d[\ude80-\udeff]' // U+1F680 to U+1F6FF
];
setTimeout(removeInvalidChars, 100);
function removeInvalidChars() {
var str = $('.valid-text').val();
str = str.replace(new RegExp(ranges.join('|'), 'g'), '');
$(".valid-text").val(str);
setTimeout(removeInvalidChars, 100);
}
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<input id="myinput" class="valid-text" type="email" name="myinput" value=" 😀 value 1 2 3 ? / "></input>

Related

Codeigniter PHPMailer how to get the address and mailcontent using inputfields?

Good Day everyone who has an idea on how to get the message and add address using input fields.
public function send()
{
$this->load->library('phpmailer_lib');
try
{
$mail=$this->phpmailer_lib->load();
$mail->setFrom('rayjayabejuela#gmail.com','Rayjay');
$mail->addAddress('flutterrun#gmail.com'); // I want the input data came from the input fields of email.
$mail->Subject="Subject Matter";
$mailContent=''; I want the input data came from the input fields came from the message.
$mail->Body=$mailContent;
if($mail->send()){
echo "Email has been set";
}
}
catch(Exception $e){
echo $mail->ErrorInfo;
}
}
This is my view page page
<form action="<?php echo base_url(); ?>email/send" method="post">
<br>
<input type="email" name="email" class="form-control" placeholder="Enter Email" required>
<br>
<textarea name="message" class="form-control" placeholder="Enter message here" required></textarea>
<br>
<button type="submit" class="btn btn-primary">Send Message</button>
</form>
public function send()
{
$this->load->library('phpmailer_lib');
try
{
$email = $this->input->post('email');
$message = $this->input->post('message');
$mail=$this->phpmailer_lib->load();
$mail->setFrom('rayjayabejuela#gmail.com','Rayjay');
$mail->addAddress($email); // I want the input data came from the input fields of email.
$mail->Subject="Subject Matter";
$mailContent=$message; I want the input data came from the input fields came from the message.
$mail->Body=$mailContent;
if($mail->send()){
echo "Email has been set";
}
}
catch(Exception $e){
echo $mail->ErrorInfo;
}
}
i'll try to help you.
You can make a change from :
$mail->addAddress('flutterrun#gmail.com');
to this :
$mail->addAddress($_POST['email']);
You can do this to mailcontent / messages too.

Pass a date input value from View to Controller using Codeigniter

I am trying to give the user to select the date he wants, and it will display the reservations for the day he selected. I am using Codeigniter, the MVC framework.
How am I setting a default value of the current date for an input date selection?
How am I sending the value to the controller and then I am using it for a function in the model.
<form id="form_reDate" name="form_reDate" method="POST" action="form_reDate.php">
<?php $r_date=#date('d-m-y'); ?>
<label for="reservations">Display reservations for :
<input type="date" id="date" name="re_date" style="margin-left: 0;"
min="2020-01-01" max="2020-12-31" value="<?php $r_date?>">
</label>
</form>
Controller:
public function form_reDate(){
$newDate = date("Y-m-d",strtotime($this->input->post('re_date')));
$data['tables'] = $this->Hosting_model->get_tables($newDate);
}
If you're using the default html of input type="date" to set its value you only use this php code.
<?php echo date('Y-m-d') ?>
to sum it:
<input type="date" id="date" name="re_date" style="margin-left: 0;"
min="2020-01-01" max="2020-12-31" value="<?php echo date('Y-m-d') ?>">
and for question #2 on how to send your input value to your Controller. Just make sure you get the data before sending it to your Model.

Form validation on radio buttons Codeigniter

I am trying to add validation for radio buttons on a html form in Codeigniter. The form is prepopulated with data from a database, including a list of uploaded documents (this field may be empty if the item has no associated docs). The user can upload a new document, adding it to the existing docs or adding a new doc deleting the current ones.
So I have a text field containing the org doc names and a file upload field for new:
<label for="orgdocs">Documents</label>
<input type="text" id="orgdocs" readonly="readonly" value="<?php echo $fetched_row['pdocs']; ?>" />
<input type="file" id="newdocs" name="newdocs[]" multiple="multiple" />
and radio buttons: (ignore the bad attempt at Spanish names)
<label for="mas"><b>Añada mas</b></label>
<input type="radio" name="docsacion" style="margin-right: 0" <?php if (isset($docsacion) && $docsacion=="mas") echo "checked";?> value="mas" title="Add another document to existing docs"><br />
<label for="otra"><b>Borrar y añada otra</b></label>
<input type="radio" name="docsacion" style="margin-right: 0" <?php if (isset($docsacion) && $docsacion=="otra") echo "checked";?> value="otra" title="Remove all current docs and add new">
I just want to add validation. IF a new document has been selected(newdocs is not empty), dosacion is required.
I have tried:
if(isset($_FILES['newdocs']['name']) && (!empty($_FILES['newdocs']['name'])))
{$this->form_validation->set_rules('docascion','Documentation upload', 'required');}
but this gives the error even if the newdocs field is empty and I´ve no idea why!?
Try this
if(!empty($_FILES['newdocs']['name'])){
$this->form_validation->set_rules('docascion','Documentation upload', 'required');
}

AJAX form $('form')[0].reset(); on submit not clearing values. What am I missing?

thank you in advance for any help given. I'm just learning jQuery and AJAX and would appreciate some help with the following code. All validation rules work, the form submits and the page does not refresh. The problem is that the form values are not clearing/resetting to default after the submit has triggered. Thoughts?
**********EDITED to include HTML markup*************
<div id="form">
<h1 class="title">Contact Us</h1><!-- title ends -->
<p class="contactUs">Ask about our services and request a quote today!</p><!-- contactUs ends -->
<div id="success"><p>Your message was sent successfully. Thank you.</p></div>
<p id="required">* All fields required.</p>
<form name="form" id="contactMe" method="post" action="process.php" onSubmit="return validateForm()" enctype="multipart/form-data">
<input class="txt" type="text" maxlength="50" size="50" required name="name" value="<?php echo $_GET['name'];?>" placeholder="Name" />
<div id="nameError"><p>Your name is required.</p></div>
<input class="txt" type="text" maxlength="50" size="50" required name="email" value="<?php echo $_GET['email'];?>" placeholder="Email Address" />
<div id="emailError"><p>A valid email address is required.</p></div>
<textarea name="message" rows="6" cols="40" required placeholder="Message"></textarea>
<div id="messageError"><p>A message is required.</p></div>
<input type="hidden" maxlength="80" size="50" id="complete" name="complete" placeholder="Please Keep This Field Empty" />
<input type="submit" value="SUBMIT" name="submit" />
<input type="reset" value="RESET" name="reset" />
</form>
</div><!-- form ends -->
//hide form submit success message by default. to be shown on successfull ajax submission only.
$(document).ready(function() {
if ($('#success').is(':visible')){
$(this).hide()
}
});
//form validation
function validateForm() {
//name
var a=document.forms["form"]["name"].value;
if (a==null || a=="")
{
$('#nameError').fadeIn(250);
return false;
}
//email address
var c=document.forms["form"]["email"].value;
var atpos=c.indexOf("#");
var dotpos=c.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=c.length)
{
$('#emailError').fadeIn(250);
return false;
}
//message
var e=document.forms["form"]["message"].value;
if (e==null || e=="")
{
$('#messageError').fadeIn(250);
return false;
}
}//javascript form validation ends
//ajax submit and clear form on success
$(function () {
$('form').on('submit', function (e) {
var myForm = validateForm();
if (myForm == false){
e.preventDefault();//stop submission for safari if fields empty
}
else{
$.ajax({
type: 'post',
url: 'process.php',
data: $('form').serialize(),
success: function () {
$('#success').fadeIn(250);
if ($('#nameError, #emailError, #messageError').is(':visible')) {
$('#nameError, #emailError, #messageError').fadeOut(250);
}
$('form')[0].reset();//clear form after submit success
}//success ends
});//ajax ends
e.preventDefault();//prevent default page refresh
}//else ends
});//submit ends
});//function ends
//if reset button is clicked AND messages displayed, remove all form html messages
$(document).ready(function() {
$('#form input[type="reset"]').click(function() {
if ($('#success, #nameError, #emailError, #messageError').is(':visible')) {
$('#success, #nameError, #emailError, #messageError').fadeOut(250);
}
});
});
By giving your input id="reset" and/or name="reset", you effectively overwrote the form.reset method of the form because by doing so you made form.reset target the reset button. Simply give it a different id and name value.
Never give elements name or id attributes that equal the name of a property of a dom node.

How do i restrict the users of other domain apart from **abc.com**

I have to build a custom module in which i have added a custom fields on to the customer registration page a fields like alternate mail id,mobile number & etc which is successfully getting saved in my database & here i have to implement a one more feature that is
on registration page when user enters his email id that should check for the domain name.
Ex: my domain name is abc & the users mail address will be user#abc.com
& the users of "abc.com" should only has to get register into my online store
How do i restrict the users of other domain apart from abc.com
Please help me in doing this.....
You can use regular expression for this. Just use the below function:
function checkEmail($email) {
if(preg_match("/^([a-zA-Z0-9\._-])*#abc.com$/",$email)){
return true;
}
return false;
}
Code Edited
<script type="text/javascript">
function validateEmail(elementValue){
var emailPattern = /^[a-zA-Z0-9._-]+#abc.com$/;
return emailPattern.test(elementValue);
}
function checkForm(){
var emailId = document.getElementById('email_address').value;
if(! validateEmail(emailId)) {
alert("Email id is not valid");
}
}
</script>
<div class="input-box"style="width: 550px;">
<input type="text" name="email" id="email_address" value="<?php echo $this->htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
<input type="submit" value="Click here" onclick="checkForm()" />(There will be be an submit button put the onclick event in it)
</div>

Resources