I am creating a form using html and php, inside this form I have date input "from" and date input "to".
How can "to" get update with the date I select in "from"?
For example, if I select in the "from" July 1st, I want "to" to get update with the same date or the next day.
This is my form:
<?php ob_start() ?>
<?php if(isset($params['message'])) :?>
<b><span style="color: red;"><?php echo $params['message'] ?></span></b>
<?php endif; ?>
<?php
date_default_timezone_set('America/Costa_Rica');
?>
<br/>
<form name="formInsertDocument" action="index.php?ctl=insertDocument" autocomplete="off" method="POST">
<h2>Insert New Document</h2>
<fieldset>
<ul>
<li>
<label for="name">Type:</label>
<input type="number" name="id_type" required value="<?php echo $params['id_type'] ?>" />
</li>
<li>
<label for="name">Client:</label>
<input type="number" name="id_client" required value="<?php echo $params['id_client'] ?>" />
</li>
<li>
<label for="name">Date:</label>
<input type="date" name="date_document" required value="<?php echo date('Y-m-d'); ?>" value="<?php echo $params['date_document'] ?>" />
</li>
<li>
<label for="name">Arrival:</label>
<input type="date" name="date_arrival" required value="<?php echo date('Y-m-d'); ?>" value="<?php echo $params['date_arrival'] ?>" />
</li>
<li>
<label for="name">Departure:</label>
<input type="date" name="date_leaving" required value="<?php echo date('Y-m-d'); ?>" value="<?php echo $params['date_leaving'] ?>" />
</li>
<li>
<label for="name">Subtotal:</label>
<input type="number" name="subtotal" required value="<?php echo $params['subtotal'] ?>" />
</li>
<li>
<label for="name">Taxable:</label>
<input type="number" name="taxable" required value=00000000 value="<?php echo $params['taxable'] ?>" />
</li>
<li>
<label for="name">Tax:</label>
<input type="number" name="tax" value=00000000 value="<?php echo $params['tax'] ?>" />
</li>
<li>
<label for="name">Other:</label>
<input type="number" name="other" required value="<?php echo $params['other'] ?>" />
</li>
<li>
<label for="name">Total:</label>
<input type="number" name="total" required value=0 value="<?php echo $params['total'] ?>" />
</li>
</ul>
</fieldset>
<input type="submit" value="Insert" name="insert" />
</form>
<?php $contenido = ob_get_clean() ?>
<?php include '../app/templates/layout.php' ?>
With javascript you'll have to use something like this:
<script>
var date_arrival = document.getElementsByName('date_arrival')[0];
var date_leave = document.getElementsByName('date_leave')[0];
date_arrival.addEventListener('change', function() {
date_leave.value = date_arrival.value;
});
</script>
I want to get the value clicked in radio button.
This is my code:
<ul class="collapsible popout" data-collapsible="accordion" id="clicks">
<?php
foreach ($preguntas['preguntas'] as $row)
{
$opciones = $pregunta->opciones($row[0]);
?>
<li>
<div class="collapsible-header"><i class="material-icons">question_answer</i><?php echo utf8_encode($row[2]); ?></div>
<div class="collapsible-body">
<?php foreach ($opciones as $opcion){ ?>
<p class="left-align" id="options">
<input class="with-gap" name="pregunta_<?php echo utf8_encode($row[0]); ?>" type="radio" id="opcion_<?php echo utf8_encode($opcion[0]); ?><?php echo $row[0] ?>" value="<?php echo $opcion[0]; ?>" />
<label for="opcion_<?php echo $opcion[0]; ?><?php echo utf8_encode($row[0]); ?>"><?php echo utf8_encode($opcion[2]); ?></label>
</p>
<?php } ?>
</div>
<?php } ?>
</li>
</ul>
I need to get the value of this input id="opcion_..."
<p class="left-align" id="options">
<input class="with-gap" name="pregunta_<?php echo utf8_encode($row[0]); ?>" type="radio" id="opcion_<?php echo utf8_encode($opcion[0]); ?><?php echo $row[0] ?>" value="<?php echo $opcion[0]; ?>" />
<label for="opcion_<?php echo $opcion[0]; ?><?php echo utf8_encode($row[0]); ?>"><?php echo utf8_encode($opcion[2]); ?></label>
</p>
The problem is name and id is changing, it's not the same
Any idea?
Thank you.
JQuery selector for part of attribute $("[attribute^='value']") like this:
$("[id^='opcion_']").click(function(){
alert($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label><input name="pregunta_xxx" type="radio" id="opcion_123" value="123">radio for 123</label>
<label><input name="pregunta_xxx" type="radio" id="opcion_456" value="456">radio for 456</label>
I feel like this should be pretty simple, but I'm not getting the results that I want. I have an email signup form that displays across all my websites. If they happen to visit my website with the store code ama_br the email signup disappears. That is fine and that works. My elseif statement is a different form than the one that is displayed across all store views and I want this new form to only appear when it's store code ama_ca. It does not work for me and I don't see anything wrong with my code. Please help. Thank you.
<?php if (Mage::app()->getStore()->getCode() != "ama_br"):?>
<ul>
<li><?php echo $this->__('Email Sign Up')?></li>
<li>
<form action="<?php echo $this->getUrl('email_preferences')?>" method="get" id="newsletter-validate-detail">
<input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('Enter Email address')?>" title="<?php echo $this->__('Enter Email address')?>' class="required-entry validate-email">
<button class="submit">+</button>
<input type="hidden" name="source" value="nt">
</form>
</li>
<li class="footer-promo"><?php echo $this->getChildHtml('footer_promo')?></li>
</ul>
<?php elseif (Mage::app()->getStore()->getCode() == "ama_ca"):?>
<ul>
<li><?php echo $this->__('Email Sign Up')?></li>
<li>
<form method="post" action="http://enews.******.com/q/9MNK4U4iV9Mutb9YzTxF2zRWDIPgKoX0F0" accept-charset="UTF-8">
<input type="hidden" name="crvs" value="6hZNXcISD79ac2Empmsr2az_B3Qc5osTNmkOdNHleqhPIYmsxEOe6PbgaUo-3WBn_Vbgorrbk4qjekx7w4tljA">
<input type="hidden" name="CheckBox.Source.ca_footer" value="on">
<input name="email" type="text" id="newsletter" placeholder="Enter Email address" title="Enter Email address' class=" required-entry="">
<input type="hidden" id="submit" value="Sign Up">
</form>
</li>
<li class="footer-promo"><?php echo $this->getChildHtml('footer_promo')?></li>
</ul>
<?php endif;?>
Description
You have done every thing right but you just miss the trick look carefully on your if statement Logic that is if your Code not equals to ama_br that is it can be equal to ama_ca so it will show the form in if statement for ama_ca as well as on any other string from ama_br so the form you are trying to show on Code equals to ama_ca is not showing. Try one of the following it will resolve your query.
Code
<?php if (Mage::app()->getStore()->getCode() == "ama_ca"): ?>
<ul>
<li><?php echo $this->__('Email Sign Up') ?></li>
<li>
<form method="post" action="http://enews.******.com/q/9MNK4U4iV9Mutb9YzTxF2zRWDIPgKoX0F0" accept-charset="UTF-8">
<input type="hidden" name="crvs" value="6hZNXcISD79ac2Empmsr2az_B3Qc5osTNmkOdNHleqhPIYmsxEOe6PbgaUo-3WBn_Vbgorrbk4qjekx7w4tljA">
<input type="hidden" name="CheckBox.Source.ca_footer" value="on">
<input name="email" type="text" id="newsletter" placeholder="Enter Email address" title="Enter Email address' class=" required-entry="">
<input type="hidden" id="submit" value="Sign Up">
</form>
</li>
<li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
</ul>
<?php elseif (Mage::app()->getStore()->getCode() != "ama_br"): ?>
<ul>
<li><?php echo $this->__('Email Sign Up') ?></li>
<li>
<form action="<?php echo $this->getUrl('email_preferences') ?>" method="get" id="newsletter-validate-detail">
<input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('Enter Email address') ?>" title="<?php echo $this->__('Enter Email address') ?>' class="required-entry validate-email">
<button class="submit">+</button>
<input type="hidden" name="source" value="nt">
</form>
</li>
<li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
</ul>
<?php endif; ?>
OR
<?php if (Mage::app()->getStore()->getCode() != "ama_br" && Mage::app()- >getStore()->getCode() != "ama_ca"): ?>
<ul>
<li><?php echo $this->__('Email Sign Up') ?></li>
<li>
<form action="<?php echo $this->getUrl('email_preferences') ?>" method="get" id="newsletter-validate-detail">
<input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('Enter Email address') ?>" title="<?php echo $this->__('Enter Email address') ?>' class="required-entry validate-email">
<button class="submit">+</button>
<input type="hidden" name="source" value="nt">
</form>
</li>
<li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
</ul>
<?php elseif (Mage::app()->getStore()->getCode() == "ama_ca"): ?>
<ul>
<li><?php echo $this->__('Email Sign Up') ?></li>
<li>
<form method="post" action="http://enews.******.com/q/9MNK4U4iV9Mutb9YzTxF2zRWDIPgKoX0F0" accept-charset="UTF-8">
<input type="hidden" name="crvs" value="6hZNXcISD79ac2Empmsr2az_B3Qc5osTNmkOdNHleqhPIYmsxEOe6PbgaUo-3WBn_Vbgorrbk4qjekx7w4tljA">
<input type="hidden" name="CheckBox.Source.ca_footer" value="on">
<input name="email" type="text" id="newsletter" placeholder="Enter Email address" title="Enter Email address' class=" required-entry="">
<input type="hidden" id="submit" value="Sign Up">
</form>
</li>
<li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
</ul>
<?php endif; ?>
I have a magento store where the Add to Cart button has stopped working and instead a search query is performed ( where the & are changed to & so it doesn't even work ) This can be seen by adding a item to cart here: http://bit.ly/1o8SwmE
This add to cart button does however work on category grid pages. I have tried pasting the link generated in the form into a web browser and it also redirects me to the same broken search page, I have also tried pasting the action link from the add to cart form on a working category grid page into firebug on the non working page and this then adds the product from the category page perfectly.
The snippets of code i have used are pasted below and other people have had them working it seems so this may not be the issue.
OLD CODE
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('QTY') ?>:</label>
<input type="text" name="qty" id="qty" class="new-qty-cat" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button class="new-qty-button" type="button" onclick="this.form.submit()"></button>
</form>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
NEW CODE
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId(); ?>">
<input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" />
<button class=form-button" onclick="productAddToCartForm_<?php echo $_product->getId(); ?>.submit()"><span><?php echo $this->__('Add to Cart') ?></span></button>
</form>
<script type="text/javascript"> var productAddToCartForm_<?php echo $_product->getId(); ?> = new VarienForm('product_addtocart_form_<?php echo $_product->getId(); ?>'); productAddToCartForm_<?php echo $_product->getId(); ?>.submit = function(){ if (this.validator.validate()) { this.form.submit(); } }.bind(productAddToCartForm_<?php echo $_product->getId(); ?>);</script>
NEW CODE 2
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>
New Code 3
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input class="new-qty-cat" type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" class="new-qty-button" onclick="this.form.submit()"><span><span> </span></span></button>
</form>
I'm using the Mingle plugin for Wordpress for users to register, so they can post on a Mingle Forum.
The signup process works, but I want to redirect the user to the forum page once they have submitted their details, rather than just staying on the signup page.
I've tried adding <input type="hidden" name="redirect_to" value="<?php echo bloginfo('url'); ?>" /> to the code so that the page redirects (as it worked on the login form), but doesn't seem to work with signup form.
I've tried using the "action" function in the form details too; this redirects the page, but doesn't submit the data.
The page's code is below - would really appreciate a solution, if possible! Thanks.
<form name="registerform" id="registerform" method="post">
<input type="hidden" id="mngl-process-form" name="mngl-process-form" value="Y" />
<input type="hidden" name="redirect_to" value="http://creativespotlights.com/forum" action="http://creativespotlights.com/forum" />
<p>
<label><?php _e('Username', 'mingle'); ?>*:<br />
<input type="text" name="user_login" id="user_login" class="input mngl_signup_input" value="<?php echo $user_login; ?>" size="20" tabindex="200" /></label>
</p>
<p>
<label><?php _e('E-mail', 'mingle'); ?>*:<br />
<input type="text" name="user_email" id="user_email" class="input mngl_signup_input" value="<?php echo $user_email; ?>" size="25" tabindex="300" /></label>
</p>
<?php if(isset($mngl_options->field_visibilities['signup_page']['name'])) { ?>
<p>
<label><?php _e('First Name', 'mingle'); ?>:<br />
<input type="text" name="user_first_name" id="user_first_name" class="input mngl_signup_input" value="<?php echo $user_first_name; ?>" size="20" tabindex="400" /></label>
</p>
<p>
<label><?php _e('Last Name', 'mingle'); ?>:<br />
<input type="text" name="user_last_name" id="user_last_name" class="input mngl_signup_input" value="<?php echo $user_last_name; ?>" size="20" tabindex="500" /></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['url'])) { ?>
<p>
<label><?php _e('Website', 'mingle'); ?>:<br />
<input type="text" name="mngl_user_url" id="mngl_user_url" value="<?php echo $mngl_user_url; ?>" class="input mngl_signup_input" size="20" tabindex="600"/></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['location'])) { ?>
<p>
<label><?php _e('Location', 'mingle'); ?>:<br />
<input type="text" name="mngl_user_location" id="mngl_user_location" value="<?php echo $mngl_user_location; ?>" class="input mngl_signup_input" size="20" tabindex="700" /></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['bio'])) { ?>
<p>
<label><?php _e('Bio', 'mingle'); ?>:<br />
<textarea name="mngl_user_bio" id="mngl_user_bio" class="input mngl-growable mngl_signup_input" tabindex="800"><?php echo wptexturize($mngl_user_bio); ?></textarea></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['sex'])) { ?>
<p>
<label><?php _e('Gender', 'mingle'); ?>*: <?php echo MnglProfileHelper::sex_dropdown('mngl_user_sex', $mngl_user_sex, '', 900); ?></label>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['signup_page']['password'])) { ?>
<p>
<label><?php _e('Password', 'mingle'); ?>:<br/>
<input type="password" name="mngl_user_password" id="mngl_user_password" class="input mngl_signup_input" tabindex="1000"/></label>
</p>
<p>
<label><?php _e('Password Confirmation', 'mingle'); ?>:<br />
<input type="password" name="mngl_user_password_confirm" id="mngl_user_password_confirm" class="input mngl_signup_input" tabindex="1100"/></label>
</p>
<?php } else { ?>
<p id="reg_passmail"><?php _e('A password will be e-mailed to you.', 'mingle'); ?></p>
<?php } ?>
<?php if($mngl_options->signup_captcha) { ?>
<?php
$captcha_code = MnglUtils::str_encrypt(MnglUtils::generate_random_code(6));
?>
<p>
<label><?php _e('Enter Captcha Text', 'mingle'); ?>*:<br />
<img src="<?php echo MNGL_SCRIPT_URL; ?>&controller=captcha&action=display&width=120&height=40&code=<?php echo $captcha_code; ?>" /><br/>
<input id="security_code" name="security_code" style="width:120px" type="text" tabindex="1200" />
<input type="hidden" name="security_check" value="<?php echo $captcha_code; ?>">
</p>
<?php } ?>
<?php do_action('mngl-user-signup-fields'); ?>
<br class="clear" />
<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="mngl-share-button" value="<?php _e('Sign Up', 'mingle'); ?>" tabindex="60" />
</p>
</form>
Try this
<?php
if (isset($_POST['wp-submit']))
{
header('Location: http://site/result.php');
}
?>
in the top of your code
OR you can try to do it by javascript with onsubmit="window.location.href='result.php';"
You can use :
header('Location: http://yoursite.com/location.php');
But you have to get a clean output (no html before the header).
Doc here.
Something like this should work:
if (isset($_POST['user_login']))
{
(your redirect code here)
}
After a form has been successfully submitted you should perform a 303 redirect to the same page. Doing this will prevent resubmitting the form if the user happens to press F5 or some other form or reloading the page.
wp_redirect("/path/to/my/script", 303);
You will need to substitute /path/to/my/script with the URL where your form lives.