will get_options return everything?
There is no WordPress function named “get_options.” “get_option” will return specifically requested options, such as the site’s url: get_option(‘siteurl’);
sorry for that miss type. I was refering to get_option
This means that I can not create a plugin where the form fields are not determinate?
I need to pre-define everything in code.
Am i right?
You could save all the form fields as one array or object and store it in and option named something like ‘ssdesigns_options’ or whatever.
filosofo: If you’re wanting to allow people to extend a form you need a few basic steps.
Firstly, take the form element name & append a number, e.g. name=”qualification1″. For each added qualification increment that number – so you’ll end up with a list of form elements like 1 to X.
When the form is submitted you can then do a loop through the returned form until you hit a blank (i.e. the end of the array).
$x=1;
while($_POST{'qualification' . $x}!='') { $qualifications[$x]=$_POST{'qualification'.$x};
}
$options['qualifications']=$qualifications;
Haven’t checked the code, but that *should* give you an array of qualifications. You can should be able to save this data with update_option as normal (apparently WordPress will serialise arrays automatically, although I’ve not tried it).
Test this with a sample HTML form you’ve built up yourself.
Incidentally, it’s not really AJAX if you’re just adding extra fields to a form. Well… you could do it that way, but you’d be better off with some simple Javascript.
Hope that helps,
hi mutube, I will try this.
Looks like it should work.
Thanks.
ok,
Now in my existing code, I am doing this:
To add default options:
add_option(‘wphr_qualification’, __(‘your qualification’, ‘wphr’));
To update options:
update_option(‘wphr_qualification’, $_POST[‘wphr_qualification’]);
To get options:
$wphr_qualification= stripslashes(get_option(‘wphr_qualification’));
Now in the case of dynamic content as discussed above, how should I re-write my code to utilise values from:
$options[‘qualifications’]=$qualifications;
Any suggestion?
$x=1;
while($_POST{'wphr_qualification' . $x}!='') { $qualifications[$x]=$_POST{'wphr_qualification'.$x};
}
update_option('wphr_qualification', $qualifications);
Will do just fine. When you retrieve with $qualifications=get_option('wphr_qualification');
they will be available like:
$qualifications["1"]
for the first Qual.
You do know by the way that you can store more than one option under a heading using arrays, e.g.
$options['one']="1";
$options['two']="1";
$options['three']="1";
update_option('wphr_options', $options);
Just in case you’re overcomplicating things for yourself. That’s where the $options['qualifications']=$qualifications;
came into it.
Good luck,
Excellent, this really worked.
Thanks and I will add credits to you when I finish this piece of work.
No problem & thanks 🙂 Post back if you need any more help.
Good luck with the site.
mutube,
Had one more question, if u want, I can post a seperate topic.
Can we add some code in the plugin so that when you activate it, automatically a PAGE is created in WordPress?
Sorry nearly missed this – you’re wanting a new post to be generated in the blog when the plugin is activated?
Is this a blank page or to have something in it?
To be honest you’re possibly asking for trouble (multiple pages on stop/restart/etc.) but it’s certainly do-able!
Let me know what you’re trying to achieve and will give it a look.