1

I had a form and i can post other values like name,email but I could not post the radio buttons values in mail file.Please anyone can help me.

My form

  <form action="" id="bookingtest" method="post">
<div class="fieldset">
    <ul class="form-list">
        <li class="fields">
        <div class="field">
            <label for="testname" class="required"><em>*</em><?php echo $this->__('Test Name') ?> </label>
                <div class="input-box">
                    <input type="text" id="testname" name="testname" value="<?php echo $_GET['name']?>" class="input-text required-entry" title="<?php echo $this->__('Test Name') ?>" />
                </div>
            </div>  

            <div class="field"> 

            <label for="city" class="required"><em>*</em><?php echo $this->__('City') ?> </label>
                <div class="input-box">
                        <input type="text" id="city" name="city" value="<?php echo $_GET['city']?>" class="input-text required-entry" title="<?php echo $this->__('City') ?>" />
                </div>
        </div>
        </li>
        <li>

            <label for="location" class="required"><em>*</em><?php echo $this->__('Location') ?> </label>
                <div class="input-box">
                        <input type="text" id="location" name="location" value="<?php echo $_GET['location']?>" class="input-text required-entry" title="<?php echo $this->__('Location') ?>" />
                </div>

        </li>
        <li class="fields">
        <div class="field">
            <label for="cname" class="required"><em>*</em><?php echo $this->__('Name') ?> </label>
                <div class="input-box">
                        <input type="text" id="cname" name="cname" value="" class="input-text required-entry" title="<?php echo $this->__('Name') ?>" />
                </div>
            </div>
        <div class="field">
         <label for="email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
                <div class="input-box">
                    <input type="text" name="email" value="<?php echo $this->escapeHtml($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
                </div>
        </div>
        </li>
        <li>

            <label for="mobile" class="required"><em>*</em><?php echo $this->__('Mobile Number') ?> </label>
                        <div class="input-box">
                            <input type="text" id="mobile" name="mobile" value="" class="input-text required-entry validate-mobileno" title="<?php echo $this->__('Mobile Number') ?>" />
                        </div>
         </li>
          <li>
          <label class="required"><em>*</em><?php echo $this->__('Sample Collection') ?> </label></li>
          <li>
                <div class="radio_button">
                <input type="radio" name="radio" class="input-text required-entry validate-select" value="I will visit Lab"> I will visit Lab
                </div>
                <div>
                <input type="radio" name="radio" class="input-text required-entry validate-select" value="Visit me at home/office +Rs50.00" > Visit me at home/office +Rs50.00
                </div>
         </li>
         <li>
                <label for="testschedule" class="required"><em>*</em><?php echo $this->__('Test Schedule') ?> </label>
                    <div class="input-box">
           <div style="float:left">
                        <input type="text" id="testschedule" name="testschedule" value="" class="input-text required-entry validation-failed" title="Test Schedule" style="width: 150px;"><div style="" id="advice-required-entry-testschedule" class="validation-advice">This is a required field.</div></div><div style="float:left">
                        <img style="" title="Select Date" id="date_select_trig" alt="" src="http://www.labwise.in/devel/skin/frontend/ultimo/default/images/xcalendar.gif.pagespeed.ic.nkzRZoIMTp.png">
          </div><div style="float:left;widht:50px">
                        <select name="hour" id="hour" class="input-select required-entry validate-select validation-failed" style="width: 50px;">
                                    <option value="">--</option>
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                    <option value="6">6</option>
                                    <option value="7">7</option>
                                    <option value="8">8</option>
                                    <option value="9">9</option>
                                    <option value="10">10</option>
                                    <option value="11">11</option>
                                    <option value="12">12</option>
                                 </select><div style="" id="advice-required-entry-date_time" class="validation-advice">This is a required field.</div></div><div style="float:left">
                            <b>:</b>
              </div><div style="float:left">
                            <select name="minute" id="minute" class="input-select required-entry validate-select validation-failed" style="width: 50px;">
                                    <option value="">--</option>
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                    <option value="6">6</option>
                                    <option value="7">7</option>
                                    <option value="8">8</option>
                                    <option value="9">9</option>
                                    <option value="10">10</option>
                                    <option value="11">11</option>
                                    <option value="12">12</option>
                            </select>
                </div><div style="float:left">
                            <select name="ampm" id="ampm" class="input-select required-entry validate-select validation-failed" style="width: 50px;">
                                    <option value="">--</option>
                                    <option value="1">AM</option>
                                    <option value="2">PM</option>
                            </select>
         </div><div style="float:left">
                    </div></div>
        </li>

    </ul>
    </div>
    <div class="button">
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
    <button id= "submit"  type="submit" class="button" title="<?php echo $this->__('Book Test') ?>" name="send" id="send2"><span><span><?php echo $this->__('Book Test') ?></span></span></button>
</div>


 </form>

  <script src="<?php echo Mage::getBaseUrl('js')."calendar/calendar.js" ?>" type="text/javascript"></script>

   <script src="<?php echo Mage::getBaseUrl('js')."calendar/calendar-setup.js" ?>" type="text/javascript"></script>

   <link rel="stylesheet" type="text/css" href="<?php echo Mage::getBaseUrl('js') ?>calendar/calendar-win2k-1.css"  />
<?php echo $this->getLayout()->createBlock('core/html_calendar')->setTemplate('page/js/calendar.phtml')->toHtml();?>

  <script type="text/javascript">

    if(Validation) {
     Validation.addAllThese([
['validate-mobileno','Enter correct mobile number (Eg:9986858483)',
   function(v){
    //var timePat ="^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$";

var timePat ="^{0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$";
// var matchArray = v.match(timePat);
if(v.length > 0){
if(v.length !=10){
    return false;
   }else if(v[0]!=9 && v[0]!=8 && v[0]!=7){

    return false;
   }


return true;

}else {
return false;
}

}
   ]])
  };
   var dataForm = new VarienForm('bookingtest', true); 
 </script>
 <script type="text/javascript">
   // <![CDATA[
 Calendar.setup({
 inputField : 'testschedule',
   ifFormat : '%d-%b-%Y',
showsTime: false,
 button : 'date_select_trig',
 singleClick : true,
 });
   // ]]>
</script>

Mail.phtml

   function sendMailAction(){
   //Mage::getModel('sales/order')->load(24999);
   $email=$_POST['email'];
    $name=$_POST['testname'];
    $city=$_POST['city'];
    $location=$_POST['location'];

    $cname=$_POST['cname'];
    $mobile=$_POST['mobile'];

    $html=
   '<p>TestName: '.$name.'</p>
    <p>City: '.$city.'</p>
    <p>Location: '.$location.'</p>
     <p>Name: '.$cname.'</p>
      <p>Email : '.$email.'</p>
       <p>Mobile Number: '.$mobile.'</p>
     '

     ;
     $mail = Mage::getModel('core/email');
     $mail->setToName('admin');
    $mail->setToEmail($email);
       $mail->setBody($html);
       $mail->setSubject('Booking');
        $mail->setFromEmail('admin@labwise.in');
         $mail->setFromName("Labwise");
      //$mail->addBcc("admin@labwise.in");
      $mail->setType('html');// YOu can use Html or text as Mail format

   try {
      $mail->send();
         //Mage::getSingleton('core/session')->addSuccess('Your Order is successfully Completed');
       //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
       //return '<h2>Your Order has been submitted. Thank you for using labwise.   </h2>';
    //$this->_redirect('');
   }
    catch (Exception $e) {
   //Mage::getSingleton('core/session')->addError('Unable to send.');
   //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
  //return '</h2>Unable to submit.</h2>'; 
   //$this->_redirect('');
   }
 }  
  echo sendMailAction();
  • echo $option=$_POST['radio']; did you get any value? – Qaisar Satti Nov 20 '15 at 10:44
  • No value.it has not worked i have worked by keeping that – Mouni Nov 20 '15 at 10:44
  • And one more thing the selected radio button should be displayed in the mail.(EX:If user selects i will visit lab the mail body should be Sample Collection:I will visit lab") – Mouni Nov 20 '15 at 10:47
  • @QaisarSatti please reply me. – Mouni Nov 20 '15 at 10:59
  • try Mage::app()->getRequest()->getPost('radio'); and check you are getting the value or not – Qaisar Satti Nov 20 '15 at 11:04
2
function sendMailAction(){
   //Mage::getModel('sales/order')->load(24999);
   $email=$_POST['email'];
    $name=$_POST['testname'];
    $city=$_POST['city'];
    $testschedule=$_POST['testschedule'];

    $location=$_POST['location'];
    $option=Mage::app()->getRequest()->getPost('radio'); 
    $cname=$_POST['cname'];
    $mobile=$_POST['mobile'];
    $hour=$_POST['hour'];
    $minute=$_POST['minute'];
    $ampm=$_POST['ampm'];

    $html=
   '<p>TestName: '.$name.'</p>
    <p>City: '.$city.'</p>
    <p>Location: '.$location.'</p>

     <p>Name: '.$cname.'</p>
      <p>Email : '.$email.'</p>
       <p>Mobile Number: '.$mobile.'</p>
      <p>Test Schdule: '.$testschedule.'&nbsp; '.$hour.':'.$minute.' &nbsp;'.$ampm.'</p>
       <p>Visit: '.$option.'</p>
     '

     ;
     $mail = Mage::getModel('core/email');
     $mail->setToName('admin');
    $mail->setToEmail($email);
       $mail->setBody($html);
       $mail->setSubject('Booking');
        $mail->setFromEmail('admin@labwise.in');
         $mail->setFromName("Labwise");
      //$mail->addBcc("admin@labwise.in");
      $mail->setType('html');// YOu can use Html or text as Mail format

   try {
      $mail->send();
         //Mage::getSingleton('core/session')->addSuccess('Your Order is successfully Completed');
       //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
       //return '<h2>Your Order has been submitted. Thank you for using labwise.   </h2>';
    //$this->_redirect('');
   }
    catch (Exception $e) {
   //Mage::getSingleton('core/session')->addError('Unable to send.');
   //Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());
  //return '</h2>Unable to submit.</h2>'; 
   //$this->_redirect('');
   }
 }  
  echo sendMailAction();
  • where is Test Schedule field?? – Mouni Nov 20 '15 at 11:30
  • add also want the dropdown value too? – Qaisar Satti Nov 20 '15 at 11:35
  • update the answer kindly check and feedback – Qaisar Satti Nov 20 '15 at 11:54
  • you missed another quotation before $ampm – Mouni Nov 20 '15 at 11:55
  • no quotation before $ampm see ur comment – Qaisar Satti Nov 20 '15 at 12:01
2

you have to check your posted data using

 $this->getRequest()->getPost()

in your sendMailAction check what value are getting in those array.Based on that you can get value of radio.

  • Where I need to place this code – Mouni Nov 20 '15 at 10:48
  • in sendMailAction function, before $email=$_POST['email']. this is for debugging purpose. – Rakesh Jesadiya Nov 20 '15 at 10:49
  • it has to display the selected radio button by the user. – Mouni Nov 20 '15 at 10:50
  • but you have to check which array value are printed using above method. – Rakesh Jesadiya Nov 20 '15 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.