Here is an explanation of my question.
I have 2 forms:
add & add1
2 pages:
add.php & add1.php
and 2 functions:
function post_add & function post_add1
when the user has fill and submit the form add, function post_add automatically redirect to user to add1.
I want to pass value (after the user fill it and submit it) from form add
"echo Form::text('name', Input::get('name'));"
to form add1, because you need to type the same thing on next form.
Thanks in advance!
Just use Session::flash();
Like so...
function post_add(){
//blah blah your code.
$passvalues = Input::all();
Session::flash('values', $passvalues);
Redirect::to('/add1');
}
function post_add1(){
//Now you have access to that input...
$oldinput = Session::get('values');
//do whatever you need to with the old/passed input
}
Or you could just do a with()....
function post_add(){
//blah blah your code.
$passvalues = Input::all();
Redirect::to('/add1')->with('values', $passvalues);
}
Related
How to get a user password form in Preprocess like user login
$form = Drupal::formBuilder()->getForm(Drupal\user\Form\UserLoginForm::class);
$variables['login_form'] = $render->renderPlain($form);
thanks in advance.
You need to add your own function before from submit function to get form data
$form = Drupal::formBuilder()->getForm(Drupal\user\Form\UserLoginForm::class);
// Add your own function before form submit here
$variables['login_form'] = $render->renderPlain($form);
I currently have a form in laravel on whos submission the following methods run:
public function validateSave() {
$qualitycheck = new QualityCheck();
$qualitycheck['site-name'] = Request::input('site-name');
$qualitycheck['favicon'] = Request::has('favicon');
$qualitycheck['title'] = Request::has('title');
$qualitycheck['image-optimization'] = Request::has('image-optimization');
$qualitycheck->save();
Session::flash('quality-data', $qualitycheck);
return redirect('/');
}
So i have the below line that passes the data to the next page:
Session::flash('quality-data', $qualitycheck);
But what i would really want to do is, when the form is submitted, i would really just want to show a link on the next page , which will be coded like so:
#if(Session::has('quality-data'))
Submited Quality Check
#endif
Now on click on the link , i would like to show a view with all the data that the user submitted in the form , How do i do this ? I.E. How do i pass the data form from the <a> to the view that will show up when clicked on the <a> ??
So just to put things into perspective, this is how it works now:
STEP-1 :: User submits form , data is flashed to next page.
STEP-2 :: Data user submits is shown on this page.
How i want it to work is:
STEP-1 :: User submits form , data is flashed to next page.
STEP-2 :: A link is shown to the user(Only if user clicks on the link we move to the next step).
STEP-3 :: Data user submited in first step is shown on this page.
Next time you code, please follow the below coding practices.
Prefer using create() function of model.
Put all your request data that is to be used in one variable (like $input)
Prefer using route names like route('route.name') instead of strings inside redirection() function.
Please replace your function with
public function validateSave() {
$inputs = [
'site-name' => request()->get('site_name'),
'favicon' => request()->has('facvicon'),
'title' => request()->has('title'),
'image-optimization' => request()->has('image-optimization')
]);
$qualityCheck = QualityCheck::create($inputs);
$flashMessage = '<a href=' . route('quality.check.show', $qualityCheck) . '>Submitted Quality Check</a>'
Session::flash('quality-data', $flashMessage);
return redirect(route('home.index'));
}
And ensure you have something like this in your routes file.
Route::get('quality-check/{id}', 'QualityCheckController')->name('quality.check.show');
Let me know if something doesn't work...
try this one.
<a href="{{url('routename')}}">
I have form data posted by client, I want to manipulate one of the forms value before I run it through $this->form_validation->run().
Is this possible
i.e something like;
//Get user form inputs
$input = $this->input->post();
//generate slug - my custom code
$input['slug'] = sf_generate_slug($input['slug']);
if ($this->form_validation->run()) {
...
You can reassign any post value before $this->form_validation->run() like
$_POST['slug'] = sf_generate_slug($_POST['slug']);
While if you use your above method it will validate because it didn't overrides the $_POST values
Hope it makes sense
I have two forms with two submit buttons in one page, one view and one controller should manage them. I want it to perform one action if the first one is clicked, and another action - if the second. I tried this where edit is the name of the form but it doesn't work:
if($this->getRequest()->get('edit'))
I also tried setting value to the submit buttons but I could't make it go, too. Please help me to find a way how to identify which button was pressed. :)
Symfony 2.3 comes with the solution. It supports buttons in forms, and you have isClicked() method to check if a button was clicked.
http://symfony.com/blog/new-in-symfony-2-3-buttons-support-in-forms
Give buttons different "name" (not "id") attributes
<form ...>
...
<input type="submit" name="btnA" value="ActionA">
<input type="submit" name="btnB" value="ActionB">
</form>
Then the controller should analyze the POST data for a variable whose name will be the name of the clicked button:
if (isset($_POST['btnA'])) {
/* do A */
} else if (isset($_POST['btnB'])) {
/* do B */
}
You can use hidden fields and check their values :)
Inside your controller create two forms, handle their input and then check if they are submitted and valid.
$formOne = $this->formFactory->create();
$formTwo = $this->formFactory->create();
$formOne->handleRequest($request);
$formTwo->handleRequest($request);
if($formOne->isSubmitted() && $formOne->isValid()) {
die('form one submitted');
}
if($formTwo->isSubmitted() && $formTwo->isValid()) {
die('form two submitted');
}
return new Response($this->templating->render([template-name]), [
'formOne' => $formOne->createView(),
'formTwo' => $formTwo->createView(),
]));
Then inside your template create two forms with separate buttons:
form_start(formOne)
form_rest(formOne)
<button type="submit">one</button>
form_end(formOne)
form_start(formOne)
form_rest(formOne)
<button type="submit">one</button>
form_end(formOne)
Im using Drupal 6.19 and the webform module on my site.On a particular form,i want to do some additional processing with the values entered,so i created a module and implemented hook_form_alter, and added my own function called mymodule_webform_submit to the list of submit event handlers.
Suppose i have two fields in the form having field key values name and address respectively. How to print the values of those fields in mymodule_webform_submit function ?. Some example would be really appreciated. Below is my code so far.
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'webform_client_form_8') {
$form['#submit'][] = 'mymodule_webform_submit';
}
}
function mymodule_webform_submit(&$form,&$form_state) {
drupal_set_message($form_state['values']['name']);
}
?>
Please help
Thank You
You're missing the arguments to your submit function. Once those are added, your values should be in $form_state['values']. It should be something like:
function mymodule_webform_submit($form, &$form_state) {
print $form_state['values']['name'];
print $form_state['values']['address'];
}
But do whatever you want with the values in there. Just make sure you have the correct element keys. You could see what's available by putting var_export($form_state['values']); exit(); inside the function and submitting the form.