8 – Issue after submitting or saving node

8 – Issue after submitting or saving node – Drupal Answers

javascript – Submitting a form making POST request

javascript – Submitting a form making POST request – Code Review Stack Exchange

composer – Magento2 – Getting error Could not find a matching version of package After submitting in packagist.org

I have Created New Module and uploaded in github.

Module Name : vrajeshpatel4u/helloworld

Url : https://github.com/vrajeshpatel4u/helloworld/

Packagist Url : https://packagist.org/packages/vrajeshpatel4u/helloworld

Below command I have tried still getting error : Could not find a matching version of package vrajeshpatel4u/helloworld. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stable).

git add .
git commit -m 'initial commit'
git push origin master
git tag 1.0.0
git push origin --tags

Here is the composer.json

{
    "name": "vrajeshpatel4u/helloworld",
    "description": "Simple Hello World Module for Magento 2",
    "type": "magento2-module",
    "version": "1.0.0",
    "license": (
        "OSL-3.0",
        "AFL-3.0"
    ),
    "authors": (
        {
            "name": "Vrajesh Patel"
        }
    ),
    "minimum-stability": "dev",
    "require": {
        "php": "~7.1.3||~7.2.0||~7.3.0"
    },
    "autoload": {
        "files": (
            "registration.php"
        ),
        "psr-4": {
            "V4U\Helloworld\": ""
        }
    }
}

For installing Modules I have tried below commands :

composer require vrajeshpatel4u/helloworld

composer require vrajeshpatel4u/helloworld:dev-main

Any one help me to fix the issue?

Thank you.

400 Bad Request when submitting form through admin-ajax with vanilla javascript (but not jQuery)

I’m getting a 400 Bad Request when submitting a form through admin-ajax with vanilla javascript (but not with jQuery).

My HTML form:

<form class="form" id="sign_in" action="" method="post" name="sign_in">
    <label for="sign_in_username">username</label>
    <input type="text" id="sign_in_username" name="sign_in_username">

    <label for="sign_in_password">password</label>
    <input type="password" id="sign_in_password" name="sign_in_password" >

    <input type="submit" onclick="signIn()" name="sign_in_submit" value="sign in">
</form>

In functions.php:

function sign_in_script() {
    wp_enqueue_script( 'sign-in-script', get_template_directory_uri() . '/js/sign-in.js', ('jquery'));

    $php_to_js = (
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce' => wp_create_nonce('sign-in-nonce')
    );

    wp_localize_script('sign-in-script', 'scriptData', $php_to_js);

}
add_action( 'wp_enqueue_scripts', 'sign_in_script' );
add_action('wp_ajax_ajax_sign_in', 'sign_in' );
add_action('wp_ajax_nopriv_ajax_sign_in', 'sign_in' );

function sign_in() {

    if (!isset($_POST('nonce')) || !wp_verify_nonce($_POST('nonce'), 'sign-in-nonce')) {
    wp_die(-1);
}

    $username = $_POST('username');
    $password = $_POST('password');

    echo 'You sent ' . $username . ' with ' . $password;

    wp_die();
}

The following jQuery script gives a successful request:

jQuery(document).ready(function($) {

    var data = {
        'action': 'ajax_sign_in',
        'username': 'username',
        'password': 'password',
        'nonce' : scriptData.nonce
    }

    console.log(data);

    $.post(scriptData.ajax_url, data, function(response) {
        console.log(response);
    });
});

But my attempt with vanilla JavaScript gives a 400 Bad Request:

function signIn () {

    event.preventDefault();

    const username = document.getElementById("sign_in_username").value;
    const password = document.getElementById("sign_in_password").value;

    const payload = {
        'action': 'ajax_sign_in',
        'username': username,
        'password': password,
        'nonce' : scriptData.nonce
    };

    const payloadJSON = JSON.stringify(payload);

    const xhttp = new XMLHttpRequest();

    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        alert(this.responseText);
      }
    };

    xhttp.open( "POST", scriptData.ajax_url, true );
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
    xhttp.send(payloadJSON);
}

I’m obviously not getting the vanilla JavaScript right. Can someone help?

Skipping form inputs and submitting recapthca generates some sort of string

My company’s contact us webpage has a bug where if you skip over the from and submit the recapthca, a string appears out of no where. I can’t figure out what it is and why it is happening.
enter image description here

civicrm – Why do I get a 403 response code when submitting changes at /admin/people/permissions?

I have documented the warnings and notices I get
in the drupal watchdog logs at this link:

https://gist.github.com/hesco/1797208819f7b239d8be9deca6b8bac4

I see nothing in apache2 error logs.

I see a WSOD with the message: Not allowed. in the browser.
I see the 403 code in the browser inspect tool’s js concole.
I also see that 403 in the apache2 access logs for every:
POST /admin/people/permissions

submitting the change for a specific user does not change the outcome.

Any thoughts on how I might debug this and resolve it would be appreciated.

Thanks,
— Hugh

javascript – Prevent webform from submitting when clicking button in markup component

I have a very complex webform in a Drupal 7 website I’ve inherited. I have added a markup component which builds a button and added some JS that links this button to trigger a modal window to open. In the modal a block is displayed which contains a view listing some user profiles.

When I visit the webform everything functions normally and I can click the button to open the modal, but when revisiting a draft submission the button triggers the webform to be submitted. I have been looking around for answers and trying lots of different things but nothing seems to be able to stop the button submitting the form. If I change the markup to use a different tag such as a span tag then it doesn’t submit. The markup is exactly the same inside the two forms (initial submission and draft edit) but the behavior is different!

So the question is, does anyone know a way to prevent buttons in markup components from submitting the form they are inside?

The form is absolutely massive so I don’t think it’s useful to post the markup of the whole thing here, but the button looks like this:

<button id="ref-1-modal-trigger" class="ref-modal-trigger button--gold" data-ref-number="1">Button Name</button>

And the JS looks like this:

// Get the button that opens the modal
        var btnRef1 = document.getElementById("ref-1-modal-trigger");
// When the user clicks on the button, open the modal
        btnRef1.onclick = function() {
            refNumber = btnRef1.getAttribute("data-ref-number");
            modalRef1.style.display = "block";
            modalRef1.setAttribute('data-ref-number', refNumber);
        }

The basics of the project:

Thanks in advance!

game – Submitting highscore in PHP

So, I am interested, what is the proper way to submit a highsocre (such as of a Pacman game) in PHP? Here is what I tried:

<?php
if (array_key_exists("HTTP_USER_AGENT", $_SERVER)) {
    $browser = $_SERVER('HTTP_USER_AGENT');
} else {
    $browser = "none";
}
if (substr($browser, 0, strlen("Opera")) !== "Opera" &&
        substr($browser, 0, strlen("Mozilla/5.0")) !== "Mozilla/5.0") {
    exit("Please access this URL with a proper browser! As far as I know, no browser in which you can actually play that PacMan has User Agent that does not start either with "Opera" or with "Mozilla/5.0".n");
}
if (!array_key_exists('HTTP_REFERER', $_SERVER) || $_SERVER('HTTP_REFERER') != "https://svg-pacman.sourceforge.io/") {
    exit("Your browser did not set the HTTP referer header to the URL of the PacMan game, so we cannot save your highscore. Sorry about that!n");
}
session_start();
if (!array_key_exists('first_random_number', $_SESSION) || !array_key_exists('second_random_number', $_SESSION) || !array_key_exists('sumOfRandomNumbers', $_GET) || $_GET('sumOfRandomNumbers') != $_SESSION('first_random_number') + $_SESSION('second_random_number')) {
    session_destroy();
    exit("The session does not seem to be properly set! It can be both a server error or a misconfiguration of your browser. " .
            (
            (array_key_exists('first_random_number', $_SESSION) && array_key_exists('second_random_number', $_SESSION) && array_key_exists('sumOfRandomNumbers', $_GET)) ?
                    "The random numbers sent to JavaScript in "<code>pacman.php</code>" were"
                    . $_SESSION('first_random_number') . " and "
                    . $_SESSION('second_random_number') .
                    ", and your browser claims the sum of them is " . $_GET('sumOfRandomNumbers') . ". " :
                    "") .
            "Unfortunately, we cannot set the new highscore!");
}
session_destroy();
?>
<html>
    <head>
        <title>Saving the highscore for PacMan in JavaScript</title>
    </head>
    <body>
        Attempting to save a highscore...<br>
<?php
$player = $_GET('player');
if (strpos($player, " ") !== FALSE || strpos($player, "<") !== FALSE || strpos($player, ">") !== FALSE || strpos($player, "&") !== FALSE || strlen($player) == 0 || strlen($player) > 12)
    $player = "anonymous";
$score = intval($_GET('score'));
$datoteka = fopen("pachigh.txt", "r");
$current_highscore = intval(fgets($datoteka));
fclose($datoteka);
if ($score <= $current_highscore) {
    ?>Sorry about that, but higher highscore has already been submitted!<?php
        } else {
            $hash1 = $_GET('hash');
            if (is_numeric($score) && $score < 100000) {
                $hash = 7;
                for ($i = 0; $i < $score / 127; $i++) {
                    $hash += $i;
                    $hash %= 907;
                }
                if ($hash - $hash1) {
                    ?>Invalid hash!<?php
                } else {
                    $datoteka = fopen("pachigh.txt", "w");
                    if ($datoteka === FALSE) {
                        ?>Server error: cannot open the &quot;<code>pachigh.txt</code>&quot; file for writing!<?php
                    } else {
                        fprintf($datoteka, "%dn%sn", $score, $player);
                        fclose($datoteka);
                        ?>
                        Successfully saved the new highscore!
                        <script type="text/javascript">
                            window.close();
                        </script>
                <?php
            }
        }
    } else {
        ?>
                Server error!
                <?php
            }
        }
        ?>
    </body>
</html>

CSRF token is not varying in Ajax callback while submitting form

I have a form with ajax callback as following , on each submit token is not varying , it remains constant for all submit .

wall.routing.yml

wall.commentform:
  path: '/commentform'
  defaults:
    _title: 'Comment form'
    _form: 'DrupalwallFormWallCommentPost'
  requirements:
    _permission: 'access content'
    _csrf_token: 'TRUE'

In from as following

WallCommentPost.php

$ajax = (
  'callback' => ($this, '_wall_comment_ajax_form_post'),
  'wrapper' => 'field-type-replace-comment',
  'event' => 'click',
  'progress' => array(
    'type' => 'throbber',
    'message' => '',
  )
);

$form('wall_submit') = (
  '#type' => 'submit',
  '#value' => 'Submit',
  '#ajax' => $ajax,
  '#prefix' => '<div class="col-12 p-1 d-flex justify-content-between"><div class="file_name_insert file_name_insert_data-' . $nid . ' pl-4 text-truncate"></div>',
  '#suffix' => '</div>',
  '#attributes' => array(
    'class' => array(
      'btn',
      $ajax_class,
      'd-none',
      'subbtn-' . $nid
    ),
    'disabled' => 'disabled'
  ),
);
$url = Url::fromRoute('wall.commentform');
#$token = Drupal::csrfToken()->get($url->getInternalPath());

$form('#action') = Url::fromRoute('wall.commentform')->setOption('query', (FormBuilderInterface::AJAX_FORM_REQUEST => 1, 'token1' => $token))->toString();

google search console – Page is loading fine but still GSC showing 5xx issue when submitting from URL Inspection

Google Search Console is showing a 5xx error when I check some URLs of my website. Pages are working properly and still, GSC is not accepting it.

I have checked Robots.txt of the website as well checked meta robots. Nothing is blocking. I am attaching a screenshot here: https://prnt.sc/13i9uci

If anyone has an idea regarding this, please let me know how to resolve it. That would be a great help.

DreamProxies - Cheapest USA Elite Private Proxies 100 Cheap USA Private Proxies Buy 200 Cheap USA Private Proxies 400 Best Private Proxies Cheap 1000 USA Private Proxies 2000 USA Private Proxies 5000 Cheap USA Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive.com Proxies-free.com New Proxy Lists Every Day Proxies123.com Best Quality USA Private Proxies