Tips for utilizing Codeigniter's set_value() functionality within Smarty for repopulating a form

<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />

Usually works fine in plain HTML, but I am struggling to make it work in Smarty without success so far.

<input type="text" name="{$field_name}" value="{$value|default:0}" class="form-control">

This is the code snippet that I need to incorporate into my project.

Answer №1

I was unable to find a solution to the issue at hand, so I decided to implement frontend validation using jQuery.

('#save_form_btn').on('click', function (e) {
 if(/*condition*/){
$('#value_id + small').remove();
$('#value_id').addClass('is-invalid');
$('#value_id').after('<small class="text-danger">{"error message"}</small>');              
e.preventDefault();
}
});

Please take note of the following:

  1. In addition to this, I also have backend validation set up (using Codeigniter's form validation).
  2. This piece of code ensures that the form submission is halted if the value entered does not meet the expected criteria, saving you from having to deal with old data in such cases where the frontend validation fails (the backend validation is only triggered if the frontend check passes).
  3. This may not directly address the original question, but it provides a workaround that could potentially benefit some users.
  4. I must admit that JQuery is not my strong suit, so feel free to make any necessary improvements as needed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with submit button functionality - troubleshooting with if-else logic

When my submit button is clicked, I want it to trigger an if-else statement. The goal is to check the 'complete' field in my users table and if the value is 6 or above, send an email (I already have the code for this). If the value is less than 6 ...

The FROM field in PHP email headers is not appearing as expected

I am seeking assistance in setting the FROM field in my email to a specific email address. Currently, it seems to be picking up information from my hosting company's server. [email protected] All other email features are working perfectly fine. ...

jQuery Uploadify struggling with high resolution images

I've been using the jQuery Uploadify plug-in and it's been great, but I recently encountered an issue when trying to upload images larger than 2.5mb. Even though the process completes and shows that the file is 100% uploaded, the file never actu ...

The password entered does not match the hashed and salted password in PHP during login

Currently working on a project in Unity where I am trying to implement account creation, login functionality, and saving user data using PHP and MySQL. The registration process is successfully completed, however, I am facing issues with the login process. ...

Tips for distinguishing between multiple submit buttons on a web page

while($row = mysqli_fetch_assoc($result)) { echo "<tr>"; echo "<form action='./form_page.php' method='post'>"; echo "<td style='width:9%'>" . $row['studentID']."</td>"; echo "& ...

Setting up the CodeIgniter .htaccess file on your Apache Server

After setting up Apache 2.2, Php 5.4.5 and Mysql 5.5.27 on my Windows 7 Operating System, I located my localhost at G:/local_server. Following that, I downloaded CodeIgniter_2.1.3, extracted it into the local_server, renamed it to CodeIgniter, and created ...

Retrieve live data from a Python script using jQuery and PHP for immediate usage

How can I show the current temperature on a webpage? My setup involves using a Raspberry Pi 3 with the Jessie OS and Chromium as the browser. To achieve this, I have placed a Python script inside a loop for a countdown timer. The script is triggered ever ...

Oops! Looks like there's a snag with your Wordpress site - it's showing an

Recently, I transferred my Wordpress instance to a new server. Since then, I have been encountering the 500 Internal Server Error frequently and unexpectedly. Surprisingly, there are no fatal error messages in the Apache error log, but PHP warning messages ...

dividing an array into an array containing multiple arrays

I'm dealing with an array of strings that represent sentences, and I need to split each sentence into individual words. I attempted using array_chunks but found it challenging because I would have to iterate through the resulting arrays again to achie ...

extracting information from an array using json parsing in php

I am currently facing an issue with decoding and parsing JSON values from an array. I seem to be struggling with getting it right. Here is the information provided: $send[0] : Array ( [0] => {"message-count":"1","messages":[{"error-text":"Missing to p ...

Unable to remove a particular entry from the table

Having trouble with deleting just one row or record? Finding articles that don't quite help, and ending up deleting the entire table instead? <?php // set database connection details $databaseHost = 'localhost'; $databaseName = ...

Asking for an array of PHP objects using jQuery Ajax: a guide

I'm facing a challenge with passing an array of "Blocks" using Ajax. I have successfully created the "Blocks" using a PHP class and know how to pass an array with numbers through JSON, but I am unsure how to pass an array with objects. Do I need to c ...

Sum of monthly totals even if a month is missing

Just a quick question, hopefully I can get some assistance... I need to calculate the total sales value by month from a single table. The issue I'm facing is: If there are no sales for a specific month, that month doesn't show up in the results ...

Resolving the Challenge of PHP's Unique MultiDimensional Arrays

Currently, I am extracting distinct values from my multidimensional array by employing the subsequent function: function unique_multidim_array($array, $key) { $temp_array = array(); $i = 0; $key_array = array(); ...

Encountering an issue with Ajax code on initial execution

I've implemented an Ajax script on my PHP page to execute a PHP script upon clicking a button. However, the issue I am facing is that when I initially load the web page, the script does not run. But, if I click back and repeat the process, the script ...

Error encountered: Unhandled ArgumentCountError: Inadequate number of arguments supplied for the execution of the phpfmg_hsc

Apologies for reaching out for assistance after a long time of being able to solve issues on my own. Typically, I am capable of finding solutions independently. However, since upgrading my website PHP version to 7.0, the mail send form is no longer functi ...

What is the method for transferring the value of a jQuery variable to a PHP variable without using AJAX?

Here is my JavaScript code: $('#affiliates_name').change(function(){ var id = $('#affiliates_name').val(); }); Below is the corresponding HTML: <select id="affiliates_name" style="display: none;" name="affiliates_name"> < ...

Encountered a MySQL error while attempting to insert an image into the database

I have a task to work on a website where users can upload product images that will be stored in a MySQL database. The code for my HTML form is: <FORM action="testimage1.php" ENCTYPE="multipart/form-data" method="post"> <div st ...

What steps can I take to prevent inserting an href into a conflicting keyword within a string?

Reviewing the code snippet provided: $text = "Google has released a version specifically for smart devices running Android operating system from version '25' of its famous Chrome browser. Google has not updated the Chrome application for Android ...

In PHP, use the preg_replace function to add a forward slash before any text that already includes

Categories: $category = 'fruit'; $category = 'fruit/type'; Result Needed: $category = ''; $category = 'type'; What I Tried: // This code works for "folder/subfolder" $category = preg_replace('/.*?\//i& ...