0

I have created an example of what I am trying to accomplish:

  1. I have an index page with a form + input elements (example.php).
  2. When submitted I call a php page via jQuery that processes the form data and outputs result in div on index page (proces.php)
  3. From within this php process page loaded in the div I have a button that when clicked I want to save $_POST data + other values from that page into MySQL.

I simply just cannot figure out how to "re-use" $_POST data and new values from example.php file and process.php file so I can save it from proces page when clicking button on proces.php page.

This is the example: http://mazey.dk/example.php

When form on index page is submitted the proces.php is called and here all POST data is parsed. This data I want to save when clicking Save button in proces.php file.

I hope someone can guide me in the right direction.

Thanks

***** UPDATE *****

Let me break down the code I have:

On example.php page I have a POST form with an action and a jQuery/AJAX script that prevents form from submitting in a normal way, instead it sends POST to form action URL. Result is then shown inside the with .previews class.

<script>
$(document).ready(function(){ 

    $('.selectform').ajaxForm( {
    target: ".previews",
    //success: function(res) {
        //$( "#currentOrders" ).load(window.location.href + " #currentOrders" );
    //}
    });

});
</script>

<form action="proces.php" class="selectform" method="post">
    <input name="test" type="hidden" value="123">
    <div class="form-group col-md-9">
        <input name="inputtest" type="text">
    </div>
    <div class="form-group col-md-9">
        <div class="">
            <button class="btn btn-primary btn-lg" type="submit"><i aria-hidden="true" class="fa fa-calculator"></i> Calculate</button> <button class="btn btn-default btn-outline btn-lg" type="reset">Reset</button>
        </div>
    </div>
</form>
<div class="col-md-6 col-lg-6 col-xl-6 col-xxl-6">
    <div class="previews"></div>
</div>

Inside proces.php file (that displays in the .previews ) I have a button. This button I want to trigger a "save-action" so when clicked I can save POST values + other variables that will be defined in proces.php into the MySQL DB. I have no problem in handling functionality to MySQL, but I need to figure out how to call POST data + variables upon clicking the button.

Proces.php file:

<input type="submit" name="save" value="SAVE" class="btn btn-lg btn-default">

<?
    print_r($_POST);
    $newTest = "Check";
    $data = 234;
    // TEMPERATURE CONTROLLER
    $controller = explode("|",$_POST[controller]);
    $controllerCostEach = $controller[1];
    $controllerName = $controller[2];
    $controllerCost = $controller[1];
    $qtyController = $controller[0];
    $controllerAssemblyCost = $controller[3];
    $totalControllerAssemblyCost = $controllerAssemblyCost * $qtyController;
    $controllerCost = $qtyController * $controllerCost;

//SUBMIT BUTTON CLICKED
//E.g if(save).clicked{
echo "HERE I can save original $_POST data + other variables from $_POST values from index file and this proces.php file via standard mysqli_query";
//}
//SUBMIT
?>

I hope with this explanation that someone can help me :-)

MazeyMazey
  • 303
  • 1
  • 2
  • 14
  • Please show us the relevant code here, not on an external site. I am just guessing but it sounds like your 2nd button is generated and displayed by `process.php`. Note that any JS selectors or event handlers specified at page load will only match elements which exist at page load. It means any JS you have for handling that button click will not work, unless you have already delegated to take that into account. See https://stackoverflow.com/questions/1359018/how-do-i-attach-events-to-dynamic-html-elements-with-jquery – Don't Panic Jun 30 '20 at 00:14
  • @Don'tPanic - I have updated my question so it includes code. – MazeyMazey Jun 30 '20 at 06:19
  • OK, and what happens? Do you see your button, and your `print_r()` output in the `.preview` div, as you want? Since you are already `echo`ing out HTML, can you just echo out a bunch of hidden ``s, with the data you want? Are you processing the new button with JS (if yes, where is the code, and did you note my comments above) or is that a plain HTML form? – Don't Panic Jul 01 '20 at 00:13

0 Answers0