// Add an additional field to the checkout within a new fieldset
add_filter('eshopaddtocheckout','eshop_extras_checkout');
function eshop_extras_checkout($echo){
$echo .= ' <script>
jQuery(function($) {
$(".formGroup").hide();
$("#chooseForm input:checkbox").on("change", function() {
if($(this).is(":checked")) {
$("#" + $(this).val()).show();
}
else {
$("#" + $(this).val()).hide();
}
});
});
</script>';
$echo .= '<fieldset class="eshop eshop_extra">' . "\n";
$echo .= '<legend>Select the Approriate Form</legend>' . "\n";
$echo .= ' <div id="chooseForm">
<input type="checkbox" name="forms2[]" id="ArticlesOrderForm" value="ArticlesOrderForm"> <b>Articles Order Form </b><br>
<input type="checkbox" name="forms2[]" id="PressReleasesForm" value="PressReleasesForm"> <b> Press Releases Form </b><br>
</div>
<div id="ArticlesOrderForm" class="formGroup">
<legend>Articles Order Form</legend>
<label for="kwd1">Art-Keywords1</label><input class="short" type="text" name="kwd1" value="" id="kwd1" maxlength="20" size="20" > <br>
</div>
<div id="PressReleasesForm" class="formGroup">
<legend>Press Releases Form</legend>
<label for="kwd2">PRKeywords2</label><input class="short" type="text" name="kwd2" value="" id="kwd2" maxlength="20" size="20"> <br>
</div>';
$echo .= '<fieldset class="eshop eshop_extra">' . "\n";
$echo .= '<legend>Extras</legend>' . "\n";
$echo .= '<label for="eshop_extra">'.__('Extra Field','eshop').' <span class="reqd">*</span><br />
<input class="short" type="text" name="eshop_extra" value="" id="eshop_extra" maxlength="20" size="20" /></label><br />';
$echo .= '</fieldset>' . "\n";
return $echo;
}
// Add extra field to error checks
add_filter('eshoperrorcheckout','eshop_extras_errorcheckout');
function eshop_extras_errorcheckout($_POST){
$myerror='';
if(!isset($_POST['eshop_extra']) || trim($_POST['eshop_extra'])==''){
$myerror= '<li>'.__('<strong>Extra Field</strong> - missing.','eshop_extras').'</li>';
}
if(!isset($_POST['ArticlesOrderForm'])) {
if(!isset($_POST['kwd1']) || trim($_POST['kwd1'])=='') {
$myerror= '<li>'.__('<strong>KWD1</strong> - missing.','kwd1').'</li>';
}
}
if(!isset($_POST['PressReleasesForm'])) {
if(!isset($_POST['kwd2']) || trim($_POST['kwd2'])=='') {
$myerror= '<li>'.__('<strong>KWD2</strong> - missing.','kwd2').'</li>';
}
}
return $myerror;
}
** Now iam not getting any syntax erors…. please check below link: (under select the appropriate form) , when u check them, they’re missing away.. what am I doing wrong..? **
articlewritingservicess.com/shopping-cart/checkout/
You are mixing up server-side code and client-side code.
PHP is used on the server, and will produce the HTML that is sent to the browser (that HTML can include jquery). But the jquery will only work on the browser.
The problem is that you are using jquery commands on the server-side, with the following line…
(This is the 2nd
ifstatement in youreshop_extras_errorcheckoutfunction)This should be PHP code, not jquery… something like…
Additional based on OP’s comment
The reason that your checkboxes are not remaining “checked” on the post-back of the page is because you are creating the
<input type="checkbox"code each time, and if you don’t specifically provide thecheckedattribute, it will be unchecked when the page is displayed.(I’m not sure if you’re familiar with ASP.NET, but in that technology if you tick a checkbox and then post-back, ASP.NET will handle this for you. PHP does not do it as standard, you need to tell it to check it.)
So, for instance, where you are “echo”ing the following line in your
eshop_extras_checkoutfunction (note, this is contained with a PHP string, it is not straight mark-up):… you need to conditionally put the
checkedattribute, something like this:… which would result in the string looking like
Therefore, when the final HTML is sent to the browser, the attribute
checkedwill appear if the checkbox was checked, and it won’t if it won’t.Hope that makes sense