I have a checkbox:
<input class="switch" data-on-text="Si" data-off-text="No" id="isTeam0"
checked="checked" name="isTeam" type="checkbox" value="1">
When I try to make a functional test with:
$this->visit('/tournaments/' . $tournament->id . '/edit')
->type('1', 'isTeam0')
->press('save0');
I get this error message:
1) TournamentTest::it_create_tournament_category_conf
InvalidArgumentException: Unreachable field "isTeam0"
/home/vagrant/Code/vendor/symfony/dom-crawler/FormFieldRegistry.php:89
/home/vagrant/Code/vendor/symfony/dom-crawler/FormFieldRegistry.php:126
/home/vagrant/Code/vendor/symfony/dom-crawler/Form.php:77
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:711
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:691
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:678
/home/vagrant/Code/tests/functional/TournamentTest.php:187
I don't know what to do to make it work...
Any Idea???
Related
I created checkboxes in form using javascript:
<input type="checkbox" name="is_ok[]" />
<input type="checkbox" name="is_ok[]" />
<input type="checkbox" name="is_ok[]" />
When I check 1st and 3rd checkbox and submit the form, Input::get("is_ok") returns me:
['on', 'on']
Is there any way to get value as ['on', null, 'on'] or ['on', 'off', 'on']?
Thanks in advance.
Hey assign some values to checkboxes like user_id, product_id etc what ever in your application.
E.g. View
<input type="checkbox" name="is_ok[]" value="1" />
<input type="checkbox" name="is_ok[]" value="2" />
<input type="checkbox" name="is_ok[]" value="3" />
E.g. Controller
<?php
if(isset($_POST['is_ok'])){
if (is_array($_POST['is_ok'])) {
foreach($_POST['is_ok'] as $value){
echo $value;
}
} else {
$value = $_POST['is_ok'];
echo $value;
}
}
?>
You will get array of selected checkbox.
Hope it helps..
I think I have a "good" solution to this (kind of).
<input type="checkbox" name="is_ok[0]" />
<input type="checkbox" name="is_ok[1]" />
<input type="checkbox" name="is_ok[2]" />
(Forced indices here)
In the request:
$array = \Request::get("is_ok") + array_fill(0,3,0);
ksort($array);
This will ensure that (a) The checkbox indices are maintained as expected. (b) the gaps are filled when the request is received.
It's sloppy but may work.
IMHO this is the best practice:
In your migration set that db table field to boolean and default 0
$table->boolean->('is_ok')->default(0);
{!! Form::checkbox('is_ok[]', false, isset($model->checkbox) ? : 0) !!}
and if you are not using laravel collective for forms then you can use vanilla php
<input type="checkbox" name="is_ok[]" value="<?php isset($model->checkbox) ? : 0; ?>" />
My solution is this for laravel 5
$request->get('is_ok[]');
Though it might not be best practice, here is what I did first of all I send id of a specific model as a value.
<input type="checkbox" id="verify" name="is_varified[]" value="{{$bank->id}}" {{$bank->is_varified == 1 ? 'checked':''}}>
And in controller I added two query to update the field.
//handaling the issue of checkbox
Bank::where("user_id",$user->id)->whereIn('id',$request->is_varified)->update(['is_varified'=> 1]);
Bank::where("user_id",$user->id)->whereNotIn('id',$request->is_varified)->update(['is_varified'=> 0]);
i am using Virtual Merchant online payment.
i have one demo account :
https://demo.myvirtualmerchant.com/VirtualMerchantDemo/login.do
Account ID: 002549
User ID : 002549
Password : Abcd.1234gd
the submitting form code:
<form action="https://demo.myvirtualmerchant.com/VirtualMerchantDemo/process.do" method="POST">
<input type="hidden" name="ssl_amount" value="75.00">
<input type="hidden" name="ssl_merchant_id" value="002549">
<input type="hidden" name="ssl_user_id" value="002549">
<input type="hidden" name="ssl_pin" value="2R56WU">
<input type="hidden" name="ssl_transaction_type" value="ccsale">
<input type="hidden" name="ssl_show_form" value="true">
<input type="hidden" name="ssl_cvv2cvc2_indicator" value="1">
<input type="hidden" name="ssl_invoice_number" value="20131226">
<input type="hidden" name="ssl_customer_code" value="test demo">
<input type="hidden" name="ssl_email" value="demo#gmail.com">
<input type="submit" value="Pay Now" class="button1">
i got one test credit card number: 4005550000000019 from http://www.infomerchant.net/creditcardprocessing/credit_card_test_numbers.html
after submitting, the result is:
after clicking the process button, the result is :
the text is :
Error Code : 4000
Error Name : VID Not Supplied
Error Message : The VirtualMerchant ID was not supplied in the authorization request.
could you know how to fix it ? or any suggestion.
ssl_merchant_id: 002549
ssl_user_id: 002549
ssl_pin: 2R56WU (it is from demo account under menu: user=>change pin)
I encountered a similar issue. The culprit turned up on my end, before my form POSTed data to VirtualMerchant. Make sure the data/string(s) are properly encoded, without any stray white space.
I have looked at this post PHP, pass array through POST
but cannot quite get it working.
I have a form as below:
<applications><h2>Applications</h2><br><input type="checkbox" name="apps[]" value="gg">gg<br><br>
<input type="checkbox" name="apps[]" value="aa">aa<br><br>
<input type="checkbox" name="apps[]" value="bb">bb<br><br>
<input type="checkbox" name="apps[]" value="cc">cc<br><br>
<input type="checkbox" name="apps[]" value="dd">dd<br><br>
</applications>
<servers>
<h2>Servers</h2><br><input type="checkbox" name="serv[]" value="servera">servera<br><br>
<input type="checkbox" name="serv[]" value="serverb">serverb<br><br>
</servers>
<countries1><h2>Countries</h2><br><input type="checkbox" name="country" value="uk">UK<br><br>
<input type="checkbox" name="country[]" value="germany">Germany<br><br>
<input type="checkbox" name="country[]" value="france">France<br><br>
</countries1>
<countries2>
<input type="checkbox" name="country[]" value="spain">Spain<br><br>
<input type="checkbox" name="country[]" value="sweeden">Sweeden<br><br>
</countries2>
<submitb>
<?
session_start();
$_SESSION['country']=$country;
$_SESSION['serv']=$serv;
$_SESSION['apps']=$apps;?>
<input type="submit" value="Update">
</submitb>
</form>
Then on my retrieval end:
$apps=$_SESSION['apps'];
$countries=$_SESSION['country'];
$servers= $_SESSION['serv'];
EDIT:Please could someone advise me what I am doing wrong here? I am receiving:
Undefined index: apps in C:\wamp\www\notifcation system\done.php on line 41
<?php
$apps=$_SESSION['apps']; /* fix missing semicolon */
$countries=$_SESSION['country'];
$servers= $_SESSION['serv'];
?>
For your other issue:
Undefined index: apps in ...
Simply means that $apps is not defined. This is not an error, but a notice.
Try this
if(!isset($_SESSION['apps'])){
$apps=$_SESSION['apps'];
} // etc
Note that session_start(); should always be on the first line of the page, then you will start adding things later.
Also the session_start(); should be on every page you need acces to your session to.
as mentioned above by #subzero, never forget the all important ; semicolons as in PHP, these things can break your code.
I have a form that is displaying data that is pulled from a database. There are several columns that are being pulled for the form. The basic structure of the form looks like this:
<form>
<input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy # $editedDate
<input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy # $editedDate
<input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy # $editedDate
<input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy # $editedDate
<input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy # $editedDate
<input type="submit" name="update" value="Update Checklist" />
</form>
The variables are all populated dynamically when the pages loads from data in the database. Here is my question...each input and corresponding data is being pulled from a single row in a "checklist" table. So, in the example above you would be looking at data from 5 rows in the database. When i check off a box and click submit i want it to submit that checked box to the database as a value of true or false depending on whether or not the box is checked or unchecked. I know how to do all that if i was only submitting one row; however, i am not sure how to do this with the multiple rows. I'm assuming i'll have to use some type of loop with my UPDATE query.
What would be the best way to accomplish this? Thanks for any help! Let me know if you have any questions at all. Sorry if doesn't explain my situation well enough.
Check out this page, particularly the bits following "UPDATE ===".
Haven't tried it but apparently, you can use a CASE statement in an update query.
Should work for your case.
Sounds like a bad idea maintenance-wise though (imho)
i have a form that utilizes checkboxes.
<input type="checkbox" name="check[]" value="notsure"> Not Sure, Please help me determine <br />
<input type="checkbox" name="check[]" value="keyboard"> Keyboard <br />
<input type="checkbox" name="check[]" value="touchscreen"> Touch Screen Monitors <br />
<input type="checkbox" name="check[]" value="scales">Scales <br />
<input type="checkbox" name="check[]" value="wireless">Wireless Devices <br />
And here is the code that process this form in a external php file.
$addequip = implode(', ', $_POST['check']);
I keep getting this error below;
<b>Warning</b>: implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in <b>.../process.php</b> on line <b>53</b><br />
OK
is any of your checkboxes ticked? php’s $_POST array will only have checkboxes which have been ticked
to silence your warning use this:
$addequip = implode(', ', empty($_POST['check']) ? array() : $_POST['check'] );
the following site seems to be what you need:
http://www.ozzu.com/programming-forum/desperate-gettin-checkbox-values-post-php-t28756.html
Hi I m the original user who posted this question i couldnt login to my account so posting from another account. After couple hours of trying i somehow managed to make it work partially. Below is the modified form html and process code for checkboxes
<input type="checkbox" name="check" value="Touchscreen"> Touchscreen<br>
<input type="checkbox" name="check" value="Keyboard"> Keyboard<br>
<input type="checkbox" name="check" value="Scales"> Scales<br>
I had to remove the [] so it would work. Also below is the entire post method for those would like to see. It works perfectly fine with every other field.
<form id="contact_form" action="process.php" method="POST" onSubmit="return processForm()">
And below is the php code to process checkboxes. For some reason i have to tell script that $_POST['check'] is an array without it would only return array. All other methods suggested returns invalid argument passed error.
$chckbox = array($_POST['check']);
if(is_array($chckbox))
{
foreach($chckbox as $addequip) {
$chckbox .="$addequip\n";
}
}
So this code works but returns only 1 checkbox value that is ticked even no matter how many you ticked.