Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2009
    Posts
    85
    Plugin Contributions
    0

    red flag Implementing (Limit Textarea) code into input field of "Gift Certificate" page?

    Hello.

    I need to implement this (Limit Textarea) code into my "Gift Certificate) site page (http://www.MyStore.com/index.php?main_page=gv_send):

    Here is preview of how it works:
    http://www.yaldex.com/FSForms/LimitTextarea.htm

    I am trying to give customers a feed back on how many characters they have typed in the Gift Certificate Personal Message Field... I put a warning on the page (200 characters limit), but they message just gets cut off if they go over the limit (when someone gets a gift certificate via email). All the input fields are implemented in the image on Custom Designed Gift Certificate HTML Page, customers are able to print it out from they email).

    CODE:

    <body>
    <script language="javascript" type="text/javascript">
    <!-- Begin
    function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    else
    countfield.value = maxlimit - field.value.length;
    }
    // End -->
    </script>

    <!-- textCounter() parameters are: text field, the count field, max length -->
    <form name=myform action="YOUR-SCRIPT.CGI">
    <font size="1" face="arial, helvetica, sans-serif"> ( You may enter up to 125 characters. )<br>
    <textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>
    <br>
    <input readonly type=text name=remLen size=3 maxlength=3 value="125"> characters left</font>
    </form>
    </body>

    -------------------------------------------

    I am new to PHP, so I am not quite sure how to implement it on the page or if it is even possible to make it work using javascript...
    Has anyone any experience with this??

    Any help is appreciated.
    Thanks.

  2. #2
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Implementing (Limit Textarea) code into input field of "Gift Certificate" page?

    One point to note: you need to strip the <body> and </body> tags from the code, as it wil be going inside an existing HTML page.
    The script itself can be put in a separate file named jscript_xxx.js (xxx = whatever you want) and saved in

    /includes/templates/your_template/jscript/jscript_xxx.js

    If you do this you also need to strip the <script> and </script> tags from the script.

    You then put the code that calls the script in the appropriate PHP file.

  3. #3
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Implementing (Limit Textarea) code into input field of "Gift Certificate" page?

    Another thing: if you are only using the script on one page, you can save it in a different location, like

    /includes/modules/pages/{gv_pagename}/jscript_xxx.js

    Replace {gv_pagename} with the actual folder name.

  4. #4
    Join Date
    Jun 2009
    Posts
    85
    Plugin Contributions
    0

    Default Re: Implementing (Limit Textarea) code into input field of "Gift Certificate" page?

    Thanks, I'll try it...

  5. #5
    Join Date
    Jun 2009
    Posts
    85
    Plugin Contributions
    0

    Default Re: Implementing (Limit Textarea) code into input field of "Gift Certificate" page?

    OK, I am not sure where exactly to set the call for the Javascript...
    Is it supposed to be in the header file (header_php.php) in the gv_send folder or in the tpl_gv_send_default.php?
    I tried to just put it all in the tpl_gv_send_default.php and it did not work...
    But then again I don't have a clear idea of what I am doing (no php experience...)

    Here is what I put in tpl_gv_send_default.php:



    <?php
    echo '<script type="text/javascript">
    <!--
    function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    else
    countfield.value = maxlimit - field.value.length;
    }
    //-->
    </script>';
    ?>


    <form action="<?php echo zen_href_link(FILENAME_GV_SEND, 'action=send', 'SSL', false); ?>" method="post">

    <fieldset>
    <legend><?php echo HEADING_TITLE; ?></legend>

    <label class="inputLabel" for="to-name"><?php echo ENTRY_NAME; ?></label>
    <?php echo zen_draw_input_field('to_name', $_POST['to_name'], 'size="40" id="to-name"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>';?>
    <br class="clearBoth" />

    <label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL; ?></label>
    <?php echo zen_draw_input_field('email', $_POST['email'], 'size="40" id="email-address"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; if ($error) echo $error_email; ?>
    <br class="clearBoth" />

    <label class="inputLabel" for="amount"><?php echo ENTRY_AMOUNT; ?></label>
    <?php echo zen_draw_input_field('amount', $_POST['amount'], 'id="amount"', 'text', false) . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; if ($error) echo $error_amount; ?>
    <br class="clearBoth" />

    <label class="message-area"><?php echo ENTRY_MESSAGE; ?></label>
    <?php echo zen_draw_textarea_field('message', 50, 3, onKeyDown="textCounter(this.form.message,this.form.remLen,200);" onKeyUp="textCounter(this.form.message,this.form.remLen,200);" onKeyDown="textCounter(this.form.message,this.form.remLen,200);" onKeyUp="textCounter(this.form.message,this.form.remLen,200);" stripslashes($_POST['message']), 'id="message-area"'); ?>
    <div font size="1" face="arial, helvetica, sans-serif"><input readonly type=text name=remLen size=3 maxlength=3 value="200"> characters left</font></div>


    <div id="gvLimitText"><?php echo EMAIL_GV_LIMIT_TEXT; ?></div>

    </fieldset>

    <div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_SEND, BUTTON_SEND_ALT); ?></div>
    <div class="buttonRow back"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_BACK, BUTTON_BACK_ALT) . '</a>'; ?></div>
    <br class="clearBoth" />
    </form>


    Can anyone help with this?

  6. #6
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Implementing (Limit Textarea) code into input field of "Gift Certificate" page?

    You would put the top section of code (everything inside but not including the <script> tags) in a new file named jscript_textcounter.js and saved as I described above.

    The bottom section of new code would probably go in the general area where you have it, but I think you have taken too much away from around it. I don't use javascript, so can't advise further on that.

  7. #7
    Join Date
    Jun 2009
    Posts
    85
    Plugin Contributions
    0

    Default Re: Implementing (Limit Textarea) code into input field of "Gift Certificate" page?

    Thanks any ways, I'll try to see what else could be done...

  8. #8
    Join Date
    Jun 2009
    Posts
    85
    Plugin Contributions
    0

    red flag Re: Implementing (Limit Textarea) code into input field of "Gift Certificate" page?

    OK I put java script into my tpl_gv_send_default.php page.
    And I put this in my form on my tpl_gv_send_default.php page:

    <form name="maxlength_test" action="<?php echo zen_href_link(FILENAME_GV_SEND, 'action=send', 'SSL', false); ?>" method="post">

    <fieldset>
    <label class="message-area"><?php echo ENTRY_MESSAGE; ?></label>
    <TEXTAREA
    NAME="message"
    id="message-area"
    ROWS="3"
    COLS="50"
    onkeypress="textCounter(this,this.form.counter,200);">
    </TEXTAREA>

    <br class="clearBoth" /><br class="clearBoth" /><br class="clearBoth" />
    <input
    type="text"
    name="counter"
    maxlength="3"
    size="3"
    value="200"
    onChange="textCounter(this.form.counter,this,200);"> &nbsp;characters remaining


    </fieldset>
    </form>

    -------------------------------------------------------------
    It works as far as showing character count.
    However we had someone trying to just limit the number of characters (without the feedback) in this field before and now in the actual email/HTML Gift Certificate file text just gets cut off after 125 characters... even thought I typed in 200 characters... I have no idea where to fix it... Any ideas on where should I look it up?
    Also, where do I put this line:$myString = substr($theString, 0, 200) in my code??

    Thank you for your help!

  9. #9
    Join Date
    Jun 2009
    Posts
    85
    Plugin Contributions
    0

    Default Re: Implementing (Limit Textarea) code into input field of "Gift Certificate" page?

    Here is Java Script for the php page:

    <script language="javascript" type="text/javascript">
    function textCounter( field, countfield, maxlimit ) {
    if ( field.value.length > maxlimit )
    {
    field.value = field.value.substring( 0, maxlimit );
    alert( 'Textarea value can only be 200 characters in length.' );
    return false;
    }
    else
    {
    countfield.value = maxlimit - field.value.length;
    }
    }
    </script>

 

 

Similar Threads

  1. Replies: 5
    Last Post: 13 Dec 2012, 11:47 PM
  2. Turn Off "Gift Certificate FAQ" & "Newsletter Unsubscribe" from Sidebox
    By DBB1 in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 16 Sep 2010, 04:23 AM
  3. Replies: 24
    Last Post: 17 Dec 2008, 06:33 PM
  4. Change EZ-Page "Page Title:" maxlength Input Field?
    By rainthebat in forum Customization from the Admin
    Replies: 4
    Last Post: 6 Mar 2007, 11:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR