Closed Mr-TOA closed 4 years ago
You have not declared $barcode_type in the php above, and you do not need to do $generator::$barcode_type when you have already declared $generator to be the generator type you want. Remove the ::$barcode_type part from the second line
Hi Joey, you are right but I want to select the barcode type from select option HTML tag and return the value just like above, is there anyway that I can do that ? thanks :)
Are you able to post more of the code? You could do an if statement for each select value and have it instantiate a different generator?
not more posts of the code just one at a time but through a variable; e.g.
<?php
if(isset($_POST['barcode_type'])){
$barcode_type = $_POST['barcode_type'];
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
$generated = $generator->getBarcode('1234567890', $generator::$barcode_type);
}
?>
It is probably not supported by PHP, the thing you try. Or the string you have in $barcode_type
is not an exact match for one of the values used as static variables in the class.
What did you gave as an option in $barcode_type
?
This should work:
<select name="barcode_type">
<option>C39</option>
<option>C39+</option>
<option>C39E</option>
<option>C39E+</option>
<option>C93</option>
<option>S25</option>
<option>S25+</option>
<option>I25</option>
<option>I25+</option>
<option>C128</option>
<option>C128A</option>
<option>C128B</option>
<option>C128C</option>
<option>EAN2</option>
<option>EAN5</option>
<option>EAN8</option>
<option>EAN13</option>
<option>UPCA</option>
<option>UPCE</option>
<option>MSI</option>
<option>MSI+</option>
<option>POSTNET</option>
<option>PLANET</option>
<option>RMS4CC</option>
<option>KIX</option>
<option>IMB</option>
<option>CODABAR</option>
<option>CODE11</option>
<option>PHARMA</option>
<option>PHARMA2T</option>
</select>
Note to use the string values from BarcodeGenerator.php, not the const variable names.
<?php
if(isset($_POST['barcode_type'])){
$barcode_type = $_POST['barcode_type'];
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
$generated = $generator->getBarcode('1234567890', $barcode_type);
}
?>
Note to just use $barcode_type
in the last line.
Thanks @slokhorst, that is indeed a way it should just work. This is not something related to this package itself, so I will close it now.
Hello there, I'm trying to use variable instead of const, but gives me some errors
error:
thanks