How to get the input value of form field?

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
sakurahui97
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sat Dec 22, 2018 3:23 pm

How to get the input value of form field?

Post by sakurahui97 » Sat Dec 22, 2018 3:28 pm

I am currently constructing a component in Joomla and I have to get the values of the form field that user submitted. After that, I have to insert the values into database. The problem is that I can't get the value of the form field. Thank you.

Code: Select all

<?php
    $input = JFactory::getApplication()->input; 
    $formData = new JInput($input->get('jform', '', 'array')); 

    $name = $formData->get('inventory_name', 'test');
    $leadtime = $formData->get('leadtime', null);
    $max_lead = $formData->get('max_lead', null);
    $daily_usage = $formData->get('daily_usage', null);
    $max_usage = $formData->get('max_usage', null); 

    //formula to calculate reorder point
    $lead_time_demand = $leadtime * $daily_usage;
    $safety_stock = ($max_usage * $max_lead) - ($daily_usage * $leadtime);
    $reorder_point = $lead_time_demand + $safety_stock;

    if (empty($this->item->id)){ //For new added item

        $sql_new = "INSERT INTO wer_reorder_point_list (inventory_name, reorder_point)
                    VALUES ('$name', '$reorder_point');";
        mysqli_query($con,$sql_new);
    }
?>
Last edited by toivo on Sat Dec 22, 2018 3:53 pm, edited 1 time in total.
Reason: mod note: moved from General Questions/New to Joomla! 3.x

User avatar
pmleconte
Joomla! Guru
Joomla! Guru
Posts: 591
Joined: Fri Mar 17, 2017 12:55 pm
Location: France

Re: How to get the input value of form field?

Post by pmleconte » Sat Dec 22, 2018 8:04 pm

Hi,

Depending on your form definition, the correct syntax should be :

Code: Select all

<?php
    $input = JFactory::getApplication()->input; 
    $formData = $input->getVar('jform', array(),'post', 'array'); // store result in an array

    $name = $formData['inventory_name'];
    $leadtime = (int)$formData['leadtime'];
    $max_lead = (int)$formData['max_lead'];
    ....
If anything can go wrong, it will.
https://www.conseilgouz.com/en


Locked

Return to “Joomla! 3.x Coding”