how to use the form(checkbox) to pass the user id - php

I have a table in it there are checkboxes I need that on those users
on which the checkbox is selected their id was transferred
my form
<input type="submit" form="qwe">
<form action="{{URL::to('othet_nn')}}" method="get" id="qwe">
<input type="checkbox" name="id">
</form>
my controller
public function chek(){
dd($_GET);
return view('admin.pages.othet_test');
}
I need to be passed the id of those users who had a check mark in the
checkbox

you can use this like
<form action="{{URL::to('othet_nn')}}" method="post" id="qwe">
<input type="checkbox" name="id" value="1">
</form>
public function check(Request $request){
dd($request->id);
return view('admin.pages.othet_test');
}

In Laravel you should use Request class. To see the whole input you can use:
request()->all()
and to get individual field you can use
request()->input('id')
I advise you to read documentation about requests

Related

how to send multiple sets of data input with request HTTP in Laravel?

Im trying to make a form with Laravel that send two sets of data.
my form is like this.
<form>
<fieldset method="POST" action"some url">
<label for="nameField">Name</label>
<input type="text" id="nameField" name="nameField">
<label for="phoneField">Name</label>
<input type="text" id="phoneField" name="phoneField">
<input class="button-primary" type="submit" value="Send">
</fieldset>
</form>
the first in put nameField will save to the table "names".
the phoneField will save to another table "phones".
Ok! the problem is I want to let user make as many phoneField as they want (with Javascript of course).
so i think the best way is i save nameField like this:
Name::create([ "name" => request("nameField")]);
but how about phoneField? how to save them? users can make about 10 field or more. is there any way to group the phoneFields as any array and send the array with request HTTP?
You can send group of phoneField. Use array for phoneField
<label for="phoneField">Name</label>
<input type="text" id="phoneField" name="phoneField[]">
And in your controller
$data = $request->all();
$phoneFields = $data['phoneField'];
foreach($phoneFields as $phoneField)
{
//implement to save phone number...
}

Is it possible to control which form a submit button calls?

so I'm working on a site, I currently have:
<form method =post action=process.php>
<form method = get action = process3.php>
<input type=submit value = add name = action/>
</form>
</form>
is it possible to add a attribute to control which form this input calls?
For reasons un-mentioned above I am unable to simply use just one method
You cannot nest forms like you do. You can submit forms from outside.
<form id="myform1" name="form1" action="" method="post">
<input name="field1" value="form1" />
</form>
<form id="myform2" name="form2" action="" method="post">
<input name="field2" value="form2" />
</form>
<input type="submit" form='myform1' value="submit1" />
<input type="submit" form='myform2' value="submit2" />
You can also add input fields outside the form tag
add input to form 2:
<input type="text" name='outside' value="outside" form='myform2' />
No. Forms can't be nested like this. That is invalid HTML. Moreso, its impossible to GET and POST data at the same time.
The submit action is strongly tied to its parent form, so I'd recommend writing your forms as siblings, then putting the field in the appropriate one and giving each form its own submit input.
<form method =post action=process.php>
<input type=submit value = add name = differentAction/>
</form>
<form method = get action = process3.php>
<input type=submit value = add name = action/>
</form>
Unless you are using way more sophisticated methods for controlling your forms the best way is to keep your submit action within the corresponding <form> </form> tag.
This might prove to be helpful depending on what you are trying to accomplish:
Submit multiple forms with one submit button
and this:
http://jquery.malsup.com/form/#getting-started

passing value in hidden field from one page to another in php

I have a simple registration form.
I want to pass value entered in one page to other in a text field.
how to pass and access it from next page in php.
this is my first php page.
Thanks in advance.
You can add hidden fields within HTML and access them in PHP:
<input type="hidden" name="myFieldName" value="someValue"/>
Then in PHP:
$val = $_POST['myFieldName'];
If you're going to ouput this again you should use htmlspecialchars or something similar to prevent injection attacks.
<input type="hidden" name="myFieldName" value="<?=htmlspecialchars($_POST['myFieldName']);?>"/>
Suppose this the form input in page A
<form name="" action="" method=post enctype="multipart/form-data">
<input type="text" name="myvalue" value="">
<input type=submit>
</form>
In page B
In the page you want to get values put this code
<?PHP
foreach ($_REQUEST as $key => $value ) {
$$key=(stripslashes($value));
}
?>
<form name="" action="" method=post enctype="multipart/form-data">
<input type="text" name="myvalue" value="<?PHP echo $myvalue" ?>">
<input type=submit>
</form>
So yo can use or attach variable value to another form do what else you want to do
use following code, that should help you.
<form action ="formhandler.php" method ="POST" >
<input name = "inputfield" />
<input type="submit" />
</form>
on formhandler.php file yo need to enter following code to get the value of inputfiled.
$inputfield = isset($_POST['inputfield'])?$_POST['inputfield']:"";
// now you can do what ever you want with $inputfield value
echo($inputfield);

Query String in form does not work

I have the following form in my form.php file:
<form action="operation.php?part=dictionary&operation=<?php echo (($_GET['action']=='addword')?'save':'edit&id='.$_GET['id'])?>" method="get">
.....
....
</form>
And in my operation.php file:
if($_GET['operation']=='save'){
echo "This is true";
}else{
die(mysql_error());
}
And it shows the message that it does not recognize the operation parameter.
So if anyone have any idea of how to distinguish the operation between save and edit would be really appreciated. Thanks you
You can try using:
<form action="operation.php" method="get">
<input type="hidden" name="part" value="dictionary">
<input type="hidden" name="operation" value="<?php echo (($_GET['action']=='addword')?'save':'edit&id='.$_GET['id'])?>">
</form>
Setting a form's method to "GET" results in ignoring all GET-parameter added to the action of the form. In order to get those parameter to work you will have to add them as hidden input fields otherwise you switch your form's method to "POST". This results in setting POST-parameter according to form fields and setting GET-parameter according to the link additions made at form's action.
You need to use hidden parameters to submit values to your form, like so:
<form action="operation.php" method="GET">
<input type="hidden" name="part" value="dictionary" />
<input type="hidden" name="operation" value="<?php echo (($_GET['action']=='addword')?'save':'edit&id='.$_GET['id'])?>" />
</form>

send the form value into the form action parameter

Can i send a input value into form action ?Let say, on the form the phone number taken.Now can i send the phone number as form action parameter "number"? Is their any way to send it?
<form method="post" action="abc.php?number=ph_number" enctype="multipart/form-data">
<input type="text" name="ph_number" value=""/>
<input type="submit" name="search" value="SEND"/>
</form>
How can i do it?
Thanks in advance
riad
<form method="GET" action="abc.php" enctype="multipart/form-data">
<input type="text" name="number" value=""/>
<input type="submit" name="search" value="SEND"/>
</form>
Change action="abc.php?number=ph_number" to action="abc.php
Change name="ph_number" to name="number"
When you click submit, the value contained in "number" text field will be passed to abc.php.
Receive the value with $value = $_REQUEST['number']; in abc.php.
You can leave an empty action, and use the onSubmit event to load a javascript function that does whatever and redirects to the page according to the input value.
Html
<form .. action="" onsubmit="return abcByPhone(this);">
Javascript
function abcByPhone(form) {
url = from.number.value;
...
}
EDIT:
I actually didn't read the question properly. I thought you wanted to redirect to different pages according to the input. Using plain GET (like the others mentioned) is fine for this.

Categories