Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Owdy - helmikuu 28, 2006, 02:29:41 IP

Otsikko: Register template modification
Kirjoitti: Owdy - helmikuu 28, 2006, 02:29:41 IP
I know how to ad custom fields to it, but how do i force people to fill them?
Otsikko: Re: Register template modification
Kirjoitti: kegobeer - helmikuu 28, 2006, 02:31:06 IP
You could do a javascript check and make sure the fields are filled in before allowing the form to post, or you could check the post variables and redirect back to the previous page if they aren't complete.
Otsikko: Re: Register template modification
Kirjoitti: Owdy - helmikuu 28, 2006, 02:33:13 IP
I would like to use same method as those default fields have. I just dont know how :D
Otsikko: Re: Register template modification
Kirjoitti: RyanJones - helmikuu 28, 2006, 03:20:50 IP
Lainaus käyttäjältä: Owdy - helmikuu 28, 2006, 02:33:13 IP
I would like to use same method as those default fields have. I just dont know how :D

Yup, thats Javascript.

Do you just want to vrafy the field is not empty or what?

If just empty then adding this to the input tags will do it:

onclick="if (this.value == '') { alert('Please fill in this field!'); this.focus(); }"

If not then can you be a bit more specific ?

Cheers,

Ryan Jones
Otsikko: Re: Register template modification
Kirjoitti: Owdy - helmikuu 28, 2006, 11:09:59 IP
That seems perfect. But if i ad that to input tag, i get parse errors. I suck with JS :(
Otsikko: Re: Register template modification
Kirjoitti: Elmacik - maaliskuu 01, 2006, 12:19:40 AP
Look how Oldiesmann did a great job in the past: Registering new members settings? (http://www.simplemachines.org/community/index.php?topic=53389.0)
Otsikko: Re: Register template modification
Kirjoitti: Thantos - maaliskuu 01, 2006, 08:19:46 AP
If you really want to make sure that the field is inputted then you'll have to edit the source file.  Javascript alone just won't cut it.

So say you had:
What is your shoe size: <input type="text" name="shoe_size" />
Then you'd do something like this in the source file

if ( !isset($_REQUEST['shoe_size']) || trim($_REQUEST['shoe_size']) == '' )
  fatal_error("Hey jerk I said give me your shoe size", false);

REQUEST can be exchanged with POST if you want to limit it to post only.  The false on the fatal error means it won't log the error.  Using trim keeps people from just putting in spaces or other whitespace.
Otsikko: Re: Register template modification
Kirjoitti: Owdy - maaliskuu 01, 2006, 11:31:36 AP
I got this

<input type="text" name="options[text_location]" size="50" value="', isset($context['member']['options']['text_location']) ? $context['member']['options']['text_location'] : '', '"  tabindex="', $context['tabindex']++, '" />

If i put this to Register.php, it wont work.

if ( !isset($_REQUEST['text_location']) || trim($_REQUEST['text_location']) == '' )
  fatal_error("Ammatti unohtui!", false);


Otsikko: Re: Register template modification
Kirjoitti: RyanJones - maaliskuu 01, 2006, 12:12:42 IP
Try this...

Find:       redirectexit('action=coppa;member=' . $memberID);

After, Add:   if ( !isset($_POST['text_location']) || trim($_POST['text_location']) == '' )
    fatal_error("Ammatti unohtui!", false);

See if that works for you :)

Cheers,

Ryan Jones
Otsikko: Re: Register template modification
Kirjoitti: Owdy - maaliskuu 01, 2006, 01:13:52 IP
No. :( It gives that error 'ammatti unohtui' and gives link back, but it registers member anyway. Hmmm, how about that just js error, im fine with that if it works.
Otsikko: Re: Register template modification
Kirjoitti: Thantos - maaliskuu 01, 2006, 05:30:40 IP
It helps if you use the same name....

$_REQUEST['text_location'] is in your source but you have "options[text_location]" in your form.  That would make it $_REQUEST['options']['text_location']
Otsikko: Re: Register template modification
Kirjoitti: Owdy - maaliskuu 01, 2006, 11:16:51 IP
Its still does the same. It gives an error, and if you hit 'back' link and try again it says you cannot register twice. Thats because that allows register go trough somehow.

edit: i got it, Thanks! It was in wrong area. It works like this:

// omat säädöt
if ( !isset($_REQUEST['options']['text_location']) || trim($_REQUEST['options']['text_location']) == '' )
  fatal_error("Ammatti unohtui!", false);
// Registration options are always default options...
if (isset($_POST['default_options']))