usage of post date ($_POST) or variable ($nom)

usage of post date ($_POST) or variable ($nom)

pcolynpcolyn Posts: 8Questions: 2Answers: 0
edited May 2018 in Editor

Hi,
I'm not a specialist in program language but Data Tables help me a lot to build what I need.
Now i'm blocked on it:

<?php

// DataTables PHP library
include(  "../../DataTables_new/Original/php/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;

//mysqli_set_charset($db,'utf8');
//$db->sql( "SET NAMES 'utf8'" );
//$db->query("SET NAMES 'utf8'")->exec();



Editor::inst( $db,'prat_listing')



    ->fields(

        Field::inst( 'ID' )->validator( 'Validate::notEmpty' ),
       

This is the part where I need help


) ->where( function ( $q ) { $q->where( function ( $r ) { $r->or_where( 'nom', $_POST['nom']); // $r->or_where( 'nom', $nom); } ); } ) ->process( $_POST ) ->json(); ?>

I tried to create a form where user is providing it's name and following the name provided I must have a table with some information. concerning only this user.

   <form method="post" action="gestion_modification.php" >

   <label for="nom">Nom:</label>
            <input type="text"  name="nom"  placeholder="" value="">

            <button type="submit" class="button-submit1"> Continuer </button>
            <br><br>
    </form>

Problem I tried both:

$r->or_where( 'nom', $_POST['nom']);
 $r->or_where( 'nom', $nom);

and nothing works. so I don't know how to write it correctly :(

many thanks in advance for your help

kind regards

Philippe

Answers

  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin

    I guess the first question is, are you POSTing the nom value with the DataTables and Editor Ajax requests? ajax.data and ajax.data can be used for that.

    Allan

  • pcolynpcolyn Posts: 8Questions: 2Answers: 0
    edited May 2018

    Thanks allan for your answer.

    No I just post my "nom" value via a form in html

    <form method="post" action="gestion_modification.php" >
     
    <label for="nom">Nom:</label>
             <input type="text"  name="nom"  placeholder="" value="">
     
             <button type="submit" class="button-submit1"> Continuer </button>
             <br><br>
     </form>
    

    To be honest I don't undrestand your question

    But I do a additional test:

    If In

    //modification.php file
    
    <form method="post" action="script_modification.php" >
    

    I replace gestion_modification.php by script_modification.php

    it works with:


    ->where( function ( $q ) { $q->where( function ( $r ) { $r->or_where( 'nom', $_POST['nom']); } ); } ) ->process( $_POST ) ->json();

    But I don't have a table only the data is diplayed.

    Modification.php is the file where I have the form and users can enter is name (nom)
    gestion_modification.php is my file where all the settings is done to built the table.
    script_modification.php is the file where I place my server request (DB request)

    So my question is how can I used the post_data value from gestion_modification.php to script_modification.php.

    I don't know if you understand, it is really complex for me to explain

  • pcolynpcolyn Posts: 8Questions: 2Answers: 0

    I still blocked on this subjet, could I have some help / guidance, please :)

  • pcolynpcolyn Posts: 8Questions: 2Answers: 0

    First file HMTL where fill in the formular:

    <form method="post" action="gestion_modification.php" >
    
         <label for="nom">Nom:</label>
                <input type="text"  name="nom"  placeholder="" value="">
    
                <button type="submit" class="button-submit1"> Continue </button>
    </form>
             
    

    the datatable file:

     $('#example').DataTable( {
    
                    dom: '<"top"fl><"clear"><"top"B>rt<"bottom"ip><"clear">',
                    iDisplayLength: 100,
                    lengthMenu: [[5, 10, 20, 50, 100, -1], [5, 10, 20, 50, 100, "All"]],
                    columnDefs: [
                        { type: "num-html", targets: 4 }
                    ],
    
                    ajax: "script_modification.php",
                    columns: [
    
                        { data: "nom" },
                        
                     
                   ....................................................     
                        
                   
    

    server side:

    <?php
    
    // DataTables PHP library
    include(  "../../DataTables_new/Original/php/DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    
    
    Editor::inst( $db,'prat_listing')
    
    
    
        ->fields(
    
     Field::inst( 'nom' )
                ->validator( 'Validate::notEmpty' )
                ->getFormatter( 'Format::CapitaliseFirstLetter' )
                ->setFormatter( 'Format::CapitaliseFirstLetter' ),
    
     )
        -
    >where( function ( $q ) {
            $q->where( function ( $r ) {
    
                $r->where( 'nom', $_POST['nom']);
            
    
            } );
        } )
    
        ->process( $_POST )
        ->json();
    ?>
    
    
  • pcolynpcolyn Posts: 8Questions: 2Answers: 0
    edited September 2018

    I'm blocked since along time now :(
    Could please kindly help me

    maybe just provide a concrete example

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406

    This is not a data tables related issue and I am afraid you can't expect any help on stuff like this in this forum. Sorry. But let me give it a try:

    You need to understand the difference between a $_POST and a $_SESSION variable. Read the PHP docs please or take an online course. There are many of them.

    Here is an example:
    Upon log in I save the id of the user in a session variable that I use later on in Editor queries as well. This certainly would not work with a $_POST variable.

    I call my login function and save a couple of session variables if login was successful

    $r = login($parm, $dbh);
    // if session id is set this means login was successful
    if ($r['isOk']) {
        $_SESSION['id'] = $r['id'];
        $_SESSION['type'] = $r['type'];
        $_SESSION['role'] = $r['role'];
    }
    

    Upon logout the session variables are deleted:

    function logout () {
        session_destroy();
        $_SESSION = [];
    }
    

    I can use the session variables in Editor as well:

    e.g.
    
    ->where( function ( $q ) {        
        $q  ->where( 'report.user_id', $_SESSION['id'] );
        $q  ->where( 'report_type.user_id', $_SESSION['id'] );
    } )
    
    
  • pcolynpcolyn Posts: 8Questions: 2Answers: 0

    thanks a lot for your answer. Ok I think that I understand the variable "nom" is already used in the second file, so When I call it in the third page, it doesn't exist anymore.
    so I may used $_SESSION to keep the variable in my entire process.

    I will try it directly

    thanks so much to have answe :)

This discussion has been closed.