<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CodeIgniter 4 Archives - Cody Paste</title>
	<atom:link href="https://www.codypaste.com/category/codeigniter/codeigniter-4/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codypaste.com/category/codeigniter/codeigniter-4/</link>
	<description>THE WEB PLAYGROUND</description>
	<lastBuildDate>Thu, 22 May 2025 08:04:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://www.codypaste.com/wp-content/uploads/2022/12/cropped-codypaste-32x32.png</url>
	<title>CodeIgniter 4 Archives - Cody Paste</title>
	<link>https://www.codypaste.com/category/codeigniter/codeigniter-4/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Encrypt Decrypt in CI4</title>
		<link>https://www.codypaste.com/encrypt-decrypt-in-ci4/</link>
					<comments>https://www.codypaste.com/encrypt-decrypt-in-ci4/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Wed, 30 Apr 2025 08:56:07 +0000</pubDate>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CodeIgniter 4]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1273</guid>

					<description><![CDATA[<p>Encrypt &#38; Decrypt in CI4, like id in parameter or anything. STEP 1: [crayon-698f600d1ba11576814424/] STEP 2: (Encrypt) [crayon-698f600d1ba23641455478/] STEP 3: (Decrypt) [crayon-698f600d1ba26270719627/] &#160; In View File [crayon-698f600d1ba28898563639/] [crayon-698f600d1ba2b518169860/] &#160; &#160;</p>
<p>The post <a href="https://www.codypaste.com/encrypt-decrypt-in-ci4/">Encrypt Decrypt in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Encrypt &amp; Decrypt in CI4, like id in parameter or anything.</p>
<p>STEP 1:</p><pre class="urvanov-syntax-highlighter-plain-tag">public function __construct() {        
   $this-&gt;encrypter  = \Config\Services::encrypter();       
}</pre><p>STEP 2: (Encrypt)</p><pre class="urvanov-syntax-highlighter-plain-tag">$ids = '123'
$id = bin2hex($this-&gt;encrypter-&gt;encrypt($ids));</pre><p>STEP 3: (Decrypt)</p><pre class="urvanov-syntax-highlighter-plain-tag">$id = $this-&gt;encrypter-&gt;decrypt(hex2bin($id));</pre><p>&nbsp;</p>
<h2>In View File</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    $encrypter        = \Config\Services::encrypter();
 ?&gt;</pre><p></p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;a href="&lt;?= base_url('customer/order-detail/' . bin2hex($encrypter-&gt;encrypt($order['orderid']))) ?&gt;"&gt;View Order&lt;/a&gt;</pre><p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.codypaste.com/encrypt-decrypt-in-ci4/">Encrypt Decrypt in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/encrypt-decrypt-in-ci4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Encrypt Password in CI4</title>
		<link>https://www.codypaste.com/encrypt-password-in-ci4/</link>
					<comments>https://www.codypaste.com/encrypt-password-in-ci4/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Mon, 28 Apr 2025 09:57:22 +0000</pubDate>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CodeIgniter 4]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1271</guid>

					<description><![CDATA[<p>Password encrypt and match in CI4 with hash encrypt Encrypt: [crayon-698f600d1d355291973939/] Match: [crayon-698f600d1d363816897593/] &#160;</p>
<p>The post <a href="https://www.codypaste.com/encrypt-password-in-ci4/">Encrypt Password in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Password encrypt and match in CI4 with hash encrypt</p>
<p>Encrypt:</p><pre class="urvanov-syntax-highlighter-plain-tag">$pwd = password_hash($this-&gt;request-&gt;getPost('pwd'), PASSWORD_BCRYPT);</pre><p>Match:</p><pre class="urvanov-syntax-highlighter-plain-tag">$user = $this-&gt;db-&gt;table('customer')
                         -&gt;select('id, first_name, last_name, uname, emailid, contact, picture, pwd')  // Email aur password select karo
                         -&gt;where('emailid', $email)
                         -&gt;get()
                         -&gt;getRow();
                         
                    
                    if ($user &amp;&amp; password_verify($password, $user-&gt;pwd)) {
                        
                        $record = $user;
                        // Password matches, login successful
                        $this-&gt;session-&gt;set('customerSessData', $record);
                        return redirect()-&gt;to('customer/dashboard')-&gt;with('success', 'Welcome to Dashboard');
                        // Redirect to dashboard or desired page
                    }</pre><p>&nbsp;</p>
<p>The post <a href="https://www.codypaste.com/encrypt-password-in-ci4/">Encrypt Password in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/encrypt-password-in-ci4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Encrypt decrypt in CI4 &#8211; CodeIgniter 4</title>
		<link>https://www.codypaste.com/encrypt-decrypt-in-ci4-codeigniter-4/</link>
					<comments>https://www.codypaste.com/encrypt-decrypt-in-ci4-codeigniter-4/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Fri, 24 Jan 2025 06:19:30 +0000</pubDate>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CodeIgniter 4]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1267</guid>

					<description><![CDATA[<p>To pass an encrypted value in a URL and decrypt it in CodeIgniter 4 (CI4), you can use the Encryption library provided by CI4. Here&#8217;s how to implement this: 1. Configure Encryption in CI4 Ensure that the encryption service is properly set up. Open the app/Config/Encryption.php file and configure it: [crayon-698f600d1de56857868202/] Replace your-encryption-key with a &#8230; </p>
<p class="link-more"><a href="https://www.codypaste.com/encrypt-decrypt-in-ci4-codeigniter-4/" class="more-link">read more<span class="screen-reader-text"> "Encrypt decrypt in CI4 &#8211; CodeIgniter 4"</span></a></p>
<p>The post <a href="https://www.codypaste.com/encrypt-decrypt-in-ci4-codeigniter-4/">Encrypt decrypt in CI4 &#8211; CodeIgniter 4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>To pass an encrypted value in a URL and decrypt it in CodeIgniter 4 (CI4), you can use the <code>Encryption</code> library provided by CI4. Here&#8217;s how to implement this:</p>
<hr />
<h3>1. <strong>Configure Encryption in CI4</strong></h3>
<p>Ensure that the encryption service is properly set up. Open the <code>app/Config/Encryption.php</code> file and configure it:</p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Encryption extends BaseConfig
{
    public $key = 'your-encryption-key'; // Replace with a random key
    public $driver = 'OpenSSL';         // Use OpenSSL for encryption
}</pre><p>Replace <code>your-encryption-key</code> with a strong random key. You can generate one using <code>bin2hex(random_bytes(32))</code> in PHP.</p>
<p>&nbsp;</p>
<h3>2. <strong>Encrypt the Value</strong></h3>
<p>Use CI4&#8217;s <code>encrypter()</code> helper to encrypt the value before adding it to the URL:</p><pre class="urvanov-syntax-highlighter-plain-tag">use CodeIgniter\Encryption\Encryption;

$encrypter = \Config\Services::encrypter();

// The value to encrypt
$data = 'your-value-to-encrypt';

// Encrypt the value
$encryptedValue = base64_encode($encrypter-&gt;encrypt($data));

// Pass the encrypted value in the URL
$url = base_url('your-controller/your-method/' . $encryptedValue);</pre><p>&nbsp;</p>
<h3>3. <strong>Decrypt the Value</strong></h3>
<p>Retrieve and decrypt the value in your controller:</p><pre class="urvanov-syntax-highlighter-plain-tag">public function yourMethod($encryptedValue)
{
    $encrypter = \Config\Services::encrypter();

    // Decode and decrypt the value
    try {
        $decryptedValue = $encrypter-&gt;decrypt(base64_decode($encryptedValue));
        echo 'Decrypted Value: ' . $decryptedValue;
    } catch (\Exception $e) {
        // Handle errors (e.g., invalid encryption or tampered data)
        echo 'Decryption failed: ' . $e-&gt;getMessage();
    }
}</pre><p>&nbsp;</p>
<p>&nbsp;</p>
<h3>4. <strong>Example Flow</strong></h3>
<ul>
<li><strong>Encrypt and Generate URL:</strong>
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="sticky top-9 md:top-[5.75rem]">
<div class="absolute bottom-0 right-2 flex h-9 items-center">
<div class="flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary">
<pre class="urvanov-syntax-highlighter-plain-tag">$data = '12345';
$encryptedValue = base64_encode($encrypter-&gt;encrypt($data));
echo base_url('example/decrypt/' . $encryptedValue);</pre><br />
<strong>Decrypt in Controller:</strong></p>
</div>
</div>
</div>
<div class="overflow-y-auto p-4" dir="ltr">
<pre class="urvanov-syntax-highlighter-plain-tag">public function decrypt($encryptedValue)
{
    $encrypter = \Config\Services::encrypter();
    $decryptedValue = $encrypter-&gt;decrypt(base64_decode($encryptedValue));
    echo 'Decrypted Value: ' . $decryptedValue;
}</pre><br />
&nbsp;</p>
</div>
</div>
</li>
</ul>
<p>The post <a href="https://www.codypaste.com/encrypt-decrypt-in-ci4-codeigniter-4/">Encrypt decrypt in CI4 &#8211; CodeIgniter 4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/encrypt-decrypt-in-ci4-codeigniter-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Hash Password in CI4</title>
		<link>https://www.codypaste.com/hash-password-in-ci4/</link>
					<comments>https://www.codypaste.com/hash-password-in-ci4/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Fri, 03 Jan 2025 10:57:51 +0000</pubDate>
				<category><![CDATA[CodeIgniter 4]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1259</guid>

					<description><![CDATA[<p>Password: 1. Created a Helper Function Created helper functions for password hashing and verification to reuse across your application. Create a file in app/Helpers, e.g., app/Helpers/password_helper.php password_helper.php [crayon-698f600d1e533878098043/] &#160; &#160; 2. Hash Password During Registration [crayon-698f600d1e542759774574/] &#160; 3. Verify Password During Login [crayon-698f600d1e546306176896/] If the password is verified, it will return 1, else blank. e.g. &#8230; </p>
<p class="link-more"><a href="https://www.codypaste.com/hash-password-in-ci4/" class="more-link">read more<span class="screen-reader-text"> "Hash Password in CI4"</span></a></p>
<p>The post <a href="https://www.codypaste.com/hash-password-in-ci4/">Hash Password in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h4>Password:</h4>
<p><b>1. Created a Helper Function</b><br />
Created helper functions for password hashing and verification to reuse across your application.</p>
<p>Create a file in app/Helpers, e.g.,<strong> app/Helpers/password_helper.php</strong></p>
<p><strong>password_helper.php</strong></p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    if (!function_exists('hash_password')) {
        function hash_password($password) {
            return password_hash($password, PASSWORD_BCRYPT);
        }
    }
    
    if (!function_exists('verify_password')) {
        function verify_password($input_password, $stored_hash) {
            return password_verify($input_password, $stored_hash);
        }
    }
?&gt;</pre><p>&nbsp;</p>
<p>&nbsp;</p>
<p><b>2. Hash Password During Registration</b></p><pre class="urvanov-syntax-highlighter-plain-tag">$password = $this-&gt;request-&gt;getPost('password');
$hashed_password = hash_password($password);</pre><p>&nbsp;</p>
<p><b>3. Verify Password During Login</b></p><pre class="urvanov-syntax-highlighter-plain-tag">$password = $this-&gt;request-&gt;getPost('password');
verify_password($input_password, $user-&gt;password);</pre><p>If the password is verified, it will return 1, else blank. e.g. below</p><pre class="urvanov-syntax-highlighter-plain-tag">if(verify_password($password, $user-&gt;password)) {
	// Set session or other login logic
	session()-&gt;set(['username' =&gt; $user-&gt;username]);
	return redirect()-&gt;to('/superadmin/dashboard')-&gt;with('success', 'Login successful!');
}else {
	return redirect()-&gt;back()-&gt;with('error', 'Invalid credentials!');
}</pre><p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.codypaste.com/hash-password-in-ci4/">Hash Password in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/hash-password-in-ci4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Login in CI4 Complete Code</title>
		<link>https://www.codypaste.com/login-in-ci4-complete-code/</link>
					<comments>https://www.codypaste.com/login-in-ci4-complete-code/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Fri, 03 Jan 2025 10:51:14 +0000</pubDate>
				<category><![CDATA[CodeIgniter 4]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1256</guid>

					<description><![CDATA[<p>Controller: [crayon-698f600d1e9e0370087810/] Password: 1. Created a Helper Function created helper functions for password hashing and verification to reuse them across your application. Create a file in app/Helpers, e.g., app/Helpers/password_helper.php hash_password($password) verify_password($input_password, $stored_hash) Load this helper in your application: helper('password'); 2. Hash Password During Registration $password = $this-&#62;request-&#62;getPost('password'); $hashed_password = hash_password($password); &#160; 3. Verify Password During &#8230; </p>
<p class="link-more"><a href="https://www.codypaste.com/login-in-ci4-complete-code/" class="more-link">read more<span class="screen-reader-text"> "Login in CI4 Complete Code"</span></a></p>
<p>The post <a href="https://www.codypaste.com/login-in-ci4-complete-code/">Login in CI4 Complete Code</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2><strong>Controller:</strong></h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">public function login(){
        if(!empty($_POST)){
            
            // Form Validation--&gt;
                $validation =  \Config\Services::validation();
                $validation-&gt;setRules([
                    'username' =&gt; ['label' =&gt; 'Username',  'rules' =&gt; 'required'],
                    'password'  =&gt; ['label' =&gt; 'Password', 'rules' =&gt; 'required']
                ]);
            // Form Validation Close--&gt;
            
            if(!$validation-&gt;withRequest($this-&gt;request)-&gt;run()) {
                $validationErrors = $validation-&gt;listErrors();
                // Redirect back with validation errors
                return redirect()-&gt;back()-&gt;with('error', $validationErrors);
            }else{
                $username   = $this-&gt;request-&gt;getPost('username');
        		$password   = $this-&gt;request-&gt;getPost('password');
        		
        		$user = $this-&gt;db-&gt;table('superadmin')-&gt;where('username', $username)-&gt;get()-&gt;getRow();
        		
        		if ($user) {
                    // Verify the password
                    if (verify_password($password, $user-&gt;password)) {
                        // Set session or other login logic
                        session()-&gt;set(['username' =&gt; $user-&gt;username]);
                        return redirect()-&gt;to('/superadmin/dashboard')-&gt;with('success', 'Login successful!');
                    } else {
                        return redirect()-&gt;back()-&gt;with('error', 'Invalid credentials!');
                    }
                }else {
                    return redirect()-&gt;back()-&gt;with('error', 'User not found!');
                }
            }
		}
		else{			
            echo view('superadmin/includes/header');
            echo view('superadmin/login');
            echo view('superadmin/includes/footer');           
		}    
    }</pre><p></p>
<h4>Password:</h4>
<p><b>1. Created a Helper Function</b><br />
created helper functions for password hashing and verification to reuse them across your application.</p>
<p>Create a file in app/Helpers, e.g., app/Helpers/password_helper.php<br />
<code>hash_password($password)</code></p>
<p>verify_password($input_password, $stored_hash)</p>
<p>Load this helper in your application:</p>
<p><code>helper('password');</code></p>
<p><b>2. Hash Password During Registration</b></p>
<p><code>$password = $this-&gt;request-&gt;getPost('password');<br />
$hashed_password = hash_password($password);</code></p>
<p>&nbsp;</p>
<p><b>3. Verify Password During Login</b></p>
<p><code>$password = $this-&gt;request-&gt;getPost('password');<br />
verify_password($input_password, $user-&gt;password)</code><br />
If password verify will return 1, else blank.</p>
<h4>Redirect (Back to request page):</h4>
<p><code>return redirect()-&gt;back()-&gt;with('error', 'Invalid credentials!');</code></p>
<p><b>Form validation error</b><br />
<code>if(!$validation-&gt;withRequest($this-&gt;request)-&gt;run()) {<br />
$validationErrors = $validation-&gt;listErrors();<br />
// Redirect back with validation errors<br />
return redirect()-&gt;back()-&gt;with('error', $validationErrors);<br />
}</code></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2><strong>Model:</strong></h2>
<p>Not used</p>
<h2><strong>View:</strong></h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;h1&gt;Login Super Admin&lt;/h1&gt;

&lt;?php if (session()-&gt;get('error')): ?&gt;
    &lt;div class="alert alert-danger"&gt;
        &lt;?= session()-&gt;get('error') ?&gt;
    &lt;/div&gt;
&lt;?php endif; ?&gt;

&lt;form action="&lt;?php echo base_url(); ?&gt;superadmin/login" method="post"&gt;
    &lt;input type="text" name="username"&gt;
    &lt;input type="password" name="password"&gt;
    &lt;button type="submit"&gt;LOGIN&lt;/button&gt;
&lt;/form&gt;</pre><p>&nbsp;</p>
<h2><strong>Password Helper:</strong></h2>
<p>app/Helpers/password_helper.php</p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    if (!function_exists('hash_password')) {
        function hash_password($password) {
            return password_hash($password, PASSWORD_BCRYPT);
        }
    }
    
    if (!function_exists('verify_password')) {
        function verify_password($input_password, $stored_hash) {
            return password_verify($input_password, $stored_hash);
        }
    }
?&gt;</pre><p>&nbsp;</p>
<p>The post <a href="https://www.codypaste.com/login-in-ci4-complete-code/">Login in CI4 Complete Code</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/login-in-ci4-complete-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Disable the button when the form is submitted</title>
		<link>https://www.codypaste.com/disable-the-button-when-the-form-is-submitted/</link>
					<comments>https://www.codypaste.com/disable-the-button-when-the-form-is-submitted/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sat, 23 Nov 2024 10:27:01 +0000</pubDate>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CodeIgniter 4]]></category>
		<category><![CDATA[HTML]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1223</guid>

					<description><![CDATA[<p>Solution: Disable the button when the form is submitted. Re-enable the button after the page is loaded or when the form submission is complete. Example Implementation: HTML: [crayon-698f600d221fa470682950/] JavaScript/jQuery: [crayon-698f600d22209208475174/] Explanation: Disabling the Submit Button on Form Submission: When the form is submitted ($('#myForm').submit()), we disable the submit button immediately ($('#submitButton').prop('disabled', true);) to prevent further &#8230; </p>
<p class="link-more"><a href="https://www.codypaste.com/disable-the-button-when-the-form-is-submitted/" class="more-link">read more<span class="screen-reader-text"> "Disable the button when the form is submitted"</span></a></p>
<p>The post <a href="https://www.codypaste.com/disable-the-button-when-the-form-is-submitted/">Disable the button when the form is submitted</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h3>Solution:</h3>
<ol>
<li><strong>Disable the button when the form is submitted</strong>.</li>
<li><strong>Re-enable the button after the page is loaded or when the form submission is complete</strong>.</li>
</ol>
<h3>Example Implementation:</h3>
<h4>HTML:</h4>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;form id="myForm" method="POST" action="your-action-url"&gt;
    &lt;!-- Your form fields here --&gt;
    &lt;input type="submit" value="Submit" class="btn btn-lg btn-success" id="submitButton"&gt;
&lt;/form&gt;</pre><p></p>
<h2><strong>JavaScript/jQuery:</strong></h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$(document).ready(function() {
    // Disable the submit button when the page starts loading or the form is being submitted
    $('#myForm').submit(function(event) {
        // Disable the submit button
        $('#submitButton').prop('disabled', true);
        
        // Optionally, change the button text to indicate submission
        $('#submitButton').val('Submitting...');
        
        // If you're submitting via Ajax, handle it like this:
        // $.ajax({
        //     url: 'your-action-url',
        //     type: 'POST',
        //     data: $(this).serialize(),
        //     beforeSend: function() {
        //         // Disable the button before sending the request
        //         $('#submitButton').prop('disabled', true);
        //     },
        //     success: function(response) {
        //         // Handle successful form submission here
        //         // Re-enable the button if needed (or perform actions based on success)
        //         // $('#submitButton').prop('disabled', false);
        //         // $('#submitButton').val('Submit');
        //     },
        //     error: function() {
        //         // Handle error response
        //         // Re-enable the button in case of an error
        //         // $('#submitButton').prop('disabled', false);
        //         // $('#submitButton').val('Submit');
        //     }
        // });
        
        // For traditional form submission, we can rely on the browser's default behavior
    });
    
    // Disable button if the page is being loaded
    $(window).on('beforeunload', function() {
        $('#submitButton').prop('disabled', true);
    });
});</pre><p></p>
<h3>Explanation:</h3>
<ol>
<li><strong>Disabling the Submit Button on Form Submission:</strong>
<ul>
<li>When the form is submitted (<code>$('#myForm').submit()</code>), we disable the submit button immediately (<code>$('#submitButton').prop('disabled', true);</code>) to prevent further clicks.</li>
</ul>
</li>
<li><strong>Changing the Button Text:</strong>
<ul>
<li>Optionally, you can change the button text to &#8220;Submitting&#8230;&#8221; or something else to give feedback to the user that the form is being processed.</li>
</ul>
</li>
<li><strong>Re-enabling the Button After Submission (Using Ajax):</strong>
<ul>
<li>If you&#8217;re using Ajax, you can re-enable the button when the submission is successful or if there&#8217;s an error by placing the code <code>$('#submitButton').prop('disabled', false);</code> in the success/error callbacks.</li>
</ul>
</li>
<li><strong>Disabling the Button on Page Reload or Unload:</strong>
<ul>
<li><strong><code>$(window).on('beforeunload', function() {...})</code></strong>: This disables the button if the page is being unloaded, which could happen when the user reloads or navigates away while the form is submitting. This will prevent the form from being accidentally submitted multiple times due to a page reload.</li>
</ul>
</li>
</ol>
<h3>Additional Notes:</h3>
<ul>
<li><strong>For Ajax Submissions:</strong> You can use the <code>beforeSend</code> function in the Ajax request to disable the button before sending the request, and re-enable it on the success or error response.</li>
<li><strong>For Traditional Form Submissions:</strong> The button will be disabled immediately on form submission, and the page reloads automatically once the form is submitted. After the page reloads, the button will be active again (if you set it to be enabled on page load).</li>
</ul>
<p>The post <a href="https://www.codypaste.com/disable-the-button-when-the-form-is-submitted/">Disable the button when the form is submitted</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/disable-the-button-when-the-form-is-submitted/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Database query in view file/template in CodeIgniter 4</title>
		<link>https://www.codypaste.com/database-query-in-view-file-template-in-codeigniter-4/</link>
					<comments>https://www.codypaste.com/database-query-in-view-file-template-in-codeigniter-4/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Fri, 22 Nov 2024 08:25:56 +0000</pubDate>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CodeIgniter 4]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1221</guid>

					<description><![CDATA[<p>[crayon-698f600d22790727041689/] &#160;</p>
<p>The post <a href="https://www.codypaste.com/database-query-in-view-file-template-in-codeigniter-4/">Database query in view file/template in CodeIgniter 4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$db = \Config\Database::connect();
$orderid = $order_resultval-&gt;userid;            		
$builder = $db-&gt;table('tb_customer');
$builder-&gt;select('*');
$builder-&gt;where('id', $orderid);					
$query = $builder-&gt;get();
$details = $query-&gt;getResult();</pre><p>&nbsp;</p>
<p>The post <a href="https://www.codypaste.com/database-query-in-view-file-template-in-codeigniter-4/">Database query in view file/template in CodeIgniter 4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/database-query-in-view-file-template-in-codeigniter-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Convert Dashes to Underscores in URLs automatically in CI4</title>
		<link>https://www.codypaste.com/convert-dashes-to-underscores-in-urls-automatically-in-ci4/</link>
					<comments>https://www.codypaste.com/convert-dashes-to-underscores-in-urls-automatically-in-ci4/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Fri, 22 Nov 2024 06:20:53 +0000</pubDate>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CodeIgniter 4]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1219</guid>

					<description><![CDATA[<p>dashes to underscore in ci4 url Step 1: Create a Custom Router Create a custom router that converts dashes to underscores in controller methods. File Path: app/Controllers/Router.php [crayon-698f600d23d53050621357/] Step 2: Modify Routes.php In app/Config/Routes.php, include the Router::convertDashToUnderscore method to enable the mapping. Update Your Routes.php [crayon-698f600d23d63694667434/] Step 3: Test the URL Now, accessing http://yourdomain.com/admin/configurator/configurator/order-partial-payment will &#8230; </p>
<p class="link-more"><a href="https://www.codypaste.com/convert-dashes-to-underscores-in-urls-automatically-in-ci4/" class="more-link">read more<span class="screen-reader-text"> "Convert Dashes to Underscores in URLs automatically in CI4"</span></a></p>
<p>The post <a href="https://www.codypaste.com/convert-dashes-to-underscores-in-urls-automatically-in-ci4/">Convert Dashes to Underscores in URLs automatically in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>dashes to underscore in ci4 url</p>
<h2><strong>Step 1: Create a Custom Router</strong></h2>
<p>Create a custom router that converts dashes to underscores in controller methods.</p>
<h4>File Path: <code>app/Controllers/Router.php</code></h4>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">namespace App\Controllers;

use CodeIgniter\Router\RouteCollection;

class Router
{
    public static function convertDashToUnderscore(RouteCollection $routes)
    {
        $routes-&gt;setAutoRoute(false); // Disable default auto-routing for security.

        // Add a custom handler for dashes in method names.
        $routes-&gt;setTranslateURIDashes(true);
    }
}</pre><p></p>
<h2><strong>Step 2: Modify <code>Routes.php</code></strong></h2>
<p>In <code>app/Config/Routes.php</code>, include the <code>Router::convertDashToUnderscore</code> method to enable the mapping.</p>
<h4>Update Your <code>Routes.php</code></h4>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">use App\Controllers\Router;

// Convert dashes to underscores in URLs automatically.
Router::convertDashToUnderscore($routes);

// Example route
$routes-&gt;match(['get', 'post'], 'admin/configurator/configurator/(:any)', 'admin\configurator\Configurator::$1');</pre><p></p>
<h2><strong>Step 3: Test the URL</strong></h2>
<p>Now, accessing <code>http://yourdomain.com/admin/configurator/configurator/order-partial-payment</code> will automatically call the <code>order_partial_payment</code> method in your controller.</p>
<h3>Notes:</h3>
<ol>
<li><strong>Security Implications</strong>:
<ul>
<li>Be cautious when enabling auto-routing (<code>$routes-&gt;setAutoRoute(true)</code>), as it allows users to call any public method in your controllers.</li>
<li>It&#8217;s recommended to explicitly define routes to prevent unintended access.</li>
</ul>
</li>
<li><strong>Debugging</strong>:
<ul>
<li>Check routes using <code>php spark routes</code> to verify if your route is being mapped correctly.</li>
</ul>
</li>
</ol>
<p>The post <a href="https://www.codypaste.com/convert-dashes-to-underscores-in-urls-automatically-in-ci4/">Convert Dashes to Underscores in URLs automatically in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/convert-dashes-to-underscores-in-urls-automatically-in-ci4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>URI Segment in CI4</title>
		<link>https://www.codypaste.com/uri-segment-in-ci4/</link>
					<comments>https://www.codypaste.com/uri-segment-in-ci4/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Thu, 21 Nov 2024 05:44:19 +0000</pubDate>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CodeIgniter 4]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1214</guid>

					<description><![CDATA[<p>url segment in ci4 [crayon-698f600d2415d810542563/] &#160;</p>
<p>The post <a href="https://www.codypaste.com/uri-segment-in-ci4/">URI Segment in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>url segment in ci4</p><pre class="urvanov-syntax-highlighter-plain-tag">echo $orderid = $this-&gt;request-&gt;getUri()-&gt;getSegment(5);</pre><p>&nbsp;</p>
<p>The post <a href="https://www.codypaste.com/uri-segment-in-ci4/">URI Segment in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/uri-segment-in-ci4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Redirect in CI4</title>
		<link>https://www.codypaste.com/redirect-in-ci4/</link>
					<comments>https://www.codypaste.com/redirect-in-ci4/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Tue, 19 Nov 2024 11:49:55 +0000</pubDate>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CodeIgniter 4]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=1212</guid>

					<description><![CDATA[<p>Redirect with a Flash Message To pass data (like success or error messages) during a redirect, you can use session flashdata. Example: Set flashdata in the controller before redirecting: [crayon-698f600d24fa0045080930/] Retrieve flashdata in the redirected page: [crayon-698f600d24fb1379872473/] &#160; Redirect with POST/GET Data To pass query parameters or data, append them to the redirect URL. [crayon-698f600d24fb5971838546/] &#8230; </p>
<p class="link-more"><a href="https://www.codypaste.com/redirect-in-ci4/" class="more-link">read more<span class="screen-reader-text"> "Redirect in CI4"</span></a></p>
<p>The post <a href="https://www.codypaste.com/redirect-in-ci4/">Redirect in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2><strong>Redirect with a Flash Message</strong></h2>
<p>To pass data (like success or error messages) during a redirect, you can use session flashdata.</p>
<h4>Example:</h4>
<p>Set flashdata in the controller before redirecting:</p><pre class="urvanov-syntax-highlighter-plain-tag">session()-&gt;setFlashdata('success', 'Operation completed successfully.');
return redirect()-&gt;to('/dashboard');</pre><p>Retrieve flashdata in the redirected page:</p><pre class="urvanov-syntax-highlighter-plain-tag">if (session()-&gt;getFlashdata('success')) {
    echo session()-&gt;getFlashdata('success');
}</pre><p>&nbsp;</p>
<h2><strong>Redirect with <code>POST</code>/<code>GET</code> Data</strong></h2>
<p>To pass query parameters or data, append them to the redirect URL.</p><pre class="urvanov-syntax-highlighter-plain-tag">return redirect()-&gt;to('/search')-&gt;withInput(['query' =&gt; 'CodeIgniter']);</pre><p>Retrieve input in the redirected controller:</p><pre class="urvanov-syntax-highlighter-plain-tag">$query = $this-&gt;request-&gt;getVar('query');</pre><p></p>
<h2><strong>Conditional Redirect</strong></h2>
<p>You can dynamically redirect users based on conditions.</p><pre class="urvanov-syntax-highlighter-plain-tag">if ($user-&gt;isAdmin) {
    return redirect()-&gt;to('/admin/dashboard');
} else {
    return redirect()-&gt;to('/user/dashboard');
}</pre><p></p>
<h2><strong>Use <code>redirect()</code> Helper Function</strong></h2>
<p>The <code>redirect()</code> function is a global helper and can be used without <code>$this</code> or <code>BaseController</code>.</p>
<h4>Example:</h4>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">return redirect()-&gt;to('/home');</pre><p>&nbsp;</p>
<p>The post <a href="https://www.codypaste.com/redirect-in-ci4/">Redirect in CI4</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/redirect-in-ci4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
