I made a plugin which allows frontend users to write news articles. This works fine on the Mac locally. However the New action gives a wrong casing in the __referrer of the form, resulting on the Linux server (which is sensitive for casing) in:
Class Pen\Pennews\Controller\newsController does not exist. Reflection failed.
My controller
class NewsController extends NewsBaseController
...
/**
* New action
*
* #return void
*/
public function newAction()
{
$feUserUid = $GLOBALS['TSFE']->fe_user->user['uid'];
/** #var User $user */
$user = $this->frontendUserRepository->findByUid($feUserUid);
$this->view->assignMultiple([
'user' => $user
]);
}
The form
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:section name="content">
<f:form action="create" name="newNews" controller="News" object="{newNews}">
<label for="pennews-title" class="pennews-title">Titel</label>
<f:form.textfield property="title" id="pennews-title" placeholder="Onderwep" required="required"/>
<label for="pennews-teaser" class="pennews-teaser">Teaser</label>
<f:form.textarea id="pennews-teaser" class="pennews-teaser-newPost" name="teaser" rows="3" placeholder="Korte teaser - optioneel"/>
<label for="pennews-bodytext" class="pennews-bodytext">Content</label>
<f:form.textarea id="pennews-bodytext" class="pennews-bodytext-newPost pen-form-textarea" name="bodytext" placeholder="Bericht"/>
<div class="pen-button pennews-new-button text-align-right">
<button class="button pennews-submit-news icon-left" type="submit"><i class="fas fa-pen-square"></i>Maak nieuw bericht</button>
</div>
</f:form>
</f:section>
</html>
Part of the source of the form (taken from local dev) :
<form name="newNews"
action="/vlaggensite?tx_pennews_entry%5Baction%5D=create&tx_pennews_entry%5Bcontroller%5D=News&cHash=4cc2809be1ea9f2f2d3e07a8e396981f"
method="post">
<div>
<input type="hidden" name="tx_pennews_entry[__referrer][#extension]" value="Pennews"/>
<input type="hidden" name="tx_pennews_entry[__referrer][#vendor]" value="Pen"/>
<input type="hidden" name="tx_pennews_entry[__referrer][#controller]" value="news"/>
<input type="hidden" name="tx_pennews_entry[__referrer][#action]" value="new"/>
<input type="hidden" name="tx_pennews_entry[__referrer][arguments]"
value="YTowOnt9dd9a70668d7db0e58fe5097a80fa26ab79028541"/>
<input type="hidden" name="tx_pennews_entry[__referrer][#request]"
value="a:4:{s:10:"#extension";s:7:"Pennews";s:11:"#controller";s:4:"news";s:7:"#action";s:3:"new";s:7:"#vendor";s:3:"Pen";}316417f03bf11f3d860053d7f0c1286795c3db22"/>
<input type="hidden" name="tx_pennews_entry[__trustedProperties]"
value="a:3:{s:7:"newNews";a:1:{s:5:"title";i:1;}s:6:"teaser";i:1;s:8:"bodytext";i:1;}b6e10b48e7d3acab8926ba3318ce3ce1fed6ea2d"/>
</div>
As can be visible in the action, the controller is there News with a capital. However in the refererer the controller has the value "news" - lowercase. What could cause this or how can I fix it with a capital as first letter?
Solved. On ext_localconf.php I had the controllername lowercase.
Related
UPDATE: per this response this is behavior of HTML5? I tried setting the parameters in hidden inputs and that works. Doesn't make much sense to me, but what do I know.
I have my form for a "next page" button set up like this:
<form id="next" method="get"
asp-controller="Search"
asp-action="Cities"
asp-route-sortOrder="#ViewData["CurrentSort"]"
asp-route-currentFilter="#ViewData["CurrentFilter"]"
asp-route-pageNumber="#(Model.PageIndex + 1)">
<input form="next" type="submit" class="page-btn" disabled="#nextDisabled" value="Next" />
</form>
When I inspect the page, the form has the correct action url (example):
/Search/Cities?currentFilter=Test&pageNumber=2
But the request actually being made is to
/Search/Cities?
But when it hits the controller, all of the parameters are null. Here is the top of my controller:
[Route("Search/Cities")]
public ActionResult Cities(string SearchString, string sortOrder, string currentFilter, int? pageNumber)
I'm not sure what I'm missing here.
you have 3 choices. This code was tested
first the most popular, you have to use post
<form id="next" method="post"
asp-controller="home"
asp-action="test"
asp-route-sortOrder="CurrentSort"
asp-route-currentFilter="CurrentFilter"
asp-route-pageNumber="1">
<label for="searchString">Search</label>
<input type="text" id="searchString" name="searchString"><br><br>
<input form="next" type="submit" class="page-btn" value="Next" />
</form>
in this case searchingString will be sent in a request body, all another params in a query string
second
<a href="/Home/Test?sortOrder=CurrentSort¤tFilter=CurrentFilter&pageNumber=2">
<button class="page-btn">Next</button>
</a>
the second option will generate get request if it is so important for you, but you will not be able post search string except using ajax.
third, you can use get, but route params should be in the inputs, probably hidden, search string will have a visible input
<form id="next" method="get"
asp-controller="home"
asp-action="test">
<input type="hidden" id="sortOrder" name="sortOrder" value="CurrentSort" />
<input type="hidden" id="currentFilter" name="currentFilter" value="CurrentFilter" />
<input type="hidden" id="pageNumber" name="pageNumber" value="23" />
<label for="searchString">Search</label>
<input type="text" id="searchString" name="searchString"><br><br>
<input form="next" type="submit" class="page-btn" value="Next" />
</form>
in this case nothing will be inside of the body, everything in a query string including searchString.
On a Typo3 website a form is integrated. The action should be routed to a typoscript user function.
This is what I tried so far:
The fluid form code (excerpt):
<form action="{f:cObject(typoscriptObjectPath: 'lib.mynlreg')}" method="post">
<input type="text" name="email" placeholder="Ihre E-Mail-Adresse">
<input type="submit" name="send" value="Jetzt registrieren" class="submit" />
</form>
The typoscript lib:
lib.mynlreg = USER_INT
lib.mynlreg {
userFunc = Vendor\Extension\myClass->myFunction
}
And the class:
class myClass {
public function myFunction($content, $conf) {
$arguments = $this->request->getArguments();
$formEmail = $arguments['email'];
return '<div>' . $formEmail . '</div>';
}
}
I expect to get the content of the form field "email", but after submitting the page throws an error. The question is, how do I get the post vars into the user function? Thank you for any help!
$this->request is not available in a userFunc. As gautamsinh mori says, you should use \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('email');, however I'm not sure you understand what the f:cObject ViewHelper does.
With this code, your HTML before submitting the form will be:
<form action="<div></div>" method="post">
<input type="text" name="email" placeholder="Ihre E-Mail-Adresse">
<input type="submit" name="send" value="Jetzt registrieren" class="submit" />
</form>
Your HTML after submitting will be:
<form action="<div>filledInEmail</div>" method="post">
<input type="text" name="email" placeholder="Ihre E-Mail-Adresse">
<input type="submit" name="send" value="Jetzt registrieren" class="submit" />
</form>
I'd recommend making an extension for this, but if you really want/need to do it like this, I think what you're looking for is something like:
<f:cObject typoscriptObjectPath="lib.mynlreg" />
<form action="{uri.page(addQueryString: 1)}" method="post">
<input type="text" name="email" placeholder="Ihre E-Mail-Adresse">
<input type="submit" name="send" value="Jetzt registrieren" class="submit" />
</form>
This will create the form with action to the current page (including any query string). You then have to change the userFunc to return an empty string if the form hasn't been submitted. Something like:
class myClass {
public function myFunction($content, $conf) {
$formEmail = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('email');
if (empty($formEmail)) {
return '';
}
return '<div>' . $formEmail . '</div>';
}
}
laravel 5.5
voyager 1.0
i'm trying to submit a form to a controller with :
<form class="" action="FeedController#store" method="post">
<div class="mui-textfield mui-textfield--float-label">
<input id="title" type="text" name="title" value="" required autofocus>
<label for="title" class="col-md-4 control-label">title</label>
</div>
<div class="mui-textfield mui-textfield--float-label">
<textarea id="description" type="textarea" name="description" value="" required autofocus></textarea>
<label for="description" class="col-md-4 control-label">description</label>
</div>
<input class="mui-btn btn-primary pull-right " type="submit" name="" value="submit">
</form>
within FeedController:
/**
*#param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request){
$data = ReportDatum::create([
'owner_id' => auth()->id(),
'title' => request('title'),
'description' => request('description')
]);
return test;
}
and in the routes:
Route::resource('feed', 'FeedController');
(and/or depending on what I'm trying)
Route::post('store', 'FeedController#store');
what I'm i missing to correctly submit the form?
I'm not using laravelCollective forms
You're missing the csrf_field(). Try adding it after the <form> tag.
Ref: https://laravel.com/docs/5.5/csrf
You should define route at first then it will works:
Resource controller routing
Route::resource('feed', 'FeedController');
or specific simple routing
Route::post('feed', 'FeedController#store');
Same error here. I've commented the line \Greazy\Http\Middleware\VerifyCsrfToken::class which stays in app/Http/Kernel.php and the post method worked in Postman, however it does not work when invoked on the form.
If I have a form that needs to use a textbox input like as below:
#{
if(IsPost){
username = Request.Form["username"]
}
}
<form action="Home/Index" method="post">
<input type="text" name="username" />
<input type="submit" value="submit" />
</form>
The controller is something like below,
public class HomeController : Controller
{
public ActionResult Index (string username) {
if (string username != string.Empty)
{
Console.WriteLine("Your username is " + username);
}
return View();
}
}
Seems like the data is not being passed from the post method. When I hit submit the URL that it requests is Home/Home/Index, which is not were the controller(HomeController) action is located, it should be Home/Index, and use the HomeController right?
What if I need to pass this data to a different controller that has an Index for the action, like UserController?
In this instance, you're missing a slash!
<form action="/Home/Index" method="post">
<input type="text" name="username" />
<input type="submit" value="submit" />
</form>
But when using asp.net mvc, you should use Url.Content with the home directory character to ensure that if your site is deployed in a sub-directory of the site, the correct root will be found. So use:
<form action="#Url.Content("~/Home/Index")" method="post">
<input type="text" name="username" />
<input type="submit" value="submit" />
</form>
I'm trying to insert a variable collected from a form into a URL, but I don't want the "?variable=value" part of the URL.
<form action="http://www.example.com/<?php echo htmlspecialchars($_GET['entry']);?>/" method="GET">
<input type="text" value="" name="entry" id="entry">
<input type='submit'>
</form>
Is there any easy way to do this? I want the browser to go to the following URL when the user types "whatever"
http://www.example.com/whatever/
Edit:
I've changed the code to the following, which seems to work, but have I now introduced a script vulnerability?
<form onSubmit=" location.href = 'https://www.example.com/' + document.getElementById('entry').value + '/' ; return false; ">
<input type="text" value="" name="entry" id="entry" placeholder="Your Promo Code">
<input name="promoSubmit" type="submit" value="Buy Now">
</form>
you could use javascript for this kind of tasks, i don't see why would you involve server side for such thing
but the easiest answer will be like:
<script>
function go(){
window.location='http://www.example.com/'+document.getElementById('url').value;
}
</script>
<input type='text' id='url'>
<button id='btn_go' onclick='javascript:go();'>Go</button>