In my mvc application i used raty for rating my image. Here is my code
<div class="container">
<form method="post" class='form' role='form' action="?section=photo&view=addVote">
<input type="hidden" name="photoId" value="<?php echo $photoinfo['id']; ?>"></input>
<input type="hidden" name="score" value="<?php ?>"></input>
<div class="row">
<div>
<img src="<?php echo base_url(); ?>images/photo_booth/<?php echo $photoinfo['image_name'];?>" class="img-rounded img-define" width="580" height="350"></img>
</div>
<div>
<h6><?php echo $photoinfo['title'] ?></h6>
</div>
<div>
<p class="paragraph"><?php echo $photoinfo['description'] ?></p>
</div>
<div>
<div id="raty"></div>
<button type="submit" class="btn btn-primary button_new submit-btn">Add Vote</button>
</div>
</div>
</form>
<script type="text/javascript">
$('#raty').raty({
score: <?php echo $photoinfo['vote']; ?>,
number: 10,
starOn: "<?php echo base_url(); ?>icons/star-on.png",
starOff: "<?php echo base_url(); ?>icons/star-off.png",
readOnly: false
});
$("#raty > img").click(function(){
var score=$(this).attr("alt");
});
</script>
Here i can save my score=$(this).attr("alt"); to database using javascript. But i need it to be passed as a hidden field data something like this <input type="hidden" name="score" value="<?php the score of raty! ?>"></input>
. Here addVote is a method where i have to do the operation.
can i do that? if another way exist so how?Thanks.
Write php inside javascript as string can solve your problem:-
score: "<?php echo $photoinfo['vote']; ?>"
you forgot a " " in your php
score: <?php echo $photoinfo['vote']; ?>,
you can use score: "<?php echo $photoinfo['vote']; ?>",
instend of score: <?php echo $photoinfo['vote']; ?>,
Related
I am working with multi step form with php, I have array $rec where i am getting all
questions ( from database/dynamic).
I want to validate those fields whose key is mandatory and value is 1 (coming from array($rec)).
I want "next" page/question shouldn't display until I fill first question.
Here is my html code
<form action="<?php echo site_url('Nps/FormAdd'); ?>" method="post">
<?php //echo "<pre>"; print_R($keyslug);?>
<input type="hidden" name="mobile_no" value="<?php echo $keyslug['mobileNo']; ?>">
<input type="hidden" name="contact_mapping_id" value="<?php echo $keyslug['id']; ?>">
<?php $i="1";
$lastElement = end($rec);
$i="1";
foreach($rec as $key => $records)
{
<div class="card" id="<?php echo $records['ques_id']; ?>" >
<?php if($records['type']=="range" )
{
?>
<div class="form-group" style="margin-top: 10px;">
<div class="chart-scale develop-rating">
<?php $j=$records['start_range'];
$max= $records['end_range'];
for($i=$j;$i<=$max; $i++) {
?>
<button id="rating" attr-hide-div="<?php if($i <= $records['min_value']) { echo $records['max_show_ques_id']; } else { echo $records['show_ques_id']; }?>"
attr-show-div="<?php if($i <= $records['min_value']) { echo $records['show_ques_id']; } else { echo $records['max_show_ques_id']; }?>"attr-value="<?php echo $i; ?>" class="btn rating-button-click btn-scale btn-scale-asc-<?php echo $i; ?>">
<?php echo $i; ?>
</button>
<?php } ?>
<input type="hidden" id='ques_<?php echo $records['ques_id']; ?>' class="input-develop all-mandatory-check" attr-required="<?php echo $records['mandatory']; ?>" <?php if($records['IsRatingQuestion']=="1") { ?> name='rangeR_<?php echo $records['ques_id']; ?>' <?php } else { ?> name='ques_<?php echo $records['ques_id']; ?>' <?php } ?> value="">
</div>
</div>
<?php
}
elseif($records['type']=="check_box")
{
?>
<div class="form-group checkboxes">
<label class="form-control-label"><?php echo $records['question']; ?></label>
<div>
<?php
$opt = explode("::", $records['options']);
$result = count($opt);
$i="1";
foreach($opt as $s)
{
?>
<label class="form-container"><?php echo $s; ?>
<input class="all-mandatory-check" type="checkbox" attr-required="<?php echo $records['mandatory']; ?>" id="name" value='<?php echo $s; ?>' name='check_<?php echo $records['ques_id']; ?>[]'>
<span class="checkmark"></span>
</label>
<?php } ?>
</div>
</div>
<?php
}
$key;
if($key!="0"){
?>
<input type="button" name="previous" class="previous action-button" value="Previous" />
<?php } ?>
<?php
$record_last_end = $rec;
$lastElement = array_key_last($record_last_end);
if($key == $lastElement)
{
?>
<input type="submit" name="submit" value="submit" class="next action-button" >
<?php } else { ?>
<input type="button" name="next" id="next1" class="next action-button" value="Next" />
<?php } ?>
</div>
</div>
<?php
//$i++;
} ?>
</form>
When I select my language from the dropdown flag the opencart translates to the new language and I get directed to the index page.
I want to stay on the current page.
I found an article for this issue but I couldn`t make it work.
Link
This is my current code from catalog/controller/module/language.php
<?php if (count($languages) > 1) { ?>
<!-- Language -->
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="language_form">
<div class="dropdown">
<?php foreach ($languages as $language) { ?>
<?php if ($language['code'] == $code) { ?>
<?php echo $language['name']; ?>
<?php } ?>
<?php } ?>
<ul class="dropdown-menu">
<?php foreach ($languages as $language) { ?>
<li><?php echo $language['name']; ?></li>
<?php } ?>
</ul>
</div>
<input type="hidden" name="code" value="" />
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
</form>
<?php } ?>
actually i am creating a online exam webapplication in php. and i m retrieving data from database .now the prob. is how to loop data by indexing one by one..
so user view one question at a time and after clicking on submit button it display the next question by from array.
here i used array of all the rows and taking question one by one by javascript . but there is some prob. in javascript . i only render 1st question .. increment is not implementing correctly.
<input type="hidden" value="<?php echo $i=0; ?>" id="cc">
<div id="counter">
<p id="idIndex" name="id" value="<?php echo $findData[$i]['Exam']['id']; ?>"><?php echo $findData[$i]['Exam']['id']; ?> </p>
<p ><?php echo $findData[$i]['Exam']['que'];?></p>
<input type="radio" value="<?php echo $findData[$i]['Exam']['op1']; ?>" name="op1" id="jaid" ><?php echo $findData[$i]['Exam']['op1']; ?>
<input type="radio" value="<?php echo $findData[$i]['Exam']['op2']; ?>" name="op1" id="jai" ><?php echo $findData[$i]['Exam']['op2']; ?>
<input type="radio" value="<?php echo $findData[$i]['Exam']['op3']; ?>" name="op1" id="jai"><?php echo $findData[$i]['Exam']['op3']; ?>
<input type="radio" value="<?php echo $findData[$i]['Exam']['op4']; ?>" name="op1" id="jai" ><?php echo $findData[$i]['Exam']['op4']; ?>
</div>
<input type="submit" id="sub" onclick="myexam()" >
<?php echo $this->Html->script('jquery-2.2.3.min'); ?>
<script>
function myexam(value)
{
var v=$("#cc").val();
}
</script>
PHP is server side. Once your HTML is rendered, PHP has nothing more top do with it!
$("#cc").val("<?php echo $i=+1;?>");
The php echo is a string, that wont work.
var v=$("#cc").val();
v = v + 1;
$("#cc").val(v);
That should work. Fix the other line of JS similarly.
I am trying to change radio buttons in PHP to buttons from Bootstrap.
(I would also like to get rid of the submit button at the bottom of the page and have these submit the answer.)
This code works but it uses radio buttons:
<div id='javatbd<?php echo $myfname; ?>' class='col-xs-12 form-group answer-item radio-item radio' <?php echo $sDisplayStyle; ?> >
<input
class="radio"
type="radio"
value="<?php echo $code; ?>"
name="<?php echo $name; ?>"
id="answer<?php echo $name.$code; ?>"
<?php echo $checkedState;?>
onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
aria-labelledby="label-answer<?php echo $name.$code; ?>"
/>
<label for="answer<?php echo $name.$code; ?>" class="control-label radio-label"></label>
<div class="label-text label-clickable" id="label-answer<?php echo $name.$code; ?>">
<?php echo $answer; ?>
</div>
</div>
.
.
.
<div class="col-xs-6 save-all text-right">
<button type="submit" id="movesubmitbtn" value="movesubmit" name="movesubmit" accesskey="l" class="submit button btn btn-lg btn-primary">Submit</button>
</div>
I've tried this but it does not send the value.
<div id='javatbd<?php echo $myfname; ?>' class='col-xs-12 form-group answer-item radio-item btn' <?php echo $sDisplayStyle; ?> >
<div class="container-fluid">
<input
class="btn btn-primary btn-block"
type="button"
value="<?php echo $code; ?>"
name="<?php echo $name; ?>"
id="answer<?php echo $name.$code; ?>"
<?php echo $checkedState;?>
onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
aria-labelledby="label-answer<?php echo $name.$code; ?>"
/>
</div>
</div>
You can use the Bootstrap buttons radio component to make a radio button look like normal button.
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="options" id="option1"> Option 1
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option2"> Option 2
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option3"> Option 3
</label>
</div>
You can see the live example, and other options here - http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-stateful-buttons.php
This worked. Thanks! Now I'll try to remove the O in the middle of the button and remove the Submit button, so clicking on Boss will submit the value.
<div class="btn btn-primary btn-block">
<input
class="radio"
type="radio"
value="<?php echo $code; ?>"
name="<?php echo $name; ?>"
id="answer<?php echo $name.$code; ?>"
<?php echo $checkedState;?>
onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
aria-labelledby="label-answer<?php echo $name.$code; ?>"
/>
<label for="answer<?php echo $name.$code; ?>" class="control-label radio-label"></label>
Image of radio / buttons
This worked! Thanks very much! Now I will try to remove the Submit button and make the clicked values submit the value. I'm trying to reduce space on the page.
Bootstrap Radio / buttons. It worked
<div class="btn-block" data-toggle="buttons">
<label class="btn btn-primary btn-block">
<input
class="radio"
type="radio"
value="<?php echo $code; ?>"
name="<?php echo $name; ?>"
id="answer<?php echo $name.$code; ?>"
<?php echo $checkedState;?>
onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
aria-labelledby="label-answer<?php echo $name.$code; ?>"
/>
<label for="answer<?php echo $name.$code; ?>" class="control-label radio-label"></label>
<div class="label-text label-clickable" id="label-answer<?php echo $name.$code; ?>">
<?php echo $answer; ?>
</div>
</div>
I am modifying my login/registration form via login.phtml and have a problem with the "Create Account" button when I use an image button instead of the standard css button.
I modified this original code
<button type="button" title="<?php echo $this->__('Create an Account') ?>" class="button" onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>';"><span><span><?php echo $this->__('Create an Account') ?></span></span></button>
to
<input type="image" src="http://localhost/magento/skin/frontend/default/mytemplate/images/button-createaccount.png" title="<?php echo $this->__('Create an Account') ?>" onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>';">
and moved the button into the "content" div of the right floating "create account" div. The button is display correctly but everytime when I click create account, my browser highlights the obligatory fields of the login form in the left floating "Login" div before continuing to the create account page.
When I click the original css create account button, on the lower part of the page (within another div, which is neither part of the login nor create account div) the browser continues correctly without highlighting the form fields first. Has this somehow to do with the position of the button within the div or with the window.location method???
Here's the complete code:
<div class="account-login"> <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<div class="col2-set">
<div class="col-2 new-users">
<div class="content"> <?php echo $this->__('New Customers') ?>
<p><?php echo $this->__('By creating an account with our store, you will be able to move through the checkout process faster, store multiple shipping addresses, view and track your orders in your account and more.') ?></p>
<!-- Insert image button for Create Account in new div class "button" -->
<div class="button">
<input type="image" src="http://localhost/magento/skin/frontend/default/mytemplate/images/button-createaccount.png" title="<?php echo $this->__('Create an Account') ?>" onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>';">
</div>
<!-- End Insert image button for Create Account in new div class "button" -->
</div>
</div>
<div class="col-1 registered-users">
<div class="content">
<h2><?php echo $this->__('Registered Customers') ?></h2>
<p><?php echo $this->__('If you have an account with us, please log in.') ?></p>
<ul class="form-list">
<li>
<label for="email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
<div class="input-box">
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</div>
</li>
<li>
<label for="pass" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
<div class="input-box">
<input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
</div>
</li>
<?php echo $this->getChildHtml('persistent.remember.me'); ?>
</ul>
<?php echo $this->getChildHtml('persistent.remember.me.tooltip'); ?>
<!-- Insert image button for Login in div class "button" -->
<div class="button">
<input type="image" src="http://localhost/magento/skin/frontend/default/mytemplate/images/button-login.png" title="<?php echo $this->__('Login') ?>" name="send" id="send2">
</div>
<!-- End Insert image button for Login in div class "button" -->
<div class="buttons-set"> <?php echo $this->__('Forgot Your Password?') ?> </div>
</div>
</div>
<div class="col2-set">
<div class="col-2 new-users">
<div class="buttons-set">
<button type="button" title="<?php echo $this->__('Create an Account') ?>" class="button" onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>';"><span><span><?php echo $this->__('Create an Account') ?></span></span></button>
</div>
</div>
<div class="col-1 registered-users">
<div class="buttons-set"> <?php echo $this->__('Forgot Your Password?') ?>
<button type="submit" class="button" title="<?php echo $this->__('Login') ?>" name="send" id="send2"><span><span><?php echo $this->__('Login') ?></span></span></button>
</div>
</div>
</div>
<?php if (Mage::helper('checkout')->isContextCheckout()): ?>
<input name="context" type="hidden" value="checkout" />
<?php endif; ?>
</form>
<script type="text/javascript">
var dataForm = new VarienForm('login-form', true);
</script>
</div>
You are having his issue because the form is initiated in javascript as a Varien_Form:
<script type="text/javascript">
var dataForm = new VarienForm('login-form', true);
</script>
This has a number of default behaviours which are obviously behaing strangely when it encounters buttons and elements it is not expecting. These are defined somewhere in Magento's js libraries.
Hope this helps point you in the right direction.