By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

Require user to type an specific word in form in order to get form submitted?

matheussousuke
100+
P: 249
To prevent spam, I need the user text to have the <html> tag in the beginning, because the site is about blogger/myspace templates, so the system gotta recognize that there is a <html> tag somewhere in the text.

I think it can be easily done with condition function, but I don't know how where from start.
Feb 11 '12 #1
Share this Question
Share on Google+
15 Replies


P: 23
i dont realy understand your question can you expanciate on what you want...are you trying to search for the occurence of <html> in the submitted string?
Feb 11 '12 #2

matheussousuke
100+
P: 249
It's like:

1 - User is typing, then he submits the form.
2 - On submission, user get a message saying: The content you typed is not a myspace/blogger template, please use a template.
3 - To know if he's using a template or not, the system will see if in the submitted text there was a <html> tag, but the user doesn't know about.

I think that's a little like that "Required field" function, but here there is no if (empty) function.
Feb 12 '12 #3

P: 23
i hope this should help you

if not let me know

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $word_a = "<html>";
  4. $word_b = "</html>";
  5. $main = $_POST['variable_name'];
  6.  
  7. #the main varible will be submitted by your form. Change the variable_name for the real name of your variable on the form
  8.  
  9. $errors = array();
  10. #this will hold any error messages if found
  11.  
  12. if (strpos($main, $word_a) === false) 
  13. {
  14. $errors[] = "Our Systems Detected that this is not a valid blogger/myspace template - Missing <html> tag";
  15. }
  16.  
  17. if (strpos($main, $word_a) !== false)
  18. {
  19. echo "Your success messages or you could leave it blank";
  20. }
  21.  
  22. if (strpos($main, $word_b) === false)
  23. {
  24. $errors[] = "Our Systems Detected that this is not a valid blogger/myspace template - Missing </html> tag";
  25. }
  26.  
  27. if (strpos($main, $word_b) !== false)
  28. {
  29. echo "Your success messages or you could leave it blank";
  30. }
  31.  ?>
  32.  
i hope this helps...let me know if not
Feb 12 '12 #4

P: 23
i hope this should help you

if not let me know

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $word_a = "<html>";
  4. $word_b = "</html>";
  5. $main = $_POST['variable_name'];
  6.  
  7. #the main varible will be submitted by your form. Change the variable_name for the real name of your variable on the form
  8.  
  9. $errors = array();
  10. #this will hold any error messages if found
  11.  
  12. if (strpos($main, $word_a) === false) 
  13. {
  14. $errors[] = "Our Systems Detected that this is not a valid blogger/myspace template - Missing <html> tag";
  15. }
  16.  
  17. if (strpos($main, $word_a) !== false)
  18. {
  19. echo "Your success messages or you could leave it blank";
  20. }
  21.  
  22. if (strpos($main, $word_b) === false)
  23. {
  24. $errors[] = "Our Systems Detected that this is not a valid blogger/myspace template - Missing </html> tag";
  25. }
  26.  
  27. if (strpos($main, $word_b) !== false)
  28. {
  29. echo "Your success messages or you could leave it blank";
  30. }
  31.  ?>
  32.  
i hope this helps...let me know if not
Feb 12 '12 #5

matheussousuke
100+
P: 249
Woa, that's awesome, I have to finish a few coding here, after it, I'll use ur script and let u know. Thx a lot :D
Feb 12 '12 #6

matheussousuke
100+
P: 249
Bebore using it, have to insert a scroll bar, but is it possible to do that as php?
Feb 12 '12 #7

P: 23
to insert a scroll bar using php?...if yes i don't think that's necessary insert your scroll bar using html and css. is the code working fine?
Feb 12 '12 #8

matheussousuke
100+
P: 249
I still haven't tested it. I'm having an issue with the submitted content, it has to be inside a scroll bar after submitted, because it takes too much space.
Feb 12 '12 #9

P: 23
may be this may work for you

the html
Expand|Select|Wrap|Line Numbers
  1. <div class=sub_content"><?php echo $submitted_content; ?></div
the css
Expand|Select|Wrap|Line Numbers
  1. .sub_content
  2. {
  3. overflow: scroll;
  4. max-width: specify the width you want here eg 500px;
  5. max-height: specify the height you want here eg 350px;
  6. }
  7.  
that should fix it for you.
Feb 12 '12 #10

matheussousuke
100+
P: 249
Where u from, Joseph?
Feb 12 '12 #11

P: 23
am from nigeria...where are you?
Feb 12 '12 #12

matheussousuke
100+
P: 249
Currently Brazil.

I still haven't used your script because I haven't fixed the form issue, thought it was just the scroll bar, inserted it, but there is another bug now, can I pm you?
Feb 13 '12 #13

matheussousuke
100+
P: 249
Sorry, it's been 1 week since my last reply, I'm not being able to use ur script, it wont show the error messages.
Feb 23 '12 #14

P: 23
give me your full source code and how you implemented the script let me find out why there is no error message
Feb 23 '12 #15

matheussousuke
100+
P: 249
The text comes from a textarea tag

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4.  
  5. /**
  6.  
  7.  
  8.  
  9.  * Elgg bloggertemplates Plugin
  10.  
  11.  
  12.  
  13.  * @package bloggertemplates
  14.  
  15.  
  16.  
  17.  * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
  18.  
  19.  
  20.  
  21.  * @author slyhne
  22.  
  23.  
  24.  
  25.  * @copyright slyhne 2010-2011
  26.  
  27.  
  28.  
  29.  * @link www.zurf.dk/elgg
  30.  
  31.  
  32.  
  33.  * @version 1.8
  34.  
  35.  
  36.  
  37.  */
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. // Get plugin settings
  46.  
  47.  
  48.  
  49. $allowhtml = elgg_get_plugin_setting('bloggertemplates_allowhtml', 'bloggertemplates');
  50.  
  51.  
  52.  
  53. $currency = elgg_get_plugin_setting('bloggertemplates_currency', 'bloggertemplates');
  54.  
  55.  
  56.  
  57. $numchars = elgg_get_plugin_setting('bloggertemplates_numchars', 'bloggertemplates');
  58.  
  59.  
  60.  
  61. if($numchars == ''){
  62.  
  63.  
  64.  
  65.     $numchars = '250';
  66.  
  67.  
  68.  
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. // Set title, form destination
  78.  
  79.  
  80.  
  81. $title = elgg_echo("bloggertemplates:addpost");
  82.  
  83.  
  84.  
  85. $tags = "";
  86.  
  87.  
  88.  
  89. $title = "";
  90.  
  91.  
  92.  
  93. $price = "";
  94.  
  95.  
  96.  
  97. $custom = "";
  98.  
  99.  
  100.  
  101. $description = "";
  102.  
  103.  
  104.  
  105. if (defined('ACCESS_DEFAULT')) {
  106.  
  107.  
  108.  
  109.     $access_id = ACCESS_DEFAULT;
  110.  
  111.  
  112.  
  113. } else {
  114.  
  115.  
  116.  
  117.     $access_id = 0;
  118.  
  119.  
  120.  
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. // Just in case we have some cached details
  130.  
  131.  
  132.  
  133. if (isset($vars['bloggertemplatestitle'])) {
  134.  
  135.  
  136.  
  137.     $title = $vars['bloggertemplatestitle'];
  138.  
  139.  
  140.  
  141.     $body = $vars['bloggertemplatesbody'];
  142.  
  143.  
  144.  
  145.     $price = $vars['bloggertemplatesprice'];
  146.  
  147.  
  148.  
  149.     $custom = $vars['bloggertemplatescustom'];
  150.  
  151.  
  152.  
  153.     $tags = $vars['bloggertemplatestags'];
  154.  
  155.  
  156.  
  157. }
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. ?>
  170.  
  171.  
  172.  
  173. <script type="text/javascript">
  174.  
  175.  
  176.  
  177. function textCounter(field,cntfield,maxlimit) {
  178.  
  179.  
  180.  
  181.     // if too long...trim it!
  182.  
  183.  
  184.  
  185.     if (field.value.length > maxlimit) {
  186.  
  187.  
  188.  
  189.         field.value = field.value.substring(0, maxlimit);
  190.  
  191.  
  192.  
  193.     } else {
  194.  
  195.  
  196.  
  197.         // otherwise, update 'characters left' counter
  198.  
  199.  
  200.  
  201.         cntfield.value = maxlimit - field.value.length;
  202.  
  203.  
  204.  
  205.     }
  206.  
  207.  
  208.  
  209. }
  210.  
  211.  
  212.  
  213. function acceptTerms() {
  214.  
  215.  
  216.  
  217.     error = 0;
  218.  
  219.  
  220.  
  221.     if(!(document.bloggertemplatesForm.accept_terms.checked) && (error==0)) {        
  222.  
  223.  
  224.  
  225.         alert('<?php echo elgg_echo('bloggertemplates:accept:terms:error'); ?>');
  226.  
  227.  
  228.  
  229.         document.bloggertemplatesForm.accept_terms.focus();
  230.  
  231.  
  232.  
  233.         error = 1;        
  234.  
  235.  
  236.  
  237.     }
  238.  
  239.  
  240.  
  241.     if(error == 0) {
  242.  
  243.  
  244.  
  245.         document.bloggertemplatesForm.submit();    
  246.  
  247.  
  248.  
  249.     }
  250.  
  251.  
  252.  
  253. }
  254.  
  255.  
  256.  
  257. </script>
  258.  
  259.  
  260.  
  261. <?php
  262.  
  263.  
  264.  
  265. echo "<label>";
  266.  
  267.  
  268.  
  269. echo elgg_echo("title");
  270.  
  271.  
  272.  
  273. echo "&nbsp;<small><small>" . elgg_echo("bloggertemplates:title:help") . "</small></small><br />";
  274.  
  275.  
  276.  
  277. echo elgg_view("input/text", array(
  278.  
  279.  
  280.  
  281.                 "name" => "bloggertemplatestitle",
  282.  
  283.  
  284.  
  285.                 "value" => $title,
  286.  
  287.  
  288.  
  289.                 ));
  290.  
  291.  
  292.  
  293. echo "</label></p>";
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. $bloggertemplatescategories = elgg_view('bloggertemplates/bloggertemplatescategories',$vars);
  302.  
  303.  
  304.  
  305. if (!empty($bloggertemplatescategories)) {
  306.  
  307.  
  308.  
  309.     echo "<p>{$bloggertemplatescategories}</p>";
  310.  
  311.  
  312.  
  313. }
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321. if(elgg_get_plugin_setting('bloggertemplates_custom', 'bloggertemplates') == 'yes'){
  322.  
  323.  
  324.  
  325.     $bloggertemplatescustom = elgg_view('bloggertemplates/custom',$vars);
  326.  
  327.  
  328.  
  329.     if (!empty($bloggertemplatescustom)) {
  330.  
  331.  
  332.  
  333.         echo "<p>{$bloggertemplatescustom}</p>";
  334.  
  335.  
  336.  
  337.     }
  338.  
  339.  
  340.  
  341. }
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349. echo "<p><label>" . elgg_echo("bloggertemplates:text") . "<br>";
  350.  
  351.  
  352.  
  353. if ($allowhtml != 'yes') {
  354.  
  355.  
  356.  
  357.     echo "<small><small>" . sprintf(elgg_echo("bloggertemplates:text:help"), $numchars) . "</small></small><br />";
  358.  
  359.  
  360.  
  361.     echo "<textarea name='bloggertemplatesbody' class='mceNoEditor' rows='8' cols='40' onKeyDown='textCounter(document.bloggertemplatesForm.bloggertemplatesbody,document.bloggertemplatesForm.remLen1,{$numchars}' onKeyUp='textCounter(document.bloggertemplatesForm.bloggertemplatesbody,document.bloggertemplatesForm.remLen1,{$numchars})'>{$body}</textarea><br />";
  362.  
  363.  
  364.  
  365.     echo "<div class='bloggertemplates_characters_remaining'><input readonly type='text' name='remLen1' size='3' maxlength='3' value='{$numchars}' class='bloggertemplates_charleft'>" . elgg_echo("bloggertemplates:charleft") . "</div>";
  366.  
  367.  
  368.  
  369. } else { 
  370.  
  371.  
  372.  
  373.     echo elgg_view("input/text", array("name" => "bloggertemplatesbody", "value" => $body));
  374.  
  375.  
  376.  
  377. }
  378.  
  379.  
  380.  
  381. echo "</label></p>";
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388. /*
  389. echo "<p><label>" . elgg_echo("bloggertemplates:price") . "&nbsp;<small><small>" . elgg_echo("bloggertemplates:price:help", array($currency)) . "</small></small><br />";
  390.  
  391.  
  392.  
  393. echo elgg_view("input/text", array(
  394.  
  395.  
  396.  
  397.                 "name" => "bloggertemplatesprice",
  398.  
  399.  
  400.  
  401.                 "value" => $price,
  402.  
  403.  
  404.  
  405.                 ));
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413. echo "</label></p>";
  414. */
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421. echo "<p><label>" . elgg_echo("bloggertemplates:tags") . "&nbsp;<small><small>" . elgg_echo("bloggertemplates:tags:help") . "</small></small><br />";
  422.  
  423.  
  424.  
  425. echo elgg_view("input/tags", array(
  426.  
  427.  
  428.  
  429.                 "name" => "bloggertemplatestags",
  430.  
  431.  
  432.  
  433.                 "value" => $tags,
  434.  
  435.  
  436.  
  437.                 ));
  438.  
  439.  
  440.  
  441. echo "</label></p>";
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449. echo "<p><label>" . elgg_echo("bloggertemplates:uploadimages") . "<br /><small><small>" . elgg_echo("bloggertemplates:imagelimitation") . "</small></small><br />";
  450.  
  451.  
  452.  
  453. echo elgg_view("input/file",array('name' => 'upload'));
  454.  
  455.  
  456.  
  457. echo "</label></p>";
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465. echo "<p><label>" . elgg_echo('access') . "&nbsp;<small><small>" . elgg_echo("bloggertemplates:access:help") . "</small></small><br />";
  466.  
  467.  
  468.  
  469. echo elgg_view('input/access', array('name' => 'access_id','value' => $access_id));
  470.  
  471.  
  472.  
  473. echo "</label></p>";
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481. echo "<p>";
  482.  
  483.  
  484.  
  485. // Terms checkbox and link
  486.  
  487.  
  488.  
  489. $termslink = elgg_view('output/url', array(
  490.  
  491.  
  492.  
  493.             'href' => "mod/bloggertemplates/terms.php",
  494.  
  495.  
  496.  
  497.             'text' => elgg_echo('bloggertemplates:terms:title'),
  498.  
  499.  
  500.  
  501.             'class' => "elgg-lightbox",
  502.  
  503.  
  504.  
  505.             ));
  506.  
  507.  
  508.  
  509. $termsaccept = sprintf(elgg_echo("bloggertemplates:accept:terms"),$termslink);
  510.  
  511.  
  512.  
  513. echo "</p>";
  514.  
  515.  
  516.  
  517. echo "<input type='checkbox' name='accept_terms'><label>{$termsaccept}</label></p>";
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525. echo elgg_view('input/submit', array('name' => 'submit', 'text' => elgg_echo('save')));
  526.  
  527.  
Feb 23 '12 #16

Post your reply

Sign in to post your reply or Sign up for a free account.