Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6682283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:41:15+00:00 2026-05-26T04:41:15+00:00

This is simple but I don’t seem able to make it happen in Codeigniter.

  • 0

This is simple but I don’t seem able to make it happen in Codeigniter.

Using simple php it should be:

<form id="volume" method="post" action="<?php echo $PHP_SELF;?>">
<label>length(cm):</label>
<input type="text" name="length">
<label>width(cm):</label>
<input type="text" name="width">
<label>height(cm):</label>
<input type="text" name="height">
<button type="submit">Submit</button>
</form>


<?php

$length = $_POST["length"];
$width = $_POST["width"];
$height = $_POST["height"];
$variable = 5000;

$sum_total = ($length * $width * $height) / $variable;

printf ("%01.2f" , $sum_total);

?> kg

I put the form in my view, the php in my controller but I want it to return the result in the same page instead of redirecting me.

Thank you all in advance for your responses.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:41:16+00:00Added an answer on May 26, 2026 at 4:41 am

    Put jQuery similar to this on the page with your submit button.

    $(document).ready(function(){
      $('#volume').submit(function(event){
        event.preventDefault();
    
        var post_array = {
            length: $('input[name=length]').val();
            width: $('input[name=width]').val();
            // etc
        };
    
        $.post('path/to/controller/method', post_array, function(data){
            alert(data); // do stuff;
        }
    
        return false; //to stop the form from submitting
      });
    });
    

    Put the PHP that calculates the result in ‘path/to/controller/method’ and have it return $result;.

    When a user clicks the submit button it will submit an ajax request to your new view and return the result to jQuery where you can then change the page or w/e you want to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This must be a very simple question, but I don't seem to be able
I know that this is a simple question for PHP guys but I don't
this should be pretty simple but I don't get it. How can I draw
I know this should be fairly simple but I don't get it anyhow. I've
I'm sure this is fairly simple but I really don't get php is there
This should be simple but I don't manage to get it working. I have
this is simple I know, but i don't have internet access and this netcafes
Ok so this maybe a simple/silly question but I don't know so here goes:
This is probably quite simple, but I just don't know how to do this...
This is probably a simple question, but I really don't know what I'm doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.