Yona Posted August 22, 2020 Share Posted August 22, 2020 Survey script doesn't check that requiered fields are filled. Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/ Share on other sites More sharing options...
dodgeitorelse3 Posted August 22, 2020 Share Posted August 22, 2020 With the given information I would guess that you need to make sure the survey script has been written to verify that the fields are filled. Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580880 Share on other sites More sharing options...
gw1500se Posted August 22, 2020 Share Posted August 22, 2020 9 minutes ago, dodgeitorelse3 said: With the given information I would guess that you need to make sure the survey script has been written to verify that the fields are filled. After careful analysis and deliberation of the original post I would tend to agree. 🙂 Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580881 Share on other sites More sharing options...
Yona Posted August 23, 2020 Author Share Posted August 23, 2020 I am not familiar with PHP that much. Can someone help me find out if the script has been written to verify that the fields are filled? Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580889 Share on other sites More sharing options...
requinix Posted August 23, 2020 Share Posted August 23, 2020 The only way that could possibly happen is if you gave us something to look at. Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580890 Share on other sites More sharing options...
Yona Posted August 23, 2020 Author Share Posted August 23, 2020 (edited) this is a link to the file Edited August 23, 2020 by Yona wrong file name Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580892 Share on other sites More sharing options...
gw1500se Posted August 23, 2020 Share Posted August 23, 2020 Nope. Don't make people go to a 3rd party site. This forum is specifically designed for posting code here. Be sure to use the code icon (<> at the top) and select PHP or HTML as appropriate. Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580897 Share on other sites More sharing options...
Yona Posted August 23, 2020 Author Share Posted August 23, 2020 <?php include('header.php'); /** * * @package jQuery PHP Poll and Survey * @author NETCSHOP.COM * @copyright 2018 * @version v1.0.0 * **/ /* ---------------------- Email Settings ---------------------- */ $to = 'your_email@example.com'; // Specifies the receiver email address to send survey report $subject = 'My subject'; // Specifies the subject of the email $from = 'your_email@example.com'; // Optional: Specifies additional headers, like From, Cs or Bcc $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: '.$from."\r\n". 'Reply-To: '.$from."\r\n" . 'X-Mailer: PHP/' . phpversion(); /* ------------------------------------------------------------ */ /*-------- SAMPLE DATA --------*/ $questions['1']['status'] = 'enabled'; $questions['1']['info'] = 'Tooltip for question 1'; $questions['1']['type'] = 'text'; $questions['1']['ques'] = 'What is your email address?'; $questions['2']['status'] = 'enabled'; $questions['2']['info'] = 'Tooltip for question 2'; $questions['2']['type'] = 'radio'; $questions['2']['ques'] = 'What is your gender?'; $questions['2']['opts'][] = 'Male'; $questions['2']['opts'][] = 'Female'; $questions['3']['status'] = 'enabled'; $questions['3']['info'] = 'Tooltip for question 3'; $questions['3']['type'] = 'checkbox'; $questions['3']['ques'] = 'What is your favorite search engine?'; $questions['3']['opts'][] = 'Google'; $questions['3']['opts'][] = 'Bing'; $questions['3']['opts'][] = 'Yahoo'; $questions['3']['opts'][] = 'DuckDuckGo'; $questions['4']['status'] = 'enabled'; $questions['4']['info'] = 'Tooltip for question 4'; $questions['4']['type'] = 'select'; $questions['4']['ques'] = 'What is your favorite color?'; $questions['4']['opts'][] = 'Red'; $questions['4']['opts'][] = 'Orange'; $questions['4']['opts'][] = 'Yellow'; $questions['4']['opts'][] = 'Green'; $questions['4']['opts'][] = 'Blue'; $questions['4']['opts'][] = 'Purple'; $questions['4']['opts'][] = 'Brown'; $questions['4']['opts'][] = 'Black'; $questions['4']['opts'][] = 'White'; $questions['5']['status'] = 'enabled'; $questions['5']['info'] = 'Tooltip for question 5'; $questions['5']['type'] = 'textarea'; $questions['5']['ques'] = 'Please share your opinion:'; $questions['5']['placeholder'] = 'Write your feedback here'; $questions['5']['rows'] = '7'; $questions['5']['cols'] = '106'; $questions['6']['status'] = 'enabled'; $questions['6']['info'] = 'Tool for question 6'; $questions['6']['type'] = 'rate'; $questions['6']['ques'] = 'Please rate your overall satisfaction:'; $questions['6']['opts'][] = 'Very Poor'; $questions['6']['opts'][] = 'Poor'; $questions['6']['opts'][] = 'Average'; $questions['6']['opts'][] = 'Good'; $questions['6']['opts'][] = 'Very Good'; $questions['6']['opts'][] = 'Excellent'; $questions['7']['status'] = 'enabled'; $questions['7']['optional'] = 'yes'; $questions['7']['info'] = 'Tooltip for question 7'; $questions['7']['type'] = 'radio'; $questions['7']['ques'] = 'Was your original question answered?'; $questions['7']['opts'][] = 'Yes'; $questions['7']['opts'][] = 'No'; $questions['8']['status'] = 'disabled'; $questions['8']['optional'] = 'yes'; $questions['8']['info'] = 'Tooltip for question 8'; $questions['8']['type'] = 'radio'; $questions['8']['ques'] = 'Do you like survey tools?'; $questions['8']['opts'][] = 'Yes'; $questions['8']['opts'][] = 'No'; if(isset($_POST['submit'])){ $msg = "<html><body>"; $msg .= "<table>"; $i = 1; foreach ($_POST as $key => $value) { if($key != 'submit') { $msg .= "<tr><td>Q ".$i.": </td><td>".$questions[$key]['ques']."</td></tr>"; $msg .= "<tr><td>A ".$i.": </td><td>".$value."</td></tr>"; } $i++; } $msg .= "</table>"; $msg .= "</html></body>"; if(mail($to, $subject, $msg, $headers)){ echo 'Thanks for taking this survey, your answers has been sent successfully.'; } else{ echo 'Unable to send email. Please try again.'; } }else{ print "<div class=\"loader\"></div>"; print "<form method=\"POST\">"; foreach($questions as $key => $value) { $status = $questions[$key]['status']; $type = $questions[$key]['type']; $opts = $questions[$key]['opts']; $info = $questions[$key]['info']; if($type == 'text' && $status == 'enabled') { print "<div class=\"field\">"; print "<p>".$questions[$key]['ques']." <img src=\"assets/icons/info.png\" title='".$info."' alt=\"Survey\" /></p>"; print "<input type=\"text\" name=".$key." />"; print "</div>"; } if($type == 'radio' && $status == 'enabled') { print "<div class=\"field\">"; print "<p>".$questions[$key]['ques']." <img src=\"assets/icons/info.png\" title='".$info."' alt=\"Survey\" /></p>"; foreach($opts as $op_key => $op_value) { print "<label><input type=\"radio\" name=".$key." value=".$op_value." />".$op_value."</label>"; } print "</div>"; } if($type == 'checkbox' && $status == 'enabled') { print "<div class=\"field\">"; print "<p>".$questions[$key]['ques']." <img src=\"assets/icons/info.png\" title='".$info."' alt=\"Survey\" /></p>"; foreach($opts as $op_key => $op_value) { print "<label><input type=\"checkbox\" name=".$key." value=".$op_value." />".$op_value."</label>"; } print "</div>"; } if($type == 'select' && $status == 'enabled') { print "<div class=\"field\">"; print "<p>".$questions[$key]['ques']." <img src=\"assets/icons/info.png\" title='".$info."' alt=\"Survey\" /></p>"; print "<select name=".$key.">"; print "<option value=\"0\">Choose...</option>"; foreach($opts as $op_key => $op_value) { print "<option value=".$op_value." />".$op_value."</option>"; } print "</select>"; print "</div>"; } if($type == 'textarea' && $status == 'enabled') { print "<div class=\"field\">"; print "<p>".$questions[$key]['ques']." <img src=\"assets/icons/info.png\" title='".$info."' alt=\"Survey\" /></span></p>"; print "<textarea rows=".$questions[$key]['rows']." cols=".$questions[$key]['cols']." name=".$key."></textarea>"; print "</div>"; } if($type == 'rate' && $status == 'enabled') { print "<div class=\"field\">"; print "<p>".$questions[$key]['ques']." <img src=\"assets/icons/info.png\" title='".$info."' alt=\"Survey\" /></p>"; foreach($opts as $rate_key => $rate_value) { print "<input type=\"radio\" name='".$key."' value='".$rate_value."' /><img src=\"assets/images/stars-".$rate_key."\" /> ".$rate_value."<br>\n"; } print "</div>"; } } print "<div class=\"field\">"; print "<input type=\"submit\" class=\"BtnSend\" name=\"submit\" value=\"Send\">\n"; print "</form></div>"; } include('footer.php'); ?> Thanks. This is the code. Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580898 Share on other sites More sharing options...
gw1500se Posted August 23, 2020 Share Posted August 23, 2020 You are correct, it doesn't check for required fields. The most user friendly way to do that is with a javascript before the form is submitted. That way the user does not get frustrated when inadvertently missing a field and not knowing it until the server responds after the submit. That being said you should check again in PHP before using the fields in case someone is messing with your form. Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580899 Share on other sites More sharing options...
Yona Posted August 23, 2020 Author Share Posted August 23, 2020 Thank you. Can you help me withe the Javascript? I will pay if you wish. Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580900 Share on other sites More sharing options...
gw1500se Posted August 23, 2020 Share Posted August 23, 2020 I can't but there are others that likely will. Post your request in the Job Offerings forum. Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580904 Share on other sites More sharing options...
Barand Posted August 23, 2020 Share Posted August 23, 2020 Adding a "required" attribute to your input fields will do it for you on the client side.. Don't forget you still need to check within PHP when you process the posted data. Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580905 Share on other sites More sharing options...
Yona Posted August 23, 2020 Author Share Posted August 23, 2020 Where do I add the 'required'? Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580907 Share on other sites More sharing options...
Barand Posted August 23, 2020 Share Posted August 23, 2020 https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required Quote Link to comment https://forums.phpfreaks.com/topic/311370-yona/#findComment-1580909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.