Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Forms and keeping user input to them

Options
  • 12-07-2002 2:48pm
    #1
    Registered Users Posts: 14,148 ✭✭✭✭


    Hey guys,

    got myself a bit of a curiosity here. Does anyone know (and be willing to impart said knowledge [:p] ) how to get a form to keep user-input AFTER its been submitted.

    What I'm looking to do is as follows:

    1. User fillls in Form.
    2. User forgets to fill in the field with the BIG neon flashing sign beside it saying "FILL ME or I wont work".
    3. User clicks the "submit" button, only to be presented with the same form and message telling them to fill in all required fields.
    4. (this is where I'm interested) The Form sets the field values of all user-provided input from the last time, without altering the "normal" behaviour of the form (such as clearing, etc).

    Any thoughts or ideas? I can get the form to keep values, but I seem to be overriding the basic inherited behaviour of the form, so when I want to do "normal" form actions, nothing happens.


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Can you not just use a small javascript thing (if you know javascript, cos I don't ;)) which checks all the fields when the button is pressed, and if all fields pass, then the javascript function passes the info to the cgi or whatever script. So basically, it doesn't get submitted until all the fields are correct.

    Or alternatively, after pressing 'submit', you present them with a new form containing only the fields they never filled in, and with values of the original form stored in hidden holders on the page.

    I'm not really much good at creating new forms though, I normally just steal other people's :p


  • Registered Users Posts: 14,148 ✭✭✭✭Lemming


    Originally posted by seamus
    Can you not just use a small javascript thing (if you know javascript, cos I don't ;)) which checks all the fields when the button is pressed, and if all fields pass, then the javascript function passes the info to the cgi or whatever script. So basically, it doesn't get submitted until all the fields are correct.

    Well, what I'm doing is ..... (using php), when a form is submitted, a function is called to check for various fields. If a boolean value of "true" is sent back, then the form proceeds to make calls to an object, passing in the form field values to write to a DB.

    Problem is that once you submit, the form is cleared. That's what I'm trying to prevent




    Or alternatively, after pressing 'submit', you present them with a new form containing only the fields they never filled in, and with values of the original form stored in hidden holders on the page.

    I'm not really much good at creating new forms though, I normally just steal other people's :p [/B][/QUOTE]


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Is there any way you could load all the form fields into global variables when the submit button is pressed? That way, if 'false' is returned, you simply return the fields back to the form. I'm assuming here that the form and php are in the same page, and the form isn't just posting the info to a php script, ie

    <form action=post method=/mydir/submit.php>

    or however it's written.....That's all the helps I can attempt to be :)


  • Registered Users Posts: 14,148 ✭✭✭✭Lemming


    Originally posted by seamus
    Is there any way you could load all the form fields into global variables when the submit button is pressed? That way, if 'false' is returned, you simply return the fields back to the form. I'm assuming here that the form and php are in the same page, and the form isn't just posting the info to a php script, ie

    <form action=post method=/mydir/submit.php>

    or however it's written.....That's all the helps I can attempt to be :)

    No .. it's all being done within the php page. I can get the field values being set if a false is returned, but it seems to be over-riding the form's basic actionslike "clearing", etc.


  • Registered Users Posts: 944 ✭✭✭nahdoic


    [PHP]<form action=retain.php method=get>
    <p><input type=text name=username value = "<?=$username?>"></p>
    <p><textarea name=message>
    <?=$message?>
    </textarea></p>
    <p><input type=submit></p>
    </form>[/PHP]


  • Advertisement
  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    You would want to avoid CR's with Textareas, btw:
    <p><textarea name=message><?=$message?></textarea></p>
    
    As an aside, with ASP that would be:
    <p><textarea name=message><%=Response.QueryString("message").Value%></textarea></p>
    


  • Registered Users Posts: 11,987 ✭✭✭✭zAbbo


    Dreamweaver has a built in function, which validatesb a form, just select the form and click behaviors and validate form.
    <script language="JavaScript">
    <!--
    function MM_findObj(n, d) { //v4.0
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && document.getElementById) x=document.getElementById(n); return x;
    }
    
    function MM_validateForm() { //v4.0
      var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
          } else if (test!='R') {
            if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
      } if (errors) alert('The following error(s) occurred:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    </head>
    
    <body bgcolor="#FFFFFF" text="#000000">
     
    <form name="form1" method="post" action="<%=MM_editAction%>" onSubmit="MM_validateForm('name','','RisEmail');return document.MM_returnValue">
      <p>Email Address 
        <input type="text" name="name">
      </p>
      <p> 
        <input type="submit" name="Submit" value="Send Form" class="button">
        <input type="hidden" name="FFSubmitted" value="yes">
      </p>
    </form>
    


  • Registered Users Posts: 706 ✭✭✭DJB


    Check out www.yaromat.com for a good extension for dreamweaver that has advanced form checking.

    Regards,

    Dave


Advertisement