The datatable cant display the searching and sorting, may I know why?

The datatable cant display the searching and sorting, may I know why? The problem is, the searching, sorting didn’t display. But when I use HTML code 100% then it will display, but when I use data that fetch from MySQL, it didn’t display the searching and sorting but it displays the table. I’m new to this and still a student. This is where the js and css link I take
datatable

table for datatype

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Content filter for IHSR</title>

    <!--Link from datatable for sort,pagging,search-->
    <link href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
</head>

<body >
    <?php
    include('connection.php');

    // select column from table ihsr_facebook_content
    $query = "SELECT * FROM customer ORDER BY Customer_Name ASC";//later change to DESC
    // get results from database
    $result = mysqli_query($connect, $query);

    // display data in table
    if(mysqli_num_rows($result)>0)
    {
    $output = '<div>
                <table id="example" class="display" style="width:100%">
                  <thead class="table-dark">
                    <tr>
                      <th style="padding-left: 10px; padding-right: 20px;" >No.</th>
                      <th style="padding-left: 10px; padding-right: 20px;" colspan="2">Name</th>
                      <th style="padding-left: 10px; padding-right: 20px;" >Email</th>
                      <th style="padding-left: 10px; padding-right: 20px;" >Contact</th>
                      <th style="padding-left: 10px; padding-right: 20px;" >Address</th>
                      <th width="7%">Edit</th>
                      <th width="9%">Delete</th>
                    </tr>
                  </thead>
                <tbody>';
    $num = mysqli_num_rows($result);
    $count= 1 ;
    // loop through results of database query, displaying them in the table
    while($row = mysqli_fetch_array( $result )) {
      $Customer_ID = $row['Customer_Id'];
      $Customer_Name = $row['Customer_Name'];
      $Customer_Email = $row['Customer_Email'];
      $Customer_Contact = $row['Customer_Contact'];
      $Customer_Address = $row['Customer_Address'];

    // echo out the contents of each row into a table
      $output.='<tr>
                  <td>'.$count.'</td>
                  <td colspan="2">'.$Customer_Name.'</td>
                  <td>'.$Customer_Email.'</td>
                  <td>'.$Customer_Contact.'</td>
                  <td>'.$Customer_Address.'</td>
                  <td><a class="btn-1" href="product_edit.php?GetEdit='.$Customer_ID.'" id="myBtn">Edit</a></td>
                  <td><button type="button" class="delButton btn-1" data-toggle="modal" id="'.$Customer_ID.'" data-target="#myModal" >Delete</button></td>
                </tr>';
      $count++;
    }
    }
    // close table>
    echo $output.'</tbody></table></div>';
    ?>

<script>
$(document).ready(function() {
    $('#example').DataTable();
} );

</script>
</body>
</html>

first time trying email for with php, help would be appreciated

I am trying to send some basic text data from a html form to an email. I found an article online with the php code contain below. Here is the link to the article https://html.form.guide/email-form/php-form-to-email/. I am using easyphp dev server to run my code and it is reporting an error on line 22 of the php file. Here is the error: Parse error: syntax error, unexpected ‘mail’ (T_STRING) in C:Program Files (x86)EasyPHP-Devserver-17eds-wwwform-to-email.php on line 22. Any help in clarifying what this means would be greatly appreciated as this is my first time attempting this. Thanks in advance.

<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

$email_from = '[email protected]';

$email_subject = "New Form submission";

$email_body = "You have received a new message from the user $name.n".
                        "Here is the message:n $message".
                        

$to = "[email protected]";

$headers = "From: $email_from rn";

$headers .= "Reply-To: $visitor_email rn";


ini_set(25)
mail($to,$email_subject, $email_body,$headers);

?>

Sort A Multi Dimensional Array In Laravel

enter image description here

This is the result of dd() that I use in my controller on laravel 8. I want to sort the data based on the JB column. I can’t use the manual order by in SQL syntax because I get JB from complex DB RAW. Therefore I want to sort this multi-dimensional array using php. Does anyone know how to sort the multi-dimensional array based on JB column value?

Send data with cURL by post’s data

Hi can I concatenate my post data?

CURLOPT_POSTFIELDS => "{"contact":{"dataFields":[{"key":"FIRSTNAME","value":"Foo"},{"key":"LASTNAME","value":"Bar"}],"email":"[email protected]","optInType":"Single","emailType":"PlainText"},"consentFields":{"fields":[{"key":"UK_OPT_IN_COUNT","value":"Y"}]}}"

I need to replace Foo with $_POST['firstName'], Bar with $_POST['lastName'], and [email protected] with $_POST['email']

Carry over Phone Number field to meta field WooCommerce

so I’ve implemented a phone login and register option in WooCommerce with the code:

function wooc_add_phone_number_field() {
    return apply_filters( 'woocommerce_forms_field', array(
        'wooc_user_phone' => array(
            'type'        => 'text',
            'pattern'     => '[0][0-9]{9}',
            'label'       => __( 'Phone Number', ' woocommerce' ),
            'placeholder' => __( 'MUST START WITH 0 e.g 081 123 4567', 'woocommerce' ),
            'required'    => true,
        ),
    ) );
}
add_action( 'woocommerce_register_form', 'wooc_add_field_to_registeration_form', 15 );
function wooc_add_field_to_registeration_form() {
    $fields = wooc_add_phone_number_field();
    foreach ( $fields as $key => $field_args ) {
        woocommerce_form_field( $key, $field_args );
    }
}


//Store
add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
function wooc_save_extra_register_fields( $customer_id ) {
    if (isset($_POST['wooc_user_phone'])){
        update_user_meta( $customer_id, 'wooc_user_phone', sanitize_text_field( $_POST['wooc_user_phone'] ) );
    }
}

//Check against phone
function wooc_get_users_by_phone($phone_number){
    $user_query = new WP_User_Query( array(
        'meta_key' => 'wooc_user_phone',
        'meta_value' => $phone_number,
        'compare'=> '='
    ));
    return $user_query->get_results();
}


//Authenticate 
add_filter('authenticate','wooc_login_with_phone',30,3);
function wooc_login_with_phone($user, $username, $password ){
    if($username != ''){
        $users_with_phone = wooc_get_users_by_phone($username);
        if(empty($users_with_phone)){
            return $user;
  }
  $phone_user = $users_with_phone[0];
  
  if ( wp_check_password( $password, $phone_user->user_pass, $phone_user->ID ) ){
   return $phone_user;
  }
    }
    return $user;
}


//Login label
add_filter( 'gettext', 'wooc_change_login_label', 10, 3 );
function wooc_change_login_label( $translated, $original, $domain ) {
    if ( $translated == "Username or email address" && $domain === 'woocommerce' ) {
        $translated = "Username or email address or phone";
    }
    return $translated;
}

Which works perfectly fine however what I want to do is then populate the phone field in the Billing Address with the value that is stored here so when a user goes to Billing Form theyll find the same details they entered when registering.

Run PHP script after Azure Web app deployment

I am having an Azure app Service and I want to upload/deploy an .php file to it an run it right after the upload.

I managed to upload it via curl and also start a post deployment script. Unfortunately I can not use the command “php …” in it because I get an error like: “/opt/Kudu/Scripts/starter.sh: line 2: exec: php: not foundn” in the logs.
The same occurs if I use the “/api/command” endpoint with the same command. I get the same kind of error in the response.

It seems like the php executable is not known in that environment.
Is there any way to run a php script via the command API or in a post deployment script?

Thanks in advance

PHP simplexml – dealing with namespaces

Background
I am trying to extract the value of the following element

<D:POD>2021-08-07</D:POD>

from the following XML.

The output I am trying to get

2021-08-07

The problem of this XML is that its elements (including the root element) contain namespaces. I am struggling to deal with this using simplexml.

My steps

I request and receive the above XML from the api using

$this->curl = curl_init($this->url);
curl_setopt($this->curl, CURLOPT_URL, $this->url);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
$this->headers = array(
    "Accept: application/xml",
 );
 curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->headers);

 $this->resp = curl_exec($this->curl);
 curl_close($this->curl); 

Then I run simplex_load_string:

$this->xml = simplexml_load_string($this->resp);

I am trying to access:

<are:Ares_odpovedi>(root)
   <are:Odpoved>
      <D:Vypis_OR>
         <D:ZAU>
 ->         <D:POD>2021-08-07</D:POD>

I am not able to point to the element <D:POD> with the standard $xml->element_lvl1->element_lvl2… since all the elements have namespaces.

I tried running print_r on the result to help me to point to these namespaced elements:

print_r($this->xml);

but it only displays the attributes of the root element (are:Ares_odpovedi) in the XMLobject. I cannot see any child elements of this root element.

SimpleXMLElement Object ( [@attributes] => Array ( [odpoved_datum_cas]
=> 2022-01-17T11:41:46 [odpoved_pocet] => 1 [odpoved_typ] => Vypis_OR [vystup_format] => XML [xslt] => klient [validation_XSLT] =>
http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_odpovedi.xsl
[Id] => ares ) )

Question:
Is there please a way how to get the value of a specific child element (<D:POD>2021-08-07</D:POD>) in this xml where all the elements (including the root element) contain namespaces?

HIGHCHARTS PROBLEM: ajax call from an .php JSON data file for display it on the chart not working

we are two students that have to load on a highcharts chart some x and y data taken from a .php file that contains the data in JSON format, but after making the AJAX call we do not know how to recall the data on the chart, we have seen a lot of guides but, we can’t find anything, if you can help us we will be glad.

Our complete code:
Html:

<html lang="it">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <script src="https://code.highcharts.com/highcharts.js"></script>
 <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
 <title>Grafico Stage</title>
</head>
<body>

 <div id="container"></div>

 <script src="index.js"></script>
</body>
</html>

.javaScript

    Highcharts.chart('container', {
        colors: ["#669900"],
        chart: {
            type: 'spline',
            zoomType: 'x,y',
        },
        title: {
            text: 'Grafico Stage Samela-Ungureanu'
        },
        credits: {
            text: 'Powered by Sirius s.r.l',
            href: 'http://www.sirius.to.it/',
            position: {
                align: 'left',
                x: 70,
                y: -355
            },
            style: {
                fontSize: "15px",
                color: "#669900"
            }
        },
        yAxis: {
            title: {
                text: null,
            },
        },
        series: [
            {
                name: 'Potenza',
                data: []
            },
        ],
        xAxis: {
            categories: []
        },
        series: [
            {
                name: 'SSEMontalto.Montalto.WPP.Line 01.WTG01.DMAV.Active Power',
                data: []

            },

        ]

    });
    $.ajax({
        url: "getData.php",
        cache: false,
        dataType: "json",
        type: "GET",
        complete: function (data) {
            console.log("Ajax request finished");
        },
        success: function (data) {

            console.log(data)
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.log("Error:" + textStatus);
        }
    })

});

.php with JSON format

{"SSEMontalto.Montalto.WPP.Line 01.WTG01.DMAV.Active Power":[{"unixdate":1641769200000,"value":558.571,"valid":true},{"unixdate":1641769800000,"value":613.30537229,"valid":true},{"unixdate":1641770400000,"value":622.3602128064896,"valid":true},{"unixdate":1641771000000,"value":659.07448648037,"valid":true},{"unixdate":1641771600000,"value":779.1308358631477,"valid":true},{"unixdate":1641772200000,"value":929.2911635973804,"valid":true},{"unixdate":1641772800000,"value":986.1693585565218,"valid":true},{"unixdate":1641773400000,"value":941.6240886305237,"valid":true},{"unixdate":1641774000000,"value":954.4424173490511,"valid":true},{"unixdate":1641774600000,"value":871.015560090988,"valid":true},{"unixdate":1641775200000,"value":857.4163941512874,"valid":true},{"unixdate":1641775800000,"value":869.1389910921237,"valid":true},{"unixdate":1641776400000,"value":788.9252844652405,"valid":true},{"unixdate":1641777000000,"value":882.9557112700836,"valid":true},{"unixdate":1641777600000,"value":975.8267588928936,"valid":true},{"unixdate":1641778200000,"value":1082.4865752934047,"valid":true},{"unixdate":1641778800000,"value":1028.8623553265202,"valid":false},{"unixdate":1641779400000,"value":1004.2612275483077,"valid":false},{"unixdate":1641780000000,"value":916.8332578616346,"valid":false},{"unixdate":1641780600000,"value":834.2073278298863,"valid":false},{"unixdate":1641781200000,"value":802.6701198012775,"valid":false},{"unixdate":1641781800000,"value":832.7614199225076,"valid":true},{"unixdate":1641782400000,"value":777.5618292029441,"valid":true},{"unixdate":1641783000000,"value":916.6365379741827,"valid":true},{"unixdate":1641783600000,"value":981.8332283741345,"valid":true},{"unixdate":1641784200000,"value":942.9703055286295,"valid":true},{"unixdate":1641784800000,"value":886.8984622509806,"valid":true},{"unixdate":1641785400000,"value":1017.234399567998,"valid":true},{"unixdate":1641786000000,"value":1175.1203679593466,"valid":true},{"unixdate":1641786600000,"value":1371.0740395573036,"valid":true},{"unixdate":1641787200000,"value":1501.2547774651905,"valid":true},{"unixdate":1641787800000,"value":1356.8190553252646,"valid":true},{"unixdate":1641788400000,"value":1367.9571829504296,"valid":true},{"unixdate":1641789000000,"value":1477.3964935008298,"valid":true},{"unixdate":1641789600000,"value":1590.378912944812,"valid":true},{"unixdate":1641790200000,"value":1647.0536558865135,"valid":true},{"unixdate":1641790800000,"value":1889.096425887316,"valid":true},{"unixdate":1641791400000,"value":1847.0262484828054,"valid":true},{"unixdate":1641792000000,"value":1960.263733724789,"valid":true},{"unixdate":1641792600000,"value":2210.8442468068292,"valid":true},{"unixdate":1641793200000,"value":2519.3321879407736,"valid":true},{"unixdate":1641793800000,"value":2276.6172056223713,"valid":true},{"unixdate":1641794400000,"value":2315.142121975913,"valid":true},{"unixdate":1641795000000,"value":2382.065935295871,"valid":true},{"unixdate":1641795600000,"value":2344.3363929467196,"valid":true},{"unixdate":1641796200000,"value":2522.0488132140454,"valid":true},{"unixdate":1641796800000,"value":2652.630412567016,"valid":true},{"unixdate":1641797400000,"value":3045.331124104262,"valid":true},{"unixdate":1641798000000,"value":2870.0692725809376,"valid":true},{"unixdate":1641798600000,"value":2806.2389319587373,"valid":true},{"unixdate":1641799200000,"value":2678.3053052896703,"valid":true},{"unixdate":1641799800000,"value":2514.4331951855215,"valid":true},{"unixdate":1641800400000,"value":2664.9572239821073,"valid":true},{"unixdate":1641801000000,"value":3092.4003729654933,"valid":true},{"unixdate":1641801600000,"value":3103.059877051105,"valid":true},{"unixdate":1641802200000,"value":3015.2091488719116,"valid":true},{"unixdate":1641802800000,"value":2996.9430118480454,"valid":true},{"unixdate":1641803400000,"value":3459.90777137532,"valid":true},{"unixdate":1641804000000,"value":3149.616322622838,"valid":true},{"unixdate":1641804600000,"value":2876.0973419336256,"valid":true},{"unixdate":1641805200000,"value":2712.3496158679764,"valid":true},{"unixdate":1641805800000,"value":3128.5542397236854,"valid":true},{"unixdate":1641806400000,"value":3654.620635133223,"valid":true},{"unixdate":1641807000000,"value":3857.583646725982,"valid":true},{"unixdate":1641807600000,"value":3889.5321544881663,"valid":true},{"unixdate":1641808200000,"value":4231.877106129751,"valid":true},{"unixdate":1641808800000,"value":4260.962797480181,"valid":true},{"unixdate":1641809400000,"value":4643.022026716241,"valid":true},{"unixdate":1641810000000,"value":5323.015817638969,"valid":true},{"unixdate":1641810600000,"value":6113.084440372033,"valid":true},{"unixdate":1641811200000,"value":7118.216123311324,"valid":true},{"unixdate":1641811800000,"value":8109.207053782603,"valid":true},{"unixdate":1641812400000,"value":8321.01143282035,"valid":true},{"unixdate":1641813000000,"value":8448.655748199813,"valid":true},{"unixdate":1641813600000,"value":7753.37362340171,"valid":true},{"unixdate":1641814200000,"value":9149.438324657798,"valid":true},{"unixdate":1641814800000,"value":9207.509809704403,"valid":true},{"unixdate":1641815400000,"value":8299.115306898586,"valid":true},{"unixdate":1641816000000,"value":7600.04762813729,"valid":true},{"unixdate":1641816600000,"value":7496.732580680392,"valid":true},{"unixdate":1641817200000,"value":7229.024260224295,"valid":true},{"unixdate":1641817800000,"value":6512.302649944357,"valid":true},{"unixdate":1641818400000,"value":6925.951089663522,"valid":true},{"unixdate":1641819000000,"value":7955.3967558267495,"valid":true},{"unixdate":1641819600000,"value":9233.765371314063,"valid":true},{"unixdate":1641820200000,"value":8361.017569713571,"valid":true},{"unixdate":1641820800000,"value":9688.253859747472,"valid":true},{"unixdate":1641821400000,"value":11162.38950228507,"valid":true},{"unixdate":1641822000000,"value":10203.975577229372,"valid":true},{"unixdate":1641822600000,"value":11722.123063609557,"valid":true},{"unixdate":1641823200000,"value":12441.474589654084,"valid":true},{"unixdate":1641823800000,"value":12923.071629545006,"valid":true},{"unixdate":1641824400000,"value":11823.447464587021,"valid":true},{"unixdate":1641825000000,"value":12596.795516350729,"valid":true},{"unixdate":1641825600000,"value":12336.230801095015,"valid":true},{"unixdate":1641826200000,"value":12052.374130361819,"valid":true},{"unixdate":1641826800000,"value":11394.278345721674,"valid":true},{"unixdate":1641827400000,"value":12538.12716029198,"valid":true},{"unixdate":1641828000000,"value":11657.210884137026,"valid":true},{"unixdate":1641828600000,"value":10614.496684972737,"valid":true}]}

PHP Paypal MALFORMED_REQUEST_JSON although JSON seems to be well formatted

I try to implement a paypal express checkout flow to a website.

The user must be able to adjust the order after they have logged in with paypal and choosed their payment option.

To do so, I create the order with paypal with the intent “AUTHORIZE” and user action “CONTINUE”. It is created, the user is sent back to our website and I can fetch order and payer information with the (order) id created.

But then, when the payer is done checking and adjusting some final parameters and clicks the “buy now” button, I want to send the update order call as referenced here:
https://developer.paypal.com/api/orders/v2/#orders_patch

I create the payload in exactly the same way as for order creation, but this time with intent “CAPTURE” and user_action=”PAY_NOW”. I PATCH it to the correct path, but I keep getting the failure message “MALFORMED_REQUEST_JSON” .

Hoewever, the JSON itself is a valid JSON, no errors thrown in creation. Here is a sample:

{
    intent: "CAPTURE",
    application_context: {
        landing_page: "NO_PREFERENCE",
        shipping_preference: "SET_PROVIDED_ADDRESS",
        user_action: "PAY_NOW",
    },
    purchase_units: [{
        reference_id: "2289256",
        description: "Your Order with us",
        custom_id: "OrderId 2289256",
        soft_descriptor: "Name of the site",
        invoice_id: "2289256",
        amount: {
            currency_code: "EUR",
            value: 59.98,
            breakdown: {
                item_total: {
                    currency_code: "EUR",
                    value: 50.41,
                },
                shipping: {
                    currency_code: "EUR",
                    value: 0,
                },
                discount: {
                    currency_code: "EUR",
                    value: 0,
                },
                tax_total: {
                    currency_code: "EUR",
                    value: 9.57,
                },
            },
        },
        items: [{
            name: "Product 1",
            description: "Product 1 description",
            sku: "1019879",
            unit_amount: {
                currency_code: "EUR",
                value: 16.8,
            },
            tax: {
                currency_code: "EUR",
                value: 3.19,
            },
            quantity: "1",
            category: "PHYSICAL_GOODS",
        }, {
            name: "Product 2",
            description: "Product 2 description",
            sku: "1024593",
            unit_amount: {
                currency_code: "EUR",
                value: 33.61,
            },
            tax: {
                currency_code: "EUR",
                value: 6.38,
            },
            quantity: "1",
            category: "PHYSICAL_GOODS",
        }, ],
        shipping: {
            name: {
                full_name: "John Doe"
            },
            address: {
                address_line_1: "Badensche Str.    24",
                address_line_2: " ",
                admin_area_2: "Berlin(Berlin)",
                postal_code: "10715",
                country_code: "DE",
            },
        },
    }],
}

Here is paypal´s response

{
    name: "INVALID_REQUEST",
    message: "Request is not well-formed, syntactically incorrect, or violates schema.",
    debug_id: "c315ce9eb90b4",
    details: [{
        field: "/",
        location: "body",
        issue: "MALFORMED_REQUEST_JSON",
        description: "The request JSON is not well formed.",
    }],
    links: [{
        href: "https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON",
        rel: "information_link",
        encType: "application/json",
    }],
}

I just cannot figure out the problem. I tried to remove the whole application_context, purchase_units, intent and see if there is a problem within any of these parameters. Nothing changed. What exactly is wrong with this call?

Contact Form with Custom Datepicker NMR don’t validate field when required

Using Custom Datepicker NMR plugin with CF7 which nearly duplicate the CF7 date.php module and add a new $tag where we can use jquery-ui-datepicker.

Everything works as except but when the field is required, the validation do not validate the datepicker field on form submit.

Looks like this line have no effect :

 **$atts['aria-invalid'] = $validation_error ? 'true' : 'false';**

Any help would be appreciated !

Thanks in advance

[PHP]

add_action('wpcf7_init', 'nmr_add_jqueryui_datepicker');
function nmr_add_jqueryui_datepicker()
{
    wpcf7_add_form_tag(
        array('datepicker', 'datepicker*'),
        'nmr_datepicker_form_tag_handler',
        array('name-attr' => true)
    );
}

function nmr_datepicker_form_tag_handler($tag)
{
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);

    $class = wpcf7_form_controls_class($tag->type);

    $class .= ' wpcf7-validates-as-date';

    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }

    $atts = array();
    $atts['class'] = $tag->get_class_option($class) . ' nmr-datepicker';
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'signed_int', true);
    $atts['min'] = $tag->get_date_option('min');
    $atts['max'] = $tag->get_date_option('max');
    $atts['step'] = $tag->get_option('step', 'int', true);
    $atts['data-format'] = $tag->get_option('format', '', true);

    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }

    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }

    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';

    $value = (string) reset($tag->values);

    if (
        $tag->has_option('placeholder')
        or $tag->has_option('watermark')
    ) {
        $atts['placeholder'] = $value;
        $value = '';
    }

    $value = $tag->get_default_option($value);

    $value = wpcf7_get_hangover($tag->name, $value);

    $atts['value'] = $value;

    $atts['type'] = 'text';
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);

    $html = sprintf(
        '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
        sanitize_html_class($tag->name),
        $atts,
        $validation_error
    );
    return $html;
}

function nmr_datepicker_enqueue_script() {   
    $path = plugin_dir_url( __FILE__ );
    wp_enqueue_style('jquery-ui-css', $path .'css/jquery-ui.css');
    wp_enqueue_script( 'nmr_datepicker', $path . 'js/nmr-datepicker.js' , array('jquery', 'jquery-ui-datepicker'));
}
add_action('wp_enqueue_scripts', 'nmr_datepicker_enqueue_script');

[JS]

(function ($) {
    $(document).ready(function () {
        $(".nmr-datepicker").each(function (i, item) {
            var settings = {};
            if (item.dataset.format) {
                settings.dateFormat = item.dataset.format;
            }
            if (item.id) {
                $(`#${item.id}`).datepicker(settings);
            }
        });
    });
})(jQuery);

combine 2 comma separated list into one in php

I have 2 arrays that are coming from the database, [options] column has comma-separated values.

Array
(
    [0] => Array
        (
            [id] => 143
            [menu_id] => 590
            [name] => bread
            [options] => small, large
        )

    [1] => Array
        (
            [id] => 144
            [menu_id] => 590
            [name] => jam
            [options] => mango, orange, grape
        )

)

Is there have any way to combine the list of [options] at [0] and [1]?

Example: small, large, mango, orange, grape

Approach

 <?php foreach ($menu_options as $key => $menu_option) : ?>  
     <?PHP $exploded_variant_options = explode(',', $menu_option['options']);
           foreach ($exploded_variant_options as $exploded_variant_option) : ?>
                     <?php echo ucfirst(sanitize($exploded_variant_option)); ?> //print one by one
                             
          <?php endforeach; ?>
  <?php endforeach; ?>

Drupal 9: implementing custom functionality in PHP

I would really appreciate it if somebody would give me some hints about implementing/inserting custom functionality into a drupal 9 page with PHP code.
I am trying to write a PHP function that is generating a file based on some specific properties of Drupal users on a button click, and I do not know where to start.
I am really confused. Is there an easy way to insert PHP code into a Drupal basic page?
I am searching for solutions, but what I always find is custom modules where none of the given examples is working

Bootstrap multiple images cropper upload problem

Herewith is a bootstrap code for cropping multiple images in a modal. I can’t figure out how to collect all cropped images and upload them into the images folder. I appreciate any help

index.php: contains the form and the modal

<?php
require 'admin/upload.php';
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Crop multiple images with cropper js</title>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" />
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <style>
            .g-height-50 {
                height: 50px;
            }
            .g-width-50 {
                width: 50px !important;
            }
            @media (min-width: 0){
                .g-pa-30 {
                    padding: 2.14286rem !important;
                }
            }
            .g-bg-secondary {
                background-color: #fafafa !important;
            }
            .u-shadow-v18 {
                box-shadow: 0 5px 10px -6px rgba(0, 0, 0, 0.15);
            }
            .g-color-gray-dark-v4 {
                color: #777 !important;
            }
            .g-font-size-12 {
                font-size: 0.85714rem !important;
            }
            .media-comment {
                margin-top:20px
            }
            .singleImageCanvasContainer{
                overflow: hidden;
                width: auto;
                height: auto;
                display: inline-block;
                position: relative;
                padding-right: 0px;
                margin-right: 15px;
                border: 2px solid #dfdfdf;
                margin-bottom: 10px;
                padding: 4px;
                border-radius: .25rem;
            }
            .singleImageCanvasContainer .singleImageCanvasCloseBtn{
                position: absolute;
                right: 0;
            }
            .singleImageCanvasContainer .singleImageCanvas{
                width: 100%;
                height: 100%;
                object-fit: cover;
            }
        </style>
    </head>
    <body>
        <div class="container m-5">
            <div class="row">
                <div class="col-md-12">
                    <input type="file" name="file" id="file" accept="image/*" multiple />
                </div>
            </div>
        </div>
        <div class="modal" id="cropperModal">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">Upload Images</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <form action="index_template.php" method="POST" id="myform" enctype="multipart/form-data">
                        <input type="hidden" id="post_img_data" name="image_data_url[]">
                        <div class="modal-body p-4">
                            <div class="img-preview"></div>
                            <div id="galleryImages"></div>
                            <div id="cropper">
                                <canvas id="cropperImg" width="0" height="0"></canvas>
                                <button type="button" class="cropImageBtn btn btn-danger" style="display:none;" id="cropImageBtn">Crop</button>
                            </div>
                            <div id="imageValidate" class="text-danger"></div>
                        </div>
                        <div class="modal-footer">
                            <button type="submit" class="btn btn-primary ">Upload</button>
                        </div>
                    </form>
                    <?php
                    print_r($_FILES['image_data_url']);
                    ?>
                </div>
            </div>
        </div>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.5/cropper.min.js" integrity="sha512-E4KfIuQAc9ZX6zW1IUJROqxrBqJXPuEcDKP6XesMdu2OV4LW7pj8+gkkyx2y646xEV7yxocPbaTtk2LQIJewXw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.5/cropper.min.css" integrity="sha512-Aix44jXZerxlqPbbSLJ03lEsUch9H/CmnNfWxShD6vJBbboR+rPdDXmKN+/QjISWT80D4wMjtM4Kx7+xkLVywQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
        <script>
            $(document).ready(function () {
                $("body").on("change", "#file", function (e) {
                    $('.singleImageCanvasContainer').remove();
                    $('#post_img_data').val('');
                });
            })
        </script>
        <script>
            var c;
            var galleryImagesContainer = document.getElementById('galleryImages');
            var imageCropFileInput = document.getElementById('file');
            var cropperImageInitCanvas = document.getElementById('cropperImg');
            var cropImageButton = document.getElementById('cropImageBtn');
            function imagesPreview(input) {
                var cropper;
                var img = [];
                if (input.files.length) {
                    var i = 0;
                    var index = 0;
                    for (let singleFile of input.files) {
                        var reader = new FileReader();
                        reader.onload = function (event) {
                            var blobUrl = event.target.result;
                            img.push(new Image());
                            img[i].onload = function (e) {
                                var singleCanvasImageContainer = document.createElement('div');
                                singleCanvasImageContainer.id = 'singleImageCanvasContainer' + index;
                                singleCanvasImageContainer.className = 'singleImageCanvasContainer';
                                var singleCanvasImageCloseBtn = document.createElement('button');
                                var singleCanvasImageCloseBtnText = document.createTextNode('X');
                                singleCanvasImageCloseBtn.id = 'singleImageCanvasCloseBtn' + index;
                                singleCanvasImageCloseBtn.className = 'singleImageCanvasCloseBtn';
                                singleCanvasImageCloseBtn.classList.add("btn", "btn-sm");
                                singleCanvasImageCloseBtn.onclick = function () {
                                    removeSingleCanvas(this)
                                };
singleCanvasImageCloseBtn.appendChild(singleCanvasImageCloseBtnText);singleCanvasImageContainer.appendChild(singleCanvasImageCloseBtn);
                                var canvas = document.createElement('canvas');
                                canvas.id = 'imageCanvas' + index;
                                canvas.className = 'imageCanvas singleImageCanvas';
                                canvas.width = e.currentTarget.width;
                                canvas.height = e.currentTarget.height;
                                canvas.onclick = function () {
                                    cropInit(canvas.id);
                                };
                                singleCanvasImageContainer.appendChild(canvas)
                                var ctx = canvas.getContext('2d');
                                ctx.drawImage(e.currentTarget, 0, 0);galleryImagesContainer.appendChild(singleCanvasImageContainer);
                                (document.querySelectorAll('.singleImageCanvas').length == input.files.length) {
                                document.querySelectorAll('.singleImageCanvas')[0].getAttribute('id');
                                urlConversion();
                                index++;
                            };
                            img[i].src = blobUrl;
                            i++;
                        }
                        reader.readAsDataURL(singleFile);
                    }
                }
            }
            imageCropFileInput.addEventListener("change", function (event) {
                $('#cropperModal').modal('show');
                var mediaValidation = validatePostMedia(event.target.files);
                if (!mediaValidation) {
                    var $el = $('#file');
                    $el.wrap('<form>').closest('form').get(0).reset();
                    $el.unwrap();
                    return false;
                }
                $('#mediaPreview').empty();
                $('.singleImageCanvasContainer').remove();
                if (cropperImageInitCanvas.cropper) {
                    cropperImageInitCanvas.cropper.destroy();
                    cropperImageInitCanvas.width = 0;
                    cropperImageInitCanvas.height = 0;
                    cropImageButton.style.display = 'none';
                }
                imagesPreview(event.target);
            });
            // Initialize Cropper
            function cropInit(selector) {
                c = document.getElementById(selector);
                if (cropperImageInitCanvas.cropper) {
                    cropperImageInitCanvas.cropper.destroy();
                }
                var allCloseButtons = document.querySelectorAll('.singleImageCanvasCloseBtn');
                for (let element of allCloseButtons) {
                    element.style.display = 'block';
                }
                c.previousSibling.style.display = 'none';
                // c.id = croppedImg;
                var ctx = c.getContext('2d');
                var imgData = ctx.getImageData(0, 0, c.width, c.height);
                var image = cropperImageInitCanvas;
                image.width = c.width;
                image.height = c.height;
                var ctx = image.getContext('2d');
                ctx.putImageData(imgData, 0, 0);
                cropper = new Cropper(image, {
                    aspectRatio: 3 / 1,
                    viewMode: 4,
                    preview: '.img-preview',
                    crop: function (event) {
                        cropImageButton.style.display = 'block';
                    }
                });
            }
            function image_crop() {
                if (cropperImageInitCanvas.cropper) {
                    var cropcanvas = cropperImageInitCanvas.cropper.getCroppedCanvas({
                        width: 250, height: 250
                    });
                    var ctx = cropcanvas.getContext('2d');
                    var imgData = ctx.getImageData(0, 0, cropcanvas.width, cropcanvas.height);
                    c.width = cropcanvas.width;
                    c.height = cropcanvas.height;
                    var ctx = c.getContext('2d');
                    ctx.putImageData(imgData, 0, 0);
                    cropperImageInitCanvas.cropper.destroy();
                    cropperImageInitCanvas.width = 0;
                    cropperImageInitCanvas.height = 0;
                    cropImageButton.style.display = 'none';
                    var allCloseButtons = document.querySelectorAll('.singleImageCanvasCloseBtn');
                    for (let element of allCloseButtons) {
                        element.style.display = 'block';
                    }
                    urlConversion();
                } else {
                    alert('Please select any Image you want to crop');
                }
            }
            cropImageButton.addEventListener("click", function () {
                image_crop();
            });
            function removeSingleCanvas(selector) {
                selector.parentNode.remove();
                urlConversion();
            }
            function urlConversion() {
                var allImageCanvas = document.querySelectorAll('.singleImageCanvas');
                var convertedUrl = '';
                canvasLength = allImageCanvas.length;
                for (let element of allImageCanvas) {
                    convertedUrl += element.toDataURL('image/jpeg');
                    convertedUrl += 'img_url';
                }
                document.getElementById('post_img_data').value = convertedUrl;
            }
        </script>
        <script>
            function validatePostMedia(files) {
                $('#imageValidate').empty();
                let err = 0;
                let ResponseTxt = '';
                if (files.length > 10) {
                    err += 1;
                    ResponseTxt += '<p> You can select maximum 10 files. </p>';
                }
                $(files).each(function (index, file) {
                    if (file.size > 1048576) {
                        err += 1;
                        ResponseTxt += 'File : ' + file.name + ' is greater than 1MB';
                    }
                });
                if (err > 0) {
                    $('#imageValidate').html(ResponseTxt);
                    return false;
                }
                return true;
            }
        </script>
        <script>
            $(document).ready(function () {
                        $('.upload').click(function () {
                    canvas = cropper.getCroppedCanvas({
                        width: 400,
                        height: 400
                    });
                    canvas.toBlob(function (blob) {
                        url = URL.createObjectURL(blob);
                        var reader = new FileReader();
                        reader.readAsDataURL(blob);
                        reader.onloadend = function () {
                            var base64data = reader.result;
                            $.ajax({
                                type: 'POST',
                                dataType: "json",
                                url: 'admin/upload.php',
                                data: {crop_image: base64data},
                                success: function (data)
                                {
                                    alert('success upload image');
                                }
                            });
                        };
                    });
                });
            });
        </script>
    </body>
</html>

upload.php: herewith I’m trying to collect cropped images for uploading and later I plan to store them in mySQL db

<?php
$folderPath = '../images/';
foreach($_POST["image_data_url"]['name'] as $key => $value){
$image_parts = explode(";base64,", $_POST['image_data_url']);
$image_type_aux = explode("image/", $image_parts[0]);  
$image_type = $image_type_aux[1];  
$image_base64 = base64_decode($image_parts[1]);  
$file = $folderPath . `uniqid()` . '.png';  
file_put_contents($file, $image_base64);  
echo json_encode(["image uploaded successfully."]);  
}
?>

How to autofill with same number as previous box?

i had this code

<div class="col-sm-4">
<?=
$this->Form->control('value[' . $key . '][2]', [
'label' => false,
'class' => 'form-control desktop-country',
'type' => 'text',
'placeholder' => __('Desktop'),
'value' => isset($option->value[$key][2]) ? $option->value[$key][2] : '',
]);
                            

?>
</div>
<div class="col-sm-4">
<?=
$this->Form->control('value[' . $key . '][3]', [
'label' => false,
'class' => 'form-control mobile-country',
'type' => 'text',
'placeholder' => __('Mobile / Tablet'),
'value' => isset($option->value[$key][3]) ? $option->value[$key][3] : '',
]);

?>
</div>

it will turn like this
Example of the code

the question is… how can i make the box automatically fill with any number entered from another box? example
on india on desktop side… i fill it with 3 and the mobile/tablet will be automatically filled with 3 also… can i do that?
i hope somone can help me… i already stuck with this since morning lol….
any suggestion?

Is the “continue X” syntax unique for PHP, or was it also in C and/or other languages? [closed]

Today, I finally learned that it’s possible to do “continue 2;” to “continue” an inner loop. I never knew about this syntax in 20+ years of using PHP. I could have used this in so many cases…

Now I wonder:

  1. Was this a thing right away, or added “late in the game” for PHP?
  2. Did this also exist in C/other languages, or was it an enhancement in PHP?

I tried to find this out on my own prior to asking.